summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-06-29 22:32:24 +0000
committerJeremy Allison <jra@samba.org>2001-06-29 22:32:24 +0000
commite2ced932dbd34384f1e3752cc073b2fb66467b46 (patch)
tree94bd92fca7c48416bd8d3ac55de72c0155eda2c0 /source3
parent2cddd5fe8ca05cd642428b4a7e2356f05cee6386 (diff)
downloadsamba-e2ced932dbd34384f1e3752cc073b2fb66467b46.tar.gz
samba-e2ced932dbd34384f1e3752cc073b2fb66467b46.tar.bz2
samba-e2ced932dbd34384f1e3752cc073b2fb66467b46.zip
Ensured all the system calls in msdfs.c go through the vfs layer.
Added vfs calls to symlink() and readlink() with appropriate configure checks. Jeremy. (This used to be commit c24e6b41ea60ab4bac2fcd19da947851d6df3c7c)
Diffstat (limited to 'source3')
-rwxr-xr-xsource3/configure2
-rw-r--r--source3/configure.in2
-rw-r--r--source3/include/config.h.in6
-rw-r--r--source3/include/vfs.h2
-rw-r--r--source3/lib/system.c28
-rw-r--r--source3/msdfs/msdfs.c1136
-rw-r--r--source3/smbd/service.c26
-rw-r--r--source3/smbd/vfs-wrap.c32
-rw-r--r--source3/smbd/vfs.c213
9 files changed, 750 insertions, 697 deletions
diff --git a/source3/configure b/source3/configure
index c5be10f3d7..cf36998f3a 100755
--- a/source3/configure
+++ b/source3/configure
@@ -5792,7 +5792,7 @@ else
fi
done
-for ac_func in srandom random srand rand setenv usleep strcasecmp fcvt fcvtl
+for ac_func in srandom random srand rand setenv usleep strcasecmp fcvt fcvtl symlink readlink
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:5799: checking for $ac_func" >&5
diff --git a/source3/configure.in b/source3/configure.in
index 61ad20b6f6..0d59ee50e2 100644
--- a/source3/configure.in
+++ b/source3/configure.in
@@ -497,7 +497,7 @@ AC_CHECK_FUNCS(initgroups select poll rdchk getgrnam getgrent pathconf)
AC_CHECK_FUNCS(setpriv setgidx setuidx setgroups sysconf mktime rename ftruncate stat64 fstat64)
AC_CHECK_FUNCS(lstat64 fopen64 atexit grantpt dup2 lseek64 ftruncate64 readdir64)
AC_CHECK_FUNCS(fseek64 fseeko64 ftell64 ftello64 setluid getpwanam setlinebuf)
-AC_CHECK_FUNCS(srandom random srand rand setenv usleep strcasecmp fcvt fcvtl)
+AC_CHECK_FUNCS(srandom random srand rand setenv usleep strcasecmp fcvt fcvtl symlink readlink)
# syscall() is needed for smbwrapper.
AC_CHECK_FUNCS(syscall)
diff --git a/source3/include/config.h.in b/source3/include/config.h.in
index eff40ac29d..fed57a33fe 100644
--- a/source3/include/config.h.in
+++ b/source3/include/config.h.in
@@ -628,6 +628,9 @@
/* Define if you have the readdir64 function. */
#undef HAVE_READDIR64
+/* Define if you have the readlink function. */
+#undef HAVE_READLINK
+
/* Define if you have the rename function. */
#undef HAVE_RENAME
@@ -706,6 +709,9 @@
/* Define if you have the strtoul function. */
#undef HAVE_STRTOUL
+/* Define if you have the symlink function. */
+#undef HAVE_SYMLINK
+
/* Define if you have the syscall function. */
#undef HAVE_SYSCALL
diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index 51f3df1ec9..93823a5f23 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -86,6 +86,8 @@ struct vfs_ops {
int (*utime)(struct connection_struct *conn, char *path, struct utimbuf *times);
int (*ftruncate)(struct files_struct *fsp, int fd, SMB_OFF_T offset);
BOOL (*lock)(struct files_struct *fsp, int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type);
+ int (*symlink)(struct connection_struct *conn, const char *oldpath, const char *newpath);
+ int (*readlink)(struct connection_struct *conn, const char *path, char *buf, size_t bufsiz);
/* NT ACL operations. */
diff --git a/source3/lib/system.c b/source3/lib/system.c
index 810096ef36..a402af77c9 100644
--- a/source3/lib/system.c
+++ b/source3/lib/system.c
@@ -265,6 +265,34 @@ char *sys_getwd(char *s)
}
/*******************************************************************
+system wrapper for symlink
+********************************************************************/
+
+int sys_symlink(const char *oldpath, const char *newpath)
+{
+#ifndef HAVE_SYMLINK
+ errno = ENOSYS;
+ return -1;
+#else
+ return symlink(oldpath, newpath);
+#endif
+}
+
+/*******************************************************************
+system wrapper for readlink
+********************************************************************/
+
+int sys_readlink(const char *path, char *buf, size_t bufsiz)
+{
+#ifndef HAVE_READLINK
+ errno = ENOSYS;
+ return -1;
+#else
+ return readlink(path, buf, bufsiz);
+#endif
+}
+
+/*******************************************************************
chown isn't used much but OS/2 doesn't have it
********************************************************************/
diff --git a/source3/msdfs/msdfs.c b/source3/msdfs/msdfs.c
index b93590fcd2..461b3676a9 100644
--- a/source3/msdfs/msdfs.c
+++ b/source3/msdfs/msdfs.c
@@ -30,285 +30,298 @@ extern uint32 global_client_caps;
/**********************************************************************
Create a tcon relative path from a dfs_path structure
**********************************************************************/
+
static void create_nondfs_path(char* pathname, struct dfs_path* pdp)
{
- pstrcpy(pathname,pdp->volumename);
- pstrcat(pathname,"\\");
- pstrcat(pathname,pdp->restofthepath);
+ 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
**********************************************************************/
+
static 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);
-
- 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;
+ pstring pathname_local;
+ char* p,*temp;
+
+ pstrcpy(pathname_local,pathname);
+ p = temp = pathname_local;
+
+ ZERO_STRUCTP(pdp);
+
+ 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;
+}
+
+/********************************************************
+ Fake up a connection struct for the VFS layer.
+*********************************************************/
+
+static BOOL create_conn_struct( connection_struct *conn, int snum, char *path)
+{
+ ZERO_STRUCTP(conn);
+ conn->service = snum;
+ conn->connectpath = path;
+
+ if (!vfs_init(conn)) {
+ DEBUG(0,("create_conn_struct: vfs init failed.\n"));
+ return False;
+ }
+ return True;
}
/**********************************************************************
Forms a valid Unix pathname from the junction
**********************************************************************/
-static BOOL form_path_from_junction(struct junction_map* jn, char* path,
- int max_pathlen)
+
+static BOOL form_path_from_junction(struct junction_map* jn, char* path, int max_pathlen,
+ connection_struct *conn)
{
- int snum;
+ int snum;
- if(!path || !jn)
- return False;
+ if(!path || !jn)
+ return False;
- snum = lp_servicenumber(jn->service_name);
- if(snum < 0)
- return False;
+ snum = lp_servicenumber(jn->service_name);
+ if(snum < 0)
+ return False;
- safe_strcpy(path, lp_pathname(snum), max_pathlen-1);
- safe_strcat(path, "/", max_pathlen-1);
- strlower(jn->volume_name);
- safe_strcat(path, jn->volume_name, max_pathlen-1);
- return True;
+ safe_strcpy(path, lp_pathname(snum), max_pathlen-1);
+ safe_strcat(path, "/", max_pathlen-1);
+ strlower(jn->volume_name);
+ safe_strcat(path, jn->volume_name, max_pathlen-1);
+
+ if (!create_conn_struct(conn, snum, path))
+ return False;
+
+ return True;
}
/**********************************************************************
Creates a junction structure from the Dfs pathname
**********************************************************************/
+
BOOL create_junction(char* pathname, struct junction_map* jn)
{
- struct dfs_path dp;
+ struct dfs_path dp;
- 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,("create_junction: Invalid hostname %s in dfs path %s\n",
- dp.hostname, pathname));
- return False;
- }
-
- /* Check for a non-DFS share */
- if(!lp_msdfs_root(lp_servicenumber(dp.servicename)))
- {
- DEBUG(4,("create_junction: %s is not an msdfs root.\n",
- dp.servicename));
- return False;
- }
+ 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,("create_junction: Invalid hostname %s in dfs path %s\n", dp.hostname, pathname));
+ return False;
+ }
- pstrcpy(jn->service_name,dp.servicename);
- pstrcpy(jn->volume_name,dp.volumename);
- return True;
+ /* Check for a non-DFS share */
+ if(!lp_msdfs_root(lp_servicenumber(dp.servicename))) {
+ DEBUG(4,("create_junction: %s is not an msdfs root.\n", dp.servicename));
+ return False;
+ }
+
+ pstrcpy(jn->service_name,dp.servicename);
+ pstrcpy(jn->volume_name,dp.volumename);
+ return True;
}
/**********************************************************************
Parse the contents of a symlink to verify if it is an msdfs referral
A valid referral is of the form: msdfs:server1\share1,server2\share2
**********************************************************************/
+
static BOOL parse_symlink(char* buf,struct referral** preflist, int* refcount)
{
- pstring temp;
- char* prot;
- char* alt_path[MAX_REFERRAL_COUNT];
- int count=0, i;
- struct referral* reflist;
+ pstring temp;
+ char* prot;
+ char* alt_path[MAX_REFERRAL_COUNT];
+ int count=0, i;
+ struct referral* reflist;
- pstrcpy(temp,buf);
+ pstrcpy(temp,buf);
- prot = strtok(temp,":");
-
- if(!strequal(prot, "msdfs"))
- return False;
-
- /* It's an msdfs referral */
- if(!preflist)
- return True;
-
- /* parse out the alternate paths */
- while(((alt_path[count] = strtok(NULL,",")) != NULL)
- && count<MAX_REFERRAL_COUNT)
- count++;
-
- DEBUG(10,("parse_symlink: count=%d\n", count));
- reflist = *preflist = (struct referral*) malloc(count *
- sizeof(struct referral));
- if(reflist == NULL)
- {
- DEBUG(0,("parse_symlink: Malloc failed!\n"));
- return False;
- }
+ prot = strtok(temp,":");
+
+ if(!strequal(prot, "msdfs"))
+ return False;
+
+ /* It's an msdfs referral */
+ if(!preflist)
+ return True;
+
+ /* parse out the alternate paths */
+ while(((alt_path[count] = strtok(NULL,",")) != NULL) && count<MAX_REFERRAL_COUNT)
+ count++;
+
+ DEBUG(10,("parse_symlink: count=%d\n", count));
+
+ reflist = *preflist = (struct referral*) malloc(count * sizeof(struct referral));
+ if(reflist == NULL) {
+ DEBUG(0,("parse_symlink: Malloc failed!\n"));
+ return False;
+ }
- for(i=0;i<count;i++)
- {
- /* replace / in the alternate path by a \ */
- char* p = strchr(alt_path[i],'/');
- if(p) *p = '\\';
-
- pstrcpy(reflist[i].alternate_path, "\\");
- pstrcat(reflist[i].alternate_path, alt_path[i]);
- reflist[i].proximity = 0;
- reflist[i].ttl = REFERRAL_TTL;
- DEBUG(10, ("parse_symlink: Created alt path: %s\n",
- reflist[i].alternate_path));
- }
-
- if(refcount)
- *refcount = count;
-
- return True;
+ for(i=0;i<count;i++) {
+ /* replace / in the alternate path by a \ */
+ char* p = strchr(alt_path[i],'/');
+ if(p)
+ *p = '\\';
+
+ pstrcpy(reflist[i].alternate_path, "\\");
+ pstrcat(reflist[i].alternate_path, alt_path[i]);
+ reflist[i].proximity = 0;
+ reflist[i].ttl = REFERRAL_TTL;
+ DEBUG(10, ("parse_symlink: Created alt path: %s\n", reflist[i].alternate_path));
+ }
+
+ if(refcount)
+ *refcount = count;
+
+ return True;
}
/**********************************************************************
Returns true if the unix path is a valid msdfs symlink
**********************************************************************/
+
BOOL is_msdfs_link(connection_struct* conn, char* path)
{
- SMB_STRUCT_STAT st;
- pstring referral;
- int referral_len = 0;
+ SMB_STRUCT_STAT st;
+ pstring referral;
+ int referral_len = 0;
- if(!path || !conn)
- return False;
+ if(!path || !conn)
+ return False;
- strlower(path);
+ strlower(path);
- if(conn->vfs_ops.lstat(conn,dos_to_unix(path,False),&st) != 0)
- {
- DEBUG(5,("is_msdfs_link: %s does not exist.\n",path));
- return False;
- }
+ if(conn->vfs_ops.lstat(conn,dos_to_unix(path,False),&st) != 0) {
+ DEBUG(5,("is_msdfs_link: %s does not exist.\n",path));
+ return False;
+ }
- if(S_ISLNK(st.st_mode))
- {
- /* open the link and read it */
- referral_len = readlink(path, referral, sizeof(pstring));
- if(referral_len == -1)
- DEBUG(0,("is_msdfs_link: Error reading msdfs link %s: %s\n",
- path, strerror(errno)));
-
- referral[referral_len] = '\0';
- DEBUG(5,("is_msdfs_link: %s -> %s\n",path,referral));
- if(parse_symlink(referral, NULL, NULL))
- return True;
- }
- return False;
+ if(S_ISLNK(st.st_mode)) {
+ /* open the link and read it */
+ referral_len = conn->vfs_ops.readlink(conn, path, referral, sizeof(pstring));
+ if(referral_len == -1)
+ DEBUG(0,("is_msdfs_link: Error reading msdfs link %s: %s\n", path, strerror(errno)));
+
+ referral[referral_len] = '\0';
+ DEBUG(5,("is_msdfs_link: %s -> %s\n",path,referral));
+ if(parse_symlink(referral, NULL, NULL))
+ return True;
+ }
+ return False;
}
/**********************************************************************
Fills in the junction_map struct with the referrals from the
symbolic link
**********************************************************************/
+
BOOL get_referred_path(struct junction_map* junction)
{
- fstring path;
- pstring buf;
- SMB_STRUCT_STAT st;
-
- if(!form_path_from_junction(junction, path, sizeof(path)))
- return False;
+ pstring path;
+ pstring buf;
+ SMB_STRUCT_STAT st;
+ connection_struct conns;
+ connection_struct *conn = &conns;
+
+ if(!form_path_from_junction(junction, path, sizeof(path), conn))
+ return False;
- DEBUG(5,("get_referred_path: lstat target: %s\n", path));
+ DEBUG(5,("get_referred_path: lstat target: %s\n", path));
- if(lstat(dos_to_unix(path, False),&st) != 0)
- {
- DEBUG(5,("get_referred_path: %s does not exist.\n",path));
- return False;
- }
+ if(conn->vfs_ops.lstat(conn,dos_to_unix(path, False),&st) != 0) {
+ DEBUG(5,("get_referred_path: %s does not exist.\n",path));
+ return False;
+ }
- if(S_ISLNK(st.st_mode))
- {
- /* open the link and read it to get the dfs referral */
- int linkcnt = 0;
- linkcnt = readlink(path, buf, sizeof(buf));
- buf[linkcnt] = '\0';
- DEBUG(5,("get_referred_path: Referral: %s\n",buf));
- if(parse_symlink(buf, &junction->referral_list,
- &junction->referral_count))
- return True;
- }
- return False;
+ if(S_ISLNK(st.st_mode)) {
+ /* open the link and read it to get the dfs referral */
+ int linkcnt = 0;
+ linkcnt = conn->vfs_ops.readlink(conn, path, buf, sizeof(buf));
+ buf[linkcnt] = '\0';
+ DEBUG(5,("get_referred_path: Referral: %s\n",buf));
+ if(parse_symlink(buf, &junction->referral_list, &junction->referral_count))
+ return True;
+ }
+ return False;
}
/**************************************************************
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;
- fstring path;
-
- pstrcpy(temp,pathname);
-
- if(!lp_msdfs_root(SNUM(conn)) )
- return False;
-
- parse_dfs_path(pathname,&dp);
-
- if(global_myname && (strcasecmp(global_myname,dp.hostname)!=0))
- return False;
-
- /* check if need to redirect */
- fstrcpy(path, conn->connectpath);
- fstrcat(path, "/");
- fstrcat(path, dp.volumename);
- if(is_msdfs_link(conn, path))
- {
- 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;
- }
+ struct dfs_path dp;
+ pstring temp;
+ fstring path;
+
+ pstrcpy(temp,pathname);
+
+ if(!lp_msdfs_root(SNUM(conn)) )
+ return False;
+
+ parse_dfs_path(pathname,&dp);
+
+ if(global_myname && (strcasecmp(global_myname,dp.hostname)!=0))
+ return False;
+
+ /* check if need to redirect */
+ fstrcpy(path, conn->connectpath);
+ fstrcat(path, "/");
+ fstrcat(path, dp.volumename);
+ if(is_msdfs_link(conn, path)) {
+ 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;
+ }
}
/*
@@ -316,450 +329,435 @@ BOOL dfs_redirect(char* pathname, connection_struct* conn)
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;
+ 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;
- }
+ 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))) {
+ create_nondfs_path(pathname,&dp);
+ return False;
+ }
+
+ return True;
}
static int setup_ver2_dfs_referral(char* pathname, char** ppdata,
struct junction_map* junction,
BOOL self_referral)
{
- char* pdata = *ppdata;
-
- unsigned char uni_requestedpath[1024];
- int uni_reqpathoffset1,uni_reqpathoffset2;
- int uni_curroffset;
- int requestedpathlen=0;
- int offset;
- int reply_size = 0;
- 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);
- return reply_size;
+ char* pdata = *ppdata;
+
+ unsigned char uni_requestedpath[1024];
+ int uni_reqpathoffset1,uni_reqpathoffset2;
+ int uni_curroffset;
+ int requestedpathlen=0;
+ int offset;
+ int reply_size = 0;
+ 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);
+ return reply_size;
}
static int setup_ver3_dfs_referral(char* pathname, char** ppdata,
struct junction_map* junction,
BOOL self_referral)
{
- char* pdata = *ppdata;
+ char* pdata = *ppdata;
- unsigned char uni_reqpath[1024];
- int uni_reqpathoffset1, uni_reqpathoffset2;
- int uni_curroffset;
- int reply_size = 0;
+ unsigned char uni_reqpath[1024];
+ int uni_reqpathoffset1, uni_reqpathoffset2;
+ int uni_curroffset;
+ int reply_size = 0;
- int reqpathlen = 0;
- int offset,i=0;
+ int reqpathlen = 0;
+ int offset,i=0;
- DEBUG(10,("setting up version3 referral\n"));
+ DEBUG(10,("setting up version3 referral\n"));
- reqpathlen = (dos_struni2(uni_reqpath,pathname,512)+1)*2;
+ 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;
- }
+ 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);
+ /* 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);
+ /* 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);
+ 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);
- return reply_size;
+ 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);
+ return reply_size;
}
-
-
/******************************************************************
* Set up the Dfs referral for the dfs pathname
******************************************************************/
-int setup_dfs_referral(char* pathname, int max_referral_level,
- char** ppdata)
+
+int setup_dfs_referral(char* pathname, int max_referral_level, char** ppdata)
{
- struct junction_map junction;
+ struct junction_map junction;
- BOOL self_referral;
+ BOOL self_referral;
- int reply_size = 0;
+ int reply_size = 0;
- ZERO_STRUCT(junction);
+ ZERO_STRUCT(junction);
- if(!create_junction(pathname, &junction))
- return -1;
+ if(!create_junction(pathname, &junction))
+ return -1;
- /* get the junction entry */
- if(!get_referred_path(&junction))
- {
+ /* get the junction entry */
+ if(!get_referred_path(&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;
+ }
- /* 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: Path %s to alternate path(s):",pathname);
+ for(i=0;i<junction.referral_count;i++)
+ dbgtext(" %s",junction.referral_list[i].alternate_path);
+ dbgtext(".\n");
+ }
}
- 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: Path %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:
+ {
+ reply_size = setup_ver2_dfs_referral(pathname, ppdata, &junction, self_referral);
+ break;
+ }
+ case 3:
+ {
+ reply_size = setup_ver3_dfs_referral(pathname, ppdata, &junction, self_referral);
+ break;
+ }
+ default:
+ {
+ DEBUG(0,("setup_dfs_referral: Invalid dfs referral version: %d\n", max_referral_level));
+ return -1;
+ }
}
- }
- /* 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:
- {
- reply_size = setup_ver2_dfs_referral(pathname, ppdata, &junction,
- self_referral);
- break;
- }
- case 3:
- {
- reply_size = setup_ver3_dfs_referral(pathname, ppdata, &junction,
- self_referral);
- break;
- }
- default:
- {
- DEBUG(0,("setup_dfs_referral: Invalid dfs referral version: %d\n",
- max_referral_level));
- return -1;
- }
- }
-
- DEBUG(10,("DFS Referral pdata:\n"));
- dump_data(10,*ppdata,reply_size);
- return reply_size;
+ DEBUG(10,("DFS Referral pdata:\n"));
+ dump_data(10,*ppdata,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));
+ 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));
}
/**********************************************************************
The following functions are called by the NETDFS RPC pipe functions
**********************************************************************/
+
BOOL create_msdfs_link(struct junction_map* jn, BOOL exists)
{
- pstring path;
- pstring msdfs_link;
- int i=0;
-
- if(!form_path_from_junction(jn, path, sizeof(path)))
- return False;
+ pstring path;
+ pstring msdfs_link;
+ connection_struct conns;
+ connection_struct *conn = &conns;
+ int i=0;
+
+ if(!form_path_from_junction(jn, path, sizeof(path), conn))
+ return False;
- /* form the msdfs_link contents */
- pstrcpy(msdfs_link, "msdfs:");
- for(i=0; i<jn->referral_count; i++)
- {
- char* refpath = jn->referral_list[i].alternate_path;
+ /* form the msdfs_link contents */
+ pstrcpy(msdfs_link, "msdfs:");
+ for(i=0; i<jn->referral_count; i++) {
+ char* refpath = jn->referral_list[i].alternate_path;
- trim_string(refpath, "\\", "\\");
- if(*refpath == '\0')
- continue;
+ trim_string(refpath, "\\", "\\");
+ if(*refpath == '\0')
+ continue;
- if(i>0)
- pstrcat(msdfs_link, ",");
+ if(i>0)
+ pstrcat(msdfs_link, ",");
- pstrcat(msdfs_link, refpath);
- }
-
- DEBUG(5,("create_msdfs_link: Creating new msdfs link: %s -> %s\n",
- path, msdfs_link));
-
- if(exists)
- if(unlink(path)!=0)
- return False;
-
- if(symlink(msdfs_link, path) < 0)
- {
- DEBUG(1,("create_msdfs_link: symlink failed %s -> %s\nError: %s\n",
- path, msdfs_link, strerror(errno)));
- return False;
- }
- return True;
+ pstrcat(msdfs_link, refpath);
+ }
+
+ DEBUG(5,("create_msdfs_link: Creating new msdfs link: %s -> %s\n", path, msdfs_link));
+
+ if(exists)
+ if(conn->vfs_ops.unlink(conn,path)!=0)
+ return False;
+
+ if(conn->vfs_ops.symlink(conn, msdfs_link, path) < 0) {
+ DEBUG(1,("create_msdfs_link: symlink failed %s -> %s\nError: %s\n",
+ path, msdfs_link, strerror(errno)));
+ return False;
+ }
+ return True;
}
BOOL remove_msdfs_link(struct junction_map* jn)
{
- pstring path;
+ pstring path;
+ connection_struct conns;
+ connection_struct *conn = &conns;
- if(!form_path_from_junction(jn, path, sizeof(path)))
- return False;
+ if(!form_path_from_junction(jn, path, sizeof(path), conn))
+ return False;
- if(unlink(path)!=0)
- return False;
+ if(conn->vfs_ops.unlink(conn, path)!=0)
+ return False;
- return True;
+ return True;
}
static BOOL form_junctions(int snum, struct junction_map* jn, int* jn_count)
{
- int cnt = *jn_count;
- DIR *dirp;
- char* dname;
-
- char* connect_path = lp_pathname(snum);
- char* service_name = lp_servicename(snum);
+ int cnt = *jn_count;
+ DIR *dirp;
+ char* dname;
+ pstring connect_path;
+ char* service_name = lp_servicename(snum);
+ connection_struct conns;
+ connection_struct *conn = &conns;
- if(*connect_path == '\0')
- return False;
-
- /* form a junction for the msdfs root - convention */
- /*
- pstrpcy(jn[cnt].service_name, service_name);
- jn[cnt].volume_name[0] = '\0';
- jn[cnt].referral_count = 1;
+ pstrcpy(connect_path,lp_pathname(snum));
+
+ if(*connect_path == '\0')
+ return False;
+
+ /*
+ * Fake up a connection struct for the VFS layer.
+ */
+
+ if (!create_conn_struct(conn, snum, connect_path))
+ return False;
+
+ /* form a junction for the msdfs root - convention */
+ /*
+ pstrpcy(jn[cnt].service_name, service_name);
+ jn[cnt].volume_name[0] = '\0';
+ jn[cnt].referral_count = 1;
- slprintf(alt_path,sizeof(alt_path)-1"\\\\%s\\%s", global_myname, service_name);
- jn[cnt].referral_l
- */
-
- dirp = opendir(connect_path);
- if(!dirp)
- return False;
-
- while((dname = readdirname(dirp)) != NULL)
- {
- SMB_STRUCT_STAT st;
- pstring pathreal;
- fstring buf;
- int buflen = 0;
- pstrcpy(pathreal, connect_path);
- pstrcat(pathreal, "/");
- pstrcat(pathreal, dname);
+ slprintf(alt_path,sizeof(alt_path)-1"\\\\%s\\%s", global_myname, service_name);
+ jn[cnt].referral_l
+ */
+
+ dirp = conn->vfs_ops.opendir(conn, dos_to_unix(connect_path,False));
+ if(!dirp)
+ return False;
+
+ while((dname = vfs_readdirname(conn, dirp)) != NULL) {
+ SMB_STRUCT_STAT st;
+ pstring pathreal;
+ fstring buf;
+ int buflen = 0;
+ pstrcpy(pathreal, connect_path);
+ pstrcat(pathreal, "/");
+ pstrcat(pathreal, dname);
- if(lstat(pathreal,&st) != 0)
- {
- DEBUG(4,("lstat error for %s: %s\n",pathreal, strerror(errno)));
- continue;
+ if(conn->vfs_ops.lstat(conn,pathreal,&st) != 0) {
+ DEBUG(4,("lstat error for %s: %s\n",pathreal, strerror(errno)));
+ continue;
+ }
+ if(S_ISLNK(st.st_mode)) {
+ buflen = conn->vfs_ops.readlink(conn, dos_to_unix(pathreal,False), buf, sizeof(fstring));
+ buf[buflen] = '\0';
+ if(parse_symlink(buf, &(jn[cnt].referral_list), &(jn[cnt].referral_count))) {
+ pstrcpy(jn[cnt].service_name, service_name);
+ pstrcpy(jn[cnt].volume_name, dname);
+ cnt++;
+ }
+ }
}
- if(S_ISLNK(st.st_mode))
- {
- buflen = readlink(pathreal, buf, sizeof(fstring));
- buf[buflen] = '\0';
- if(parse_symlink(buf, &(jn[cnt].referral_list),
- &(jn[cnt].referral_count)))
- {
- pstrcpy(jn[cnt].service_name, service_name);
- pstrcpy(jn[cnt].volume_name, dname);
- cnt++;
- }
- }
- }
- closedir(dirp);
- *jn_count = cnt;
- return True;
+ conn->vfs_ops.closedir(conn,dirp);
+ *jn_count = cnt;
+ return True;
}
int enum_msdfs_links(struct junction_map* jn)
{
- int i=0;
- int jn_count = 0;
-
- if(!lp_host_msdfs())
- return -1;
-
- for(i=0;*lp_servicename(i);i++)
- {
- if(lp_msdfs_root(i))
- form_junctions(i,jn,&jn_count);
- }
- return jn_count;
+ int i=0;
+ int jn_count = 0;
+
+ if(!lp_host_msdfs())
+ return -1;
+
+ for(i=0;*lp_servicename(i);i++) {
+ if(lp_msdfs_root(i))
+ form_junctions(i,jn,&jn_count);
+ }
+ return jn_count;
}
#else
/* Stub functions if WITH_MSDFS not defined */
-int setup_dfs_referral(char* pathname, int max_referral_level,
+ int setup_dfs_referral(connection_struct *conn, char* pathname, int max_referral_level,
char** ppdata)
{
- return -1;
+ return -1;
}
-BOOL is_msdfs_link(connection_struct* conn, char* path)
+ BOOL is_msdfs_link(connection_struct* conn, char* path)
{
- return False;
+ return False;
}
#endif
diff --git a/source3/smbd/service.c b/source3/smbd/service.c
index 61da72b2e9..0e2c0ff7a1 100644
--- a/source3/smbd/service.c
+++ b/source3/smbd/service.c
@@ -524,28 +524,10 @@ connection_struct *make_connection(char *service,char *user,char *password, int
}
/* Initialise VFS function pointers */
- if (*lp_vfsobj(SNUM(conn))) {
-
-#ifdef HAVE_LIBDL
-
- /* Loadable object file */
-
- if (!vfs_init_custom(conn)) {
- DEBUG(0, ("vfs_init failed\n"));
- conn_free(conn);
- return NULL;
- }
-#else
- DEBUG(0, ("No libdl present - cannot use VFS objects\n"));
- conn_free(conn);
- return NULL;
-#endif
-
- } else {
-
- /* Normal share - initialise with disk access functions */
-
- vfs_init_default(conn);
+ if (!vfs_init(conn)) {
+ DEBUG(0, ("vfs_init failed for service %s\n", lp_servicename(SNUM(conn))));
+ conn_free(conn);
+ return NULL;
}
/* execute any "root preexec = " line */
diff --git a/source3/smbd/vfs-wrap.c b/source3/smbd/vfs-wrap.c
index da8484e14e..a0b4966c59 100644
--- a/source3/smbd/vfs-wrap.c
+++ b/source3/smbd/vfs-wrap.c
@@ -558,6 +558,38 @@ BOOL vfswrap_lock(files_struct *fsp, int fd, int op, SMB_OFF_T offset, SMB_OFF_T
return result;
}
+int vfswrap_symlink(connection_struct *conn, const char *oldpath, const char *newpath)
+{
+ int result;
+
+ START_PROFILE(syscall_symlink);
+
+#ifdef VFS_CHECK_NULL
+ if ((oldpath == NULL) || (newpath == NULL))
+ smb_panic("NULL pointer passed to vfswrap_symlink()\n");
+#endif
+
+ result = sys_symlink(oldpath, newpath);
+ END_PROFILE(syscall_symlink);
+ return result;
+}
+
+int vfswrap_readlink(connection_struct *conn, const char *path, char *buf, size_t bufsiz)
+{
+ int result;
+
+ START_PROFILE(syscall_readlink);
+
+#ifdef VFS_CHECK_NULL
+ if ((path == NULL) || (buf == NULL))
+ smb_panic("NULL pointer passed to vfswrap_readlink()\n");
+#endif
+
+ result = sys_readlink(path, buf, bufsiz);
+ END_PROFILE(syscall_readlink);
+ return result;
+}
+
size_t vfswrap_fget_nt_acl(files_struct *fsp, int fd, SEC_DESC **ppdesc)
{
return get_nt_acl(fsp, ppdesc);
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index 713d58cdc8..ac00d00e9e 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -72,6 +72,9 @@ struct vfs_ops default_vfs_ops = {
vfswrap_utime,
vfswrap_ftruncate,
vfswrap_lock,
+ vfswrap_symlink,
+ vfswrap_readlink,
+
vfswrap_fget_nt_acl,
vfswrap_get_nt_acl,
vfswrap_fset_nt_acl,
@@ -89,7 +92,8 @@ struct vfs_ops default_vfs_ops = {
/****************************************************************************
initialise default vfs hooks
****************************************************************************/
-int vfs_init_default(connection_struct *conn)
+
+static BOOL vfs_init_default(connection_struct *conn)
{
DEBUG(3, ("Initialising default vfs hooks\n"));
@@ -102,7 +106,7 @@ int vfs_init_default(connection_struct *conn)
****************************************************************************/
#ifdef HAVE_LIBDL
-BOOL vfs_init_custom(connection_struct *conn)
+static BOOL vfs_init_custom(connection_struct *conn)
{
int vfs_version = -1;
struct vfs_ops *ops, *(*init_fptr)(int *);
@@ -146,145 +150,146 @@ BOOL vfs_init_custom(connection_struct *conn)
memcpy(&conn->vfs_ops, ops, sizeof(struct vfs_ops));
- if (conn->vfs_ops.connect == NULL) {
- conn->vfs_ops.connect = default_vfs_ops.connect;
- }
+ if (conn->vfs_ops.connect == NULL)
+ conn->vfs_ops.connect = default_vfs_ops.connect;
- if (conn->vfs_ops.disconnect == NULL) {
- conn->vfs_ops.disconnect = default_vfs_ops.disconnect;
- }
+ if (conn->vfs_ops.disconnect == NULL)
+ conn->vfs_ops.disconnect = default_vfs_ops.disconnect;
- if (conn->vfs_ops.disk_free == NULL) {
- conn->vfs_ops.disk_free = default_vfs_ops.disk_free;
- }
+ if (conn->vfs_ops.disk_free == NULL)
+ conn->vfs_ops.disk_free = default_vfs_ops.disk_free;
- if (conn->vfs_ops.opendir == NULL) {
- conn->vfs_ops.opendir = default_vfs_ops.opendir;
- }
+ if (conn->vfs_ops.opendir == NULL)
+ conn->vfs_ops.opendir = default_vfs_ops.opendir;
- if (conn->vfs_ops.readdir == NULL) {
- conn->vfs_ops.readdir = default_vfs_ops.readdir;
- }
+ if (conn->vfs_ops.readdir == NULL)
+ conn->vfs_ops.readdir = default_vfs_ops.readdir;
- if (conn->vfs_ops.mkdir == NULL) {
- conn->vfs_ops.mkdir = default_vfs_ops.mkdir;
- }
+ if (conn->vfs_ops.mkdir == NULL)
+ conn->vfs_ops.mkdir = default_vfs_ops.mkdir;
- if (conn->vfs_ops.rmdir == NULL) {
- conn->vfs_ops.rmdir = default_vfs_ops.rmdir;
- }
+ if (conn->vfs_ops.rmdir == NULL)
+ conn->vfs_ops.rmdir = default_vfs_ops.rmdir;
- if (conn->vfs_ops.closedir == NULL) {
- conn->vfs_ops.closedir = default_vfs_ops.closedir;
- }
+ if (conn->vfs_ops.closedir == NULL)
+ conn->vfs_ops.closedir = default_vfs_ops.closedir;
- if (conn->vfs_ops.open == NULL) {
- conn->vfs_ops.open = default_vfs_ops.open;
- }
+ if (conn->vfs_ops.open == NULL)
+ conn->vfs_ops.open = default_vfs_ops.open;
- if (conn->vfs_ops.close == NULL) {
- conn->vfs_ops.close = default_vfs_ops.close;
- }
+ if (conn->vfs_ops.close == NULL)
+ conn->vfs_ops.close = default_vfs_ops.close;
- if (conn->vfs_ops.read == NULL) {
- conn->vfs_ops.read = default_vfs_ops.read;
- }
+ if (conn->vfs_ops.read == NULL)
+ conn->vfs_ops.read = default_vfs_ops.read;
- if (conn->vfs_ops.write == NULL) {
- conn->vfs_ops.write = default_vfs_ops.write;
- }
+ if (conn->vfs_ops.write == NULL)
+ conn->vfs_ops.write = default_vfs_ops.write;
- if (conn->vfs_ops.lseek == NULL) {
- conn->vfs_ops.lseek = default_vfs_ops.lseek;
- }
+ if (conn->vfs_ops.lseek == NULL)
+ conn->vfs_ops.lseek = default_vfs_ops.lseek;
- if (conn->vfs_ops.rename == NULL) {
- conn->vfs_ops.rename = default_vfs_ops.rename;
- }
+ if (conn->vfs_ops.rename == NULL)
+ conn->vfs_ops.rename = default_vfs_ops.rename;
- if (conn->vfs_ops.fsync == NULL) {
- conn->vfs_ops.fsync = default_vfs_ops.fsync;
- }
+ if (conn->vfs_ops.fsync == NULL)
+ conn->vfs_ops.fsync = default_vfs_ops.fsync;
- if (conn->vfs_ops.stat == NULL) {
- conn->vfs_ops.stat = default_vfs_ops.stat;
- }
+ if (conn->vfs_ops.stat == NULL)
+ conn->vfs_ops.stat = default_vfs_ops.stat;
- if (conn->vfs_ops.fstat == NULL) {
- conn->vfs_ops.fstat = default_vfs_ops.fstat;
- }
+ if (conn->vfs_ops.fstat == NULL)
+ conn->vfs_ops.fstat = default_vfs_ops.fstat;
- if (conn->vfs_ops.lstat == NULL) {
- conn->vfs_ops.lstat = default_vfs_ops.lstat;
- }
+ if (conn->vfs_ops.lstat == NULL)
+ conn->vfs_ops.lstat = default_vfs_ops.lstat;
- if (conn->vfs_ops.unlink == NULL) {
- conn->vfs_ops.unlink = default_vfs_ops.unlink;
- }
+ if (conn->vfs_ops.unlink == NULL)
+ conn->vfs_ops.unlink = default_vfs_ops.unlink;
- if (conn->vfs_ops.chmod == NULL) {
- conn->vfs_ops.chmod = default_vfs_ops.chmod;
- }
+ if (conn->vfs_ops.chmod == NULL)
+ conn->vfs_ops.chmod = default_vfs_ops.chmod;
- if (conn->vfs_ops.fchmod == NULL) {
- conn->vfs_ops.fchmod = default_vfs_ops.fchmod;
- }
+ if (conn->vfs_ops.fchmod == NULL)
+ conn->vfs_ops.fchmod = default_vfs_ops.fchmod;
- if (conn->vfs_ops.chown == NULL) {
- conn->vfs_ops.chown = default_vfs_ops.chown;
- }
+ if (conn->vfs_ops.chown == NULL)
+ conn->vfs_ops.chown = default_vfs_ops.chown;
- if (conn->vfs_ops.fchown == NULL) {
- conn->vfs_ops.fchown = default_vfs_ops.fchown;
- }
+ if (conn->vfs_ops.fchown == NULL)
+ conn->vfs_ops.fchown = default_vfs_ops.fchown;
- if (conn->vfs_ops.chdir == NULL) {
- conn->vfs_ops.chdir = default_vfs_ops.chdir;
- }
+ if (conn->vfs_ops.chdir == NULL)
+ conn->vfs_ops.chdir = default_vfs_ops.chdir;
- if (conn->vfs_ops.getwd == NULL) {
- conn->vfs_ops.getwd = default_vfs_ops.getwd;
- }
+ if (conn->vfs_ops.getwd == NULL)
+ conn->vfs_ops.getwd = default_vfs_ops.getwd;
- if (conn->vfs_ops.utime == NULL) {
- conn->vfs_ops.utime = default_vfs_ops.utime;
- }
+ if (conn->vfs_ops.utime == NULL)
+ conn->vfs_ops.utime = default_vfs_ops.utime;
- if (conn->vfs_ops.ftruncate == NULL) {
- conn->vfs_ops.ftruncate = default_vfs_ops.ftruncate;
- }
+ if (conn->vfs_ops.ftruncate == NULL)
+ conn->vfs_ops.ftruncate = default_vfs_ops.ftruncate;
- if (conn->vfs_ops.lock == NULL) {
- conn->vfs_ops.lock = default_vfs_ops.lock;
- }
+ if (conn->vfs_ops.lock == NULL)
+ conn->vfs_ops.lock = default_vfs_ops.lock;
- if (conn->vfs_ops.fget_nt_acl == NULL) {
- conn->vfs_ops.fget_nt_acl = default_vfs_ops.fget_nt_acl;
- }
+ if (conn->vfs_ops.symlink == NULL)
+ conn->vfs_ops.symlink = default_vfs_ops.symlink;
- if (conn->vfs_ops.get_nt_acl == NULL) {
- conn->vfs_ops.get_nt_acl = default_vfs_ops.get_nt_acl;
- }
+ if (conn->vfs_ops.readlink == NULL)
+ conn->vfs_ops.readlink = default_vfs_ops.readlink;
- if (conn->vfs_ops.fset_nt_acl == NULL) {
- conn->vfs_ops.fset_nt_acl = default_vfs_ops.fset_nt_acl;
- }
+ if (conn->vfs_ops.fget_nt_acl == NULL)
+ conn->vfs_ops.fget_nt_acl = default_vfs_ops.fget_nt_acl;
- if (conn->vfs_ops.set_nt_acl == NULL) {
- conn->vfs_ops.set_nt_acl = default_vfs_ops.set_nt_acl;
- }
+ if (conn->vfs_ops.get_nt_acl == NULL)
+ conn->vfs_ops.get_nt_acl = default_vfs_ops.get_nt_acl;
- if (conn->vfs_ops.chmod_acl == NULL) {
- conn->vfs_ops.chmod_acl = default_vfs_ops.chmod_acl;
- }
+ if (conn->vfs_ops.fset_nt_acl == NULL)
+ conn->vfs_ops.fset_nt_acl = default_vfs_ops.fset_nt_acl;
+
+ if (conn->vfs_ops.set_nt_acl == NULL)
+ conn->vfs_ops.set_nt_acl = default_vfs_ops.set_nt_acl;
+
+ if (conn->vfs_ops.chmod_acl == NULL)
+ conn->vfs_ops.chmod_acl = default_vfs_ops.chmod_acl;
+
+ if (conn->vfs_ops.fchmod_acl == NULL)
+ conn->vfs_ops.fchmod_acl = default_vfs_ops.fchmod_acl;
- if (conn->vfs_ops.fchmod_acl == NULL) {
- conn->vfs_ops.fchmod_acl = default_vfs_ops.fchmod_acl;
- }
return True;
}
#endif
+/*****************************************************************
+ Generic VFS init.
+******************************************************************/
+
+BOOL vfs_init(connection_struct *conn)
+{
+ if (*lp_vfsobj(SNUM(conn))) {
+#ifdef HAVE_LIBDL
+
+ /* Loadable object file */
+
+ if (!vfs_init_custom(conn)) {
+ DEBUG(0, ("vfs_init: vfs_init_custom failed\n"));
+ return False;
+ }
+
+ return True;
+#else
+ DEBUG(0, ("vfs_init: No libdl present - cannot use VFS objects\n"));
+ return False;
+#endif
+ }
+
+ /* Normal share - initialise with disk access functions */
+
+ return vfs_init_default(conn);
+}
+
/*******************************************************************
Check if directory exists.
********************************************************************/