1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-03 04:22:09 +03:00

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 commit is contained in:
Jeremy Allison
-
parent 001e9b7b54
commit c24e6b41ea
9 changed files with 693 additions and 640 deletions

2
source/configure vendored
View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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. */

View File

@ -264,6 +264,34 @@ char *sys_getwd(char *s)
return wd;
}
/*******************************************************************
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
********************************************************************/

View File

@ -30,6 +30,7 @@ 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);
@ -41,6 +42,7 @@ static void create_nondfs_path(char* pathname, struct dfs_path* pdp)
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;
@ -66,8 +68,7 @@ static BOOL parse_dfs_path(char* pathname, struct dfs_path* pdp)
/* parse out servicename */
temp = p+1;
p = strchr(temp,'\\');
if(p == NULL)
{
if(p == NULL) {
pstrcpy(pdp->servicename,temp);
return True;
}
@ -78,8 +79,7 @@ static BOOL parse_dfs_path(char* pathname, struct dfs_path* pdp)
/* parse out volumename */
temp = p+1;
p = strchr(temp,'\\');
if(p == NULL)
{
if(p == NULL) {
pstrcpy(pdp->volumename,temp);
return True;
}
@ -93,11 +93,29 @@ static BOOL parse_dfs_path(char* pathname, struct dfs_path* pdp)
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;
@ -112,12 +130,17 @@ static BOOL form_path_from_junction(struct junction_map* jn, char* path,
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;
@ -125,18 +148,14 @@ BOOL create_junction(char* pathname, struct junction_map* jn)
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));
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));
if(!lp_msdfs_root(lp_servicenumber(dp.servicename))) {
DEBUG(4,("create_junction: %s is not an msdfs root.\n", dp.servicename));
return False;
}
@ -149,6 +168,7 @@ BOOL create_junction(char* pathname, struct junction_map* jn)
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;
@ -169,31 +189,28 @@ static BOOL parse_symlink(char* buf,struct referral** preflist, int* refcount)
return True;
/* parse out the alternate paths */
while(((alt_path[count] = strtok(NULL,",")) != NULL)
&& count<MAX_REFERRAL_COUNT)
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)
{
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++)
{
for(i=0;i<count;i++) {
/* replace / in the alternate path by a \ */
char* p = strchr(alt_path[i],'/');
if(p) *p = '\\';
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));
DEBUG(10, ("parse_symlink: Created alt path: %s\n", reflist[i].alternate_path));
}
if(refcount)
@ -205,6 +222,7 @@ static BOOL parse_symlink(char* buf,struct referral** preflist, int* refcount)
/**********************************************************************
Returns true if the unix path is a valid msdfs symlink
**********************************************************************/
BOOL is_msdfs_link(connection_struct* conn, char* path)
{
SMB_STRUCT_STAT st;
@ -216,19 +234,16 @@ BOOL is_msdfs_link(connection_struct* conn, char* path)
strlower(path);
if(conn->vfs_ops.lstat(conn,dos_to_unix(path,False),&st) != 0)
{
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))
{
if(S_ISLNK(st.st_mode)) {
/* open the link and read it */
referral_len = readlink(path, referral, sizeof(pstring));
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)));
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));
@ -242,32 +257,32 @@ BOOL is_msdfs_link(connection_struct* conn, char* path)
Fills in the junction_map struct with the referrals from the
symbolic link
**********************************************************************/
BOOL get_referred_path(struct junction_map* junction)
{
fstring path;
pstring path;
pstring buf;
SMB_STRUCT_STAT st;
connection_struct conns;
connection_struct *conn = &conns;
if(!form_path_from_junction(junction, path, sizeof(path)))
if(!form_path_from_junction(junction, path, sizeof(path), conn))
return False;
DEBUG(5,("get_referred_path: lstat target: %s\n", path));
if(lstat(dos_to_unix(path, False),&st) != 0)
{
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))
{
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));
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))
if(parse_symlink(buf, &junction->referral_list, &junction->referral_count))
return True;
}
return False;
@ -277,6 +292,7 @@ BOOL get_referred_path(struct junction_map* junction)
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;
@ -297,13 +313,10 @@ BOOL dfs_redirect(char* pathname, connection_struct* conn)
fstrcpy(path, conn->connectpath);
fstrcat(path, "/");
fstrcat(path, dp.volumename);
if(is_msdfs_link(conn, path))
{
if(is_msdfs_link(conn, path)) {
DEBUG(4,("dfs_redirect: Redirecting %s\n",temp));
return True;
}
else
{
} else {
create_nondfs_path(pathname,&dp);
DEBUG(4,("dfs_redirect: Not redirecting %s. Converted to non-dfs pathname \'%s\'\n",
temp,pathname));
@ -316,6 +329,7 @@ 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;
@ -325,21 +339,20 @@ BOOL dfs_findfirst_redirect(char* pathname, connection_struct* conn)
pstrcpy(temp,pathname);
/* Is the path Dfs-redirectable? */
if(!dfs_redirect(temp,conn))
{
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
{
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,
@ -376,8 +389,7 @@ static int setup_ver2_dfs_referral(char* pathname, char** ppdata,
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++)
{
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;
}
@ -387,8 +399,7 @@ static int setup_ver2_dfs_referral(char* pathname, char** ppdata,
reply_size += 0x16;
pdata = *ppdata = Realloc(pdata,reply_size);
if(pdata == NULL)
{
if(pdata == NULL) {
DEBUG(0,("malloc failed for Realloc!\n"));
return -1;
}
@ -397,7 +408,6 @@ static int setup_ver2_dfs_referral(char* pathname, char** ppdata,
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 */
@ -408,8 +418,7 @@ static int setup_ver2_dfs_referral(char* pathname, char** ppdata,
offset = 8;
/* add the referral elements */
for(i=0;i<junction->referral_count;i++)
{
for(i=0;i<junction->referral_count;i++) {
struct referral* ref = &(junction->referral_list[i]);
int unilen;
@ -426,8 +435,7 @@ static int setup_ver2_dfs_referral(char* pathname, char** ppdata,
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;
unilen = (dos_struni2(pdata+uni_curroffset,ref->alternate_path,512) +1)*2;
SSVAL(pdata,offset+20,uni_curroffset-offset);
uni_curroffset += unilen;
@ -459,20 +467,17 @@ static int setup_ver3_dfs_referral(char* pathname, char** ppdata,
dump_data(10,uni_reqpath,reqpathlen);
uni_reqpathoffset1 = REFERRAL_HEADER_SIZE + VERSION3_REFERRAL_SIZE *
junction->referral_count;
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++)
{
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)
{
if(pdata == NULL) {
DEBUG(0,("version3 referral setup: malloc failed for Realloc!\n"));
return -1;
}
@ -490,8 +495,7 @@ static int setup_ver3_dfs_referral(char* pathname, char** ppdata,
memcpy(pdata+uni_reqpathoffset2,uni_reqpath,reqpathlen);
offset = 8;
for(i=0;i<junction->referral_count;i++)
{
for(i=0;i<junction->referral_count;i++) {
struct referral* ref = &(junction->referral_list[i]);
int unilen;
@ -508,8 +512,7 @@ static int setup_ver3_dfs_referral(char* pathname, char** ppdata,
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;
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);
@ -521,13 +524,11 @@ static int setup_ver3_dfs_referral(char* pathname, char** ppdata,
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;
@ -541,15 +542,13 @@ int setup_dfs_referral(char* pathname, int max_referral_level,
return -1;
/* get the junction entry */
if(!get_referred_path(&junction))
{
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)
{
if((ref = (struct referral*) malloc(sizeof(struct referral))) == NULL) {
DEBUG(0,("malloc failed for referral\n"));
return -1;
}
@ -558,12 +557,9 @@ int setup_dfs_referral(char* pathname, int max_referral_level,
ref->proximity = 0;
ref->ttl = REFERRAL_TTL;
junction.referral_list = ref;
}
else
{
} else {
self_referral = False;
if( DEBUGLVL( 3 ) )
{
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++)
@ -574,26 +570,23 @@ int setup_dfs_referral(char* pathname, int max_referral_level,
/* 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;
if(max_referral_level<2 || max_referral_level>3)
max_referral_level = 2;
switch(max_referral_level)
{
switch(max_referral_level) {
case 2:
{
reply_size = setup_ver2_dfs_referral(pathname, ppdata, &junction,
self_referral);
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);
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));
DEBUG(0,("setup_dfs_referral: Invalid dfs referral version: %d\n", max_referral_level));
return -1;
}
}
@ -607,8 +600,7 @@ 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)) )
{
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));
}
@ -618,19 +610,21 @@ int dfs_path_error(char* inbuf, char* outbuf)
/**********************************************************************
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;
connection_struct conns;
connection_struct *conn = &conns;
int i=0;
if(!form_path_from_junction(jn, path, sizeof(path)))
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++)
{
for(i=0; i<jn->referral_count; i++) {
char* refpath = jn->referral_list[i].alternate_path;
trim_string(refpath, "\\", "\\");
@ -643,15 +637,13 @@ BOOL create_msdfs_link(struct junction_map* jn, BOOL exists)
pstrcat(msdfs_link, refpath);
}
DEBUG(5,("create_msdfs_link: Creating new msdfs link: %s -> %s\n",
path, msdfs_link));
DEBUG(5,("create_msdfs_link: Creating new msdfs link: %s -> %s\n", path, msdfs_link));
if(exists)
if(unlink(path)!=0)
if(conn->vfs_ops.unlink(conn,path)!=0)
return False;
if(symlink(msdfs_link, path) < 0)
{
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;
@ -662,11 +654,13 @@ BOOL create_msdfs_link(struct junction_map* jn, BOOL exists)
BOOL remove_msdfs_link(struct junction_map* jn)
{
pstring path;
connection_struct conns;
connection_struct *conn = &conns;
if(!form_path_from_junction(jn, path, sizeof(path)))
if(!form_path_from_junction(jn, path, sizeof(path), conn))
return False;
if(unlink(path)!=0)
if(conn->vfs_ops.unlink(conn, path)!=0)
return False;
return True;
@ -677,13 +671,23 @@ 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);
pstring connect_path;
char* service_name = lp_servicename(snum);
connection_struct conns;
connection_struct *conn = &conns;
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);
@ -694,12 +698,11 @@ static BOOL form_junctions(int snum, struct junction_map* jn, int* jn_count)
jn[cnt].referral_l
*/
dirp = opendir(connect_path);
dirp = conn->vfs_ops.opendir(conn, dos_to_unix(connect_path,False));
if(!dirp)
return False;
while((dname = readdirname(dirp)) != NULL)
{
while((dname = vfs_readdirname(conn, dirp)) != NULL) {
SMB_STRUCT_STAT st;
pstring pathreal;
fstring buf;
@ -708,18 +711,14 @@ static BOOL form_junctions(int snum, struct junction_map* jn, int* jn_count)
pstrcat(pathreal, "/");
pstrcat(pathreal, dname);
if(lstat(pathreal,&st) != 0)
{
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 = readlink(pathreal, buf, sizeof(fstring));
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)))
{
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++;
@ -727,7 +726,7 @@ static BOOL form_junctions(int snum, struct junction_map* jn, int* jn_count)
}
}
closedir(dirp);
conn->vfs_ops.closedir(conn,dirp);
*jn_count = cnt;
return True;
}
@ -740,8 +739,7 @@ int enum_msdfs_links(struct junction_map* jn)
if(!lp_host_msdfs())
return -1;
for(i=0;*lp_servicename(i);i++)
{
for(i=0;*lp_servicename(i);i++) {
if(lp_msdfs_root(i))
form_junctions(i,jn,&jn_count);
}
@ -751,7 +749,7 @@ int enum_msdfs_links(struct junction_map* jn)
#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;

View File

@ -524,29 +524,11 @@ 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"));
if (!vfs_init(conn)) {
DEBUG(0, ("vfs_init failed for service %s\n", lp_servicename(SNUM(conn))));
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);
}
/* execute any "root preexec = " line */
if (*lp_rootpreexec(SNUM(conn))) {

View File

@ -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);

View File

@ -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) {
if (conn->vfs_ops.connect == NULL)
conn->vfs_ops.connect = default_vfs_ops.connect;
}
if (conn->vfs_ops.disconnect == NULL) {
if (conn->vfs_ops.disconnect == NULL)
conn->vfs_ops.disconnect = default_vfs_ops.disconnect;
}
if (conn->vfs_ops.disk_free == NULL) {
if (conn->vfs_ops.disk_free == NULL)
conn->vfs_ops.disk_free = default_vfs_ops.disk_free;
}
if (conn->vfs_ops.opendir == NULL) {
if (conn->vfs_ops.opendir == NULL)
conn->vfs_ops.opendir = default_vfs_ops.opendir;
}
if (conn->vfs_ops.readdir == NULL) {
if (conn->vfs_ops.readdir == NULL)
conn->vfs_ops.readdir = default_vfs_ops.readdir;
}
if (conn->vfs_ops.mkdir == NULL) {
if (conn->vfs_ops.mkdir == NULL)
conn->vfs_ops.mkdir = default_vfs_ops.mkdir;
}
if (conn->vfs_ops.rmdir == NULL) {
if (conn->vfs_ops.rmdir == NULL)
conn->vfs_ops.rmdir = default_vfs_ops.rmdir;
}
if (conn->vfs_ops.closedir == NULL) {
if (conn->vfs_ops.closedir == NULL)
conn->vfs_ops.closedir = default_vfs_ops.closedir;
}
if (conn->vfs_ops.open == NULL) {
if (conn->vfs_ops.open == NULL)
conn->vfs_ops.open = default_vfs_ops.open;
}
if (conn->vfs_ops.close == NULL) {
if (conn->vfs_ops.close == NULL)
conn->vfs_ops.close = default_vfs_ops.close;
}
if (conn->vfs_ops.read == NULL) {
if (conn->vfs_ops.read == NULL)
conn->vfs_ops.read = default_vfs_ops.read;
}
if (conn->vfs_ops.write == NULL) {
if (conn->vfs_ops.write == NULL)
conn->vfs_ops.write = default_vfs_ops.write;
}
if (conn->vfs_ops.lseek == NULL) {
if (conn->vfs_ops.lseek == NULL)
conn->vfs_ops.lseek = default_vfs_ops.lseek;
}
if (conn->vfs_ops.rename == NULL) {
if (conn->vfs_ops.rename == NULL)
conn->vfs_ops.rename = default_vfs_ops.rename;
}
if (conn->vfs_ops.fsync == NULL) {
if (conn->vfs_ops.fsync == NULL)
conn->vfs_ops.fsync = default_vfs_ops.fsync;
}
if (conn->vfs_ops.stat == NULL) {
if (conn->vfs_ops.stat == NULL)
conn->vfs_ops.stat = default_vfs_ops.stat;
}
if (conn->vfs_ops.fstat == NULL) {
if (conn->vfs_ops.fstat == NULL)
conn->vfs_ops.fstat = default_vfs_ops.fstat;
}
if (conn->vfs_ops.lstat == NULL) {
if (conn->vfs_ops.lstat == NULL)
conn->vfs_ops.lstat = default_vfs_ops.lstat;
}
if (conn->vfs_ops.unlink == NULL) {
if (conn->vfs_ops.unlink == NULL)
conn->vfs_ops.unlink = default_vfs_ops.unlink;
}
if (conn->vfs_ops.chmod == NULL) {
if (conn->vfs_ops.chmod == NULL)
conn->vfs_ops.chmod = default_vfs_ops.chmod;
}
if (conn->vfs_ops.fchmod == NULL) {
if (conn->vfs_ops.fchmod == NULL)
conn->vfs_ops.fchmod = default_vfs_ops.fchmod;
}
if (conn->vfs_ops.chown == NULL) {
if (conn->vfs_ops.chown == NULL)
conn->vfs_ops.chown = default_vfs_ops.chown;
}
if (conn->vfs_ops.fchown == NULL) {
if (conn->vfs_ops.fchown == NULL)
conn->vfs_ops.fchown = default_vfs_ops.fchown;
}
if (conn->vfs_ops.chdir == NULL) {
if (conn->vfs_ops.chdir == NULL)
conn->vfs_ops.chdir = default_vfs_ops.chdir;
}
if (conn->vfs_ops.getwd == NULL) {
if (conn->vfs_ops.getwd == NULL)
conn->vfs_ops.getwd = default_vfs_ops.getwd;
}
if (conn->vfs_ops.utime == NULL) {
if (conn->vfs_ops.utime == NULL)
conn->vfs_ops.utime = default_vfs_ops.utime;
}
if (conn->vfs_ops.ftruncate == NULL) {
if (conn->vfs_ops.ftruncate == NULL)
conn->vfs_ops.ftruncate = default_vfs_ops.ftruncate;
}
if (conn->vfs_ops.lock == NULL) {
if (conn->vfs_ops.lock == NULL)
conn->vfs_ops.lock = default_vfs_ops.lock;
}
if (conn->vfs_ops.fget_nt_acl == NULL) {
if (conn->vfs_ops.symlink == NULL)
conn->vfs_ops.symlink = default_vfs_ops.symlink;
if (conn->vfs_ops.readlink == NULL)
conn->vfs_ops.readlink = default_vfs_ops.readlink;
if (conn->vfs_ops.fget_nt_acl == NULL)
conn->vfs_ops.fget_nt_acl = default_vfs_ops.fget_nt_acl;
}
if (conn->vfs_ops.get_nt_acl == NULL) {
if (conn->vfs_ops.get_nt_acl == NULL)
conn->vfs_ops.get_nt_acl = default_vfs_ops.get_nt_acl;
}
if (conn->vfs_ops.fset_nt_acl == NULL) {
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) {
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) {
if (conn->vfs_ops.chmod_acl == NULL)
conn->vfs_ops.chmod_acl = default_vfs_ops.chmod_acl;
}
if (conn->vfs_ops.fchmod_acl == NULL) {
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.
********************************************************************/