summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/close.c22
-rw-r--r--source3/smbd/fileio.c44
-rw-r--r--source3/smbd/filename.c6
-rw-r--r--source3/smbd/files.c118
-rw-r--r--source3/smbd/nttrans.c40
-rw-r--r--source3/smbd/open.c650
-rw-r--r--source3/smbd/oplock.c52
-rw-r--r--source3/smbd/predict.c162
-rw-r--r--source3/smbd/reply.c131
-rw-r--r--source3/smbd/trans2.c22
-rw-r--r--source3/smbd/vfs.c7
11 files changed, 231 insertions, 1023 deletions
diff --git a/source3/smbd/close.c b/source3/smbd/close.c
index 8e2ed0de0e..61e8264159 100644
--- a/source3/smbd/close.c
+++ b/source3/smbd/close.c
@@ -92,10 +92,7 @@ static void close_filestruct(files_struct *fsp)
static int close_normal_file(files_struct *fsp, BOOL normal_close)
{
- SMB_DEV_T dev = fsp->fd_ptr->dev;
- SMB_INO_T inode = fsp->fd_ptr->inode;
- BOOL last_reference = False;
- BOOL delete_on_close = fsp->fd_ptr->delete_on_close;
+ BOOL delete_on_close = fsp->delete_on_close;
connection_struct *conn = fsp->conn;
int err = 0;
@@ -103,12 +100,8 @@ static int close_normal_file(files_struct *fsp, BOOL normal_close)
close_filestruct(fsp);
-#if USE_READ_PREDICTION
- invalidate_read_prediction(fsp->fd_ptr->fd);
-#endif
-
if (lp_share_modes(SNUM(conn))) {
- lock_share_entry(conn, dev, inode);
+ lock_share_entry_fsp(fsp);
del_share_mode(fsp);
}
@@ -117,13 +110,10 @@ static int close_normal_file(files_struct *fsp, BOOL normal_close)
locking_close_file(fsp);
- if(fd_attempt_close(fsp, &err) == 0)
- last_reference = True;
-
- fsp->fd_ptr = NULL;
-
if (lp_share_modes(SNUM(conn)))
- unlock_share_entry(conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
+
+ fd_close(fsp, &err);
/* NT uses smbclose to start a print - weird */
if (normal_close && fsp->print_file)
@@ -139,7 +129,7 @@ static int close_normal_file(files_struct *fsp, BOOL normal_close)
* reference to a file.
*/
- if (normal_close && last_reference && delete_on_close) {
+ if (normal_close && delete_on_close) {
DEBUG(5,("close_file: file %s. Delete on close was set - deleting file.\n",
fsp->fsp_name));
if(fsp->conn->vfs_ops.unlink(dos_to_unix(fsp->fsp_name, False)) != 0) {
diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c
index 00a515d16d..43fd091b49 100644
--- a/source3/smbd/fileio.c
+++ b/source3/smbd/fileio.c
@@ -37,7 +37,7 @@ SMB_OFF_T seek_file(files_struct *fsp,SMB_OFF_T pos)
if (fsp->print_file && lp_postscript(fsp->conn->service))
offset = 3;
- seek_ret = fsp->conn->vfs_ops.lseek(fsp->fd_ptr->fd,pos+offset,SEEK_SET);
+ seek_ret = fsp->conn->vfs_ops.lseek(fsp->fd,pos+offset,SEEK_SET);
/*
* We want to maintain the fiction that we can seek
@@ -96,16 +96,6 @@ ssize_t read_file(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n)
{
ssize_t ret=0,readret;
-#if USE_READ_PREDICTION
- if (!fsp->can_write) {
- ret = read_predict(fsp->fd_ptr->fd,pos,data,NULL,n);
-
- data += ret;
- n -= ret;
- pos += ret;
- }
-#endif
-
/*
* Serve from write cache if we can.
*/
@@ -120,7 +110,7 @@ ssize_t read_file(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n)
}
if (n > 0) {
- readret = fsp->conn->vfs_ops.read(fsp->fd_ptr->fd,data,n);
+ readret = fsp->conn->vfs_ops.read(fsp->fd,data,n);
if (readret > 0) ret += readret;
}
@@ -151,7 +141,7 @@ static ssize_t real_write_file(files_struct *fsp,char *data,SMB_OFF_T pos, size_
if ((pos != -1) && (seek_file(fsp,pos) == -1))
return -1;
- return write_data(fsp->fd_ptr->fd,data,n);
+ return write_data(fsp->fd,data,n);
}
/****************************************************************************
@@ -173,7 +163,7 @@ ssize_t write_file(files_struct *fsp, char *data, SMB_OFF_T pos, size_t n)
SMB_STRUCT_STAT st;
fsp->modified = True;
- if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd,&st) == 0) {
+ if (fsp->conn->vfs_ops.fstat(fsp->fd,&st) == 0) {
int dosmode = dos_mode(fsp->conn,fsp->fsp_name,&st);
if (MAP_ARCHIVE(fsp->conn) && !IS_DOS_ARCHIVE(dosmode)) {
file_chmod(fsp->conn,fsp->fsp_name,dosmode | aARCH,&st);
@@ -205,19 +195,17 @@ ssize_t write_file(files_struct *fsp, char *data, SMB_OFF_T pos, size_t n)
*/
if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type)) {
- SMB_DEV_T dev = fsp->fd_ptr->dev;
- SMB_INO_T inode = fsp->fd_ptr->inode;
share_mode_entry *share_list = NULL;
pid_t pid = getpid();
int token = -1;
int num_share_modes = 0;
int i;
- if (lock_share_entry(fsp->conn, dev, inode) == False) {
+ if (lock_share_entry_fsp(fsp) == False) {
DEBUG(0,("write_file: failed to lock share mode entry for file %s.\n", fsp->fsp_name ));
}
- num_share_modes = get_share_modes(fsp->conn, dev, inode, &share_list);
+ num_share_modes = get_share_modes(fsp->conn, fsp->dev, fsp->inode, &share_list);
for(i = 0; i < num_share_modes; i++) {
share_mode_entry *share_entry = &share_list[i];
@@ -247,7 +235,7 @@ ssize_t write_file(files_struct *fsp, char *data, SMB_OFF_T pos, size_t n)
*/
if (pid == share_entry->pid) {
- files_struct *new_fsp = file_find_dit(dev, inode, &share_entry->time);
+ files_struct *new_fsp = file_find_dit(fsp->dev, fsp->inode, &share_entry->time);
/* Paranoia check... */
if(new_fsp == NULL) {
@@ -263,12 +251,12 @@ ssize_t write_file(files_struct *fsp, char *data, SMB_OFF_T pos, size_t n)
* message.
*/
- request_oplock_break(share_entry, dev, inode);
+ request_oplock_break(share_entry, fsp->dev, fsp->inode);
}
}
free((char *)share_list);
- unlock_share_entry(fsp->conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
}
/* Paranoia check... */
@@ -300,7 +288,7 @@ nonop=%u allocated=%u active=%u direct=%u perfect=%u readhits=%u\n",
}
DEBUG(9,("write_file(fd=%d pos=%d size=%d) wofs=%d wsize=%d\n",
- fsp->fd_ptr->fd, (int)pos, (int)n, (int)wcp->offset, (int)wcp->data_size));
+ fsp->fd, (int)pos, (int)n, (int)wcp->offset, (int)wcp->data_size));
/*
* If we have active cache and it isn't contiguous then we flush.
@@ -427,7 +415,7 @@ nonop=%u allocated=%u active=%u direct=%u perfect=%u readhits=%u\n",
wcp->file_size = wcp->offset + wcp->data_size;
#if 0
- if (set_filelen(fsp->fd_ptr->fd, wcp->file_size) == -1) {
+ if (set_filelen(fsp->fd, wcp->file_size) == -1) {
DEBUG(0,("write_file: error %s in setting file to length %.0f\n",
strerror(errno), (double)wcp->file_size ));
return -1;
@@ -466,7 +454,7 @@ nonop=%u allocated=%u active=%u direct=%u perfect=%u readhits=%u\n",
*/
DEBUG(9,("write_file: non cacheable write : fd = %d, pos = %.0f, len = %u, current cache pos = %.0f \
-len = %u\n",fsp->fd_ptr->fd, (double)pos, (unsigned int)n, (double)wcp->offset, (unsigned int)wcp->data_size ));
+len = %u\n",fsp->fd, (double)pos, (unsigned int)n, (double)wcp->offset, (unsigned int)wcp->data_size ));
/*
* Update the file size if needed.
@@ -501,7 +489,7 @@ len = %u\n",fsp->fd_ptr->fd, (double)pos, (unsigned int)n, (double)wcp->offset,
DEBUG(3,("WRITE_FLUSH:%d: due to noncontinuous write: fd = %d, size = %.0f, pos = %.0f, \
n = %u, wcp->offset=%.0f, wcp->data_size=%u\n",
- write_path, fsp->fd_ptr->fd, (double)wcp->file_size, (double)pos, (unsigned int)n,
+ write_path, fsp->fd, (double)wcp->file_size, (double)pos, (unsigned int)n,
(double)wcp->offset, (unsigned int)wcp->data_size ));
flush_write_cache(fsp, WRITE_FLUSH);
@@ -637,7 +625,7 @@ ssize_t flush_write_cache(files_struct *fsp, enum flush_reason_enum reason)
flush_reasons[(int)reason]++;
DEBUG(9,("flushing write cache: fd = %d, off=%.0f, size=%u\n",
- fsp->fd_ptr->fd, (double)wcp->offset, (unsigned int)data_size));
+ fsp->fd, (double)wcp->offset, (unsigned int)data_size));
if(data_size == wcp->alloc_size)
num_perfect_writes++;
@@ -651,8 +639,8 @@ sync a file
void sys_fsync_file(connection_struct *conn, files_struct *fsp)
{
- if(lp_strict_sync(SNUM(conn)) && fsp->fd_ptr != NULL) {
+ if(lp_strict_sync(SNUM(conn)) && fsp->fd != -1) {
flush_write_cache(fsp, SYNC_FLUSH);
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
}
}
diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c
index 729ef8c809..7afa9e9986 100644
--- a/source3/smbd/filename.c
+++ b/source3/smbd/filename.c
@@ -347,6 +347,12 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
extern char magic_char;
#endif
+ if (conn->printer) {
+ /* we don't ever use the filenames on a printer share as a
+ filename - so don't convert them */
+ return True;
+ }
+
DEBUG(5, ("unix_convert called on file \"%s\"\n", name));
*dirpath = 0;
diff --git a/source3/smbd/files.c b/source3/smbd/files.c
index d62950c568..127d2fcac9 100644
--- a/source3/smbd/files.c
+++ b/source3/smbd/files.c
@@ -38,13 +38,7 @@ static files_struct *chain_fsp = NULL;
/* a fsp to use to save when breaking an oplock. */
static files_struct *oplock_save_chain_fsp = NULL;
-/*
- * Indirection for file fd's. Needed as POSIX locking
- * is based on file/process, not fd/process.
- */
-static file_fd_struct *FileFd;
-
-static int files_used, fd_ptr_used;
+static int files_used;
/****************************************************************************
find first available file slot
@@ -110,72 +104,6 @@ files_struct *file_new(void )
}
-
-/****************************************************************************
-fd support routines - attempt to find an already open file by dev
-and inode - increments the ref_count of the returned file_fd_struct *.
-****************************************************************************/
-file_fd_struct *fd_get_already_open(SMB_STRUCT_STAT *sbuf)
-{
- file_fd_struct *fd_ptr;
-
- if(!sbuf) return NULL;
-
- for (fd_ptr=FileFd;fd_ptr;fd_ptr=fd_ptr->next) {
- if ((fd_ptr->ref_count > 0) &&
- (sbuf->st_dev == fd_ptr->dev) &&
- (sbuf->st_ino == fd_ptr->inode)) {
- fd_ptr->ref_count++;
-
- DEBUG(3,("Re-used file_fd_struct dev = %x, inode = %.0f, ref_count = %d\n",
- (unsigned int)fd_ptr->dev, (double)fd_ptr->inode,
- fd_ptr->ref_count));
-
- return fd_ptr;
- }
- }
-
- return NULL;
-}
-
-
-
-/****************************************************************************
-fd support routines - attempt to find a empty slot in the FileFd array.
-Increments the ref_count of the returned entry.
-****************************************************************************/
-file_fd_struct *fd_get_new(void)
-{
- extern struct current_user current_user;
- file_fd_struct *fd_ptr;
-
- fd_ptr = (file_fd_struct *)malloc(sizeof(*fd_ptr));
- if (!fd_ptr) {
- DEBUG(0,("ERROR! malloc fail for file_fd struct.\n"));
- return NULL;
- }
-
- ZERO_STRUCTP(fd_ptr);
-
- fd_ptr->dev = (SMB_DEV_T)-1;
- fd_ptr->inode = (SMB_INO_T)-1;
- fd_ptr->fd = -1;
- fd_ptr->fd_readonly = -1;
- fd_ptr->fd_writeonly = -1;
- fd_ptr->real_open_flags = -1;
- fd_add_to_uid_cache(fd_ptr, (uid_t)current_user.uid);
- fd_ptr->ref_count++;
-
- fd_ptr_used++;
-
- DLIST_ADD(FileFd, fd_ptr);
-
- DEBUG(5,("allocated fd_ptr structure (%d used)\n", fd_ptr_used));
-
- return fd_ptr;
-}
-
-
/****************************************************************************
close all open files for a connection
****************************************************************************/
@@ -257,9 +185,9 @@ files_struct *file_find_dit(SMB_DEV_T dev, SMB_INO_T inode, struct timeval *tval
for (fsp=Files;fsp;fsp=fsp->next,count++) {
if (fsp->open &&
- fsp->fd_ptr != NULL &&
- fsp->fd_ptr->dev == dev &&
- fsp->fd_ptr->inode == inode &&
+ fsp->fd != -1 &&
+ fsp->dev == dev &&
+ fsp->inode == inode &&
(tval ? (fsp->open_time.tv_sec == tval->tv_sec) : True ) &&
(tval ? (fsp->open_time.tv_usec == tval->tv_usec) : True )) {
if (count > 10) {
@@ -282,9 +210,9 @@ files_struct *file_find_di_first(SMB_DEV_T dev, SMB_INO_T inode)
for (fsp=Files;fsp;fsp=fsp->next) {
if (fsp->open &&
- fsp->fd_ptr != NULL &&
- fsp->fd_ptr->dev == dev &&
- fsp->fd_ptr->inode == inode )
+ fsp->fd != -1 &&
+ fsp->dev == dev &&
+ fsp->inode == inode )
return fsp;
}
@@ -301,9 +229,9 @@ files_struct *file_find_di_next(files_struct *start_fsp)
for (fsp = start_fsp->next;fsp;fsp=fsp->next) {
if (fsp->open &&
- fsp->fd_ptr != NULL &&
- fsp->fd_ptr->dev == start_fsp->fd_ptr->dev &&
- fsp->fd_ptr->inode == start_fsp->fd_ptr->inode )
+ fsp->fd != -1 &&
+ fsp->dev == start_fsp->dev &&
+ fsp->inode == start_fsp->inode )
return fsp;
}
@@ -334,32 +262,14 @@ void file_sync_all(connection_struct *conn)
for (fsp=Files;fsp;fsp=next) {
next=fsp->next;
- if (fsp->open && (conn == fsp->conn) && (fsp->fd_ptr != NULL)) {
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ if (fsp->open && (conn == fsp->conn) && (fsp->fd != -1)) {
+ conn->vfs_ops.fsync(fsp->fd);
}
}
}
/****************************************************************************
-free up a fd_ptr
-****************************************************************************/
-void fd_ptr_free(file_fd_struct *fd_ptr)
-{
- DLIST_REMOVE(FileFd, fd_ptr);
-
- fd_ptr_used--;
-
- DEBUG(5,("freed fd_ptr structure (%d used)\n", fd_ptr_used));
-
- /* paranoia */
- ZERO_STRUCTP(fd_ptr);
-
- free(fd_ptr);
-}
-
-
-/****************************************************************************
free up a fsp
****************************************************************************/
void file_free(files_struct *fsp)
@@ -368,10 +278,6 @@ void file_free(files_struct *fsp)
string_free(&fsp->fsp_name);
- if ((fsp->fd_ptr != NULL) && fsp->fd_ptr->ref_count == 0) {
- fd_ptr_free(fsp->fd_ptr);
- }
-
bitmap_clear(file_bmap, fsp->fnum - FILE_HANDLE_OFFSET);
files_used--;
diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c
index 1a43350e90..54e67f5593 100644
--- a/source3/smbd/nttrans.c
+++ b/source3/smbd/nttrans.c
@@ -754,18 +754,6 @@ int reply_ntcreate_and_X(connection_struct *conn,
return(ERROR(ERRSRV,ERRnofids));
}
- if (!check_name(fname,conn)) {
- if((errno == ENOENT) && bad_path) {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadpath;
- }
- file_free(fsp);
-
- restore_case_semantics(file_attributes);
-
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
-
unixmode = unix_mode(conn,smb_attr | aARCH, fname);
/*
@@ -889,7 +877,7 @@ int reply_ntcreate_and_X(connection_struct *conn,
return(ERROR(ERRDOS,ERRnoaccess));
}
} else {
- if (conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf) != 0) {
+ if (conn->vfs_ops.fstat(fsp->fd,&sbuf) != 0) {
close_file(fsp,False);
restore_case_semantics(file_attributes);
return(ERROR(ERRDOS,ERRnoaccess));
@@ -1128,18 +1116,6 @@ static int call_nt_transact_create(connection_struct *conn,
return(ERROR(ERRSRV,ERRnofids));
}
- if (!check_name(fname,conn)) {
- if((errno == ENOENT) && bad_path) {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadpath;
- }
- file_free(fsp);
-
- restore_case_semantics(file_attributes);
-
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
-
unixmode = unix_mode(conn,smb_attr | aARCH, fname);
/*
@@ -1244,7 +1220,7 @@ static int call_nt_transact_create(connection_struct *conn,
return(ERROR(ERRDOS,ERRnoaccess));
}
} else {
- if (!fsp->stat_open && conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf) != 0) {
+ if (!fsp->stat_open && conn->vfs_ops.fstat(fsp->fd,&sbuf) != 0) {
close_file(fsp,False);
restore_case_semantics(file_attributes);
return(ERROR(ERRDOS,ERRnoaccess));
@@ -1869,12 +1845,12 @@ static size_t get_nt_acl(files_struct *fsp, SEC_DESC **ppdesc)
sid_copy( &group_sid, &global_sid_World);
} else {
- if(fsp->is_directory || fsp->fd_ptr == NULL) {
+ if(fsp->is_directory || fsp->fd == -1) {
if(dos_stat(fsp->fsp_name, &sbuf) != 0) {
return 0;
}
} else {
- if(fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf) != 0) {
+ if(fsp->conn->vfs_ops.fstat(fsp->fd,&sbuf) != 0) {
return 0;
}
}
@@ -2391,10 +2367,10 @@ security descriptor.\n"));
int ret;
- if(fsp->fd_ptr == NULL)
+ if(fsp->fd == -1)
ret = conn->vfs_ops.stat(dos_to_unix(fsp->fsp_name,False), &sbuf);
else
- ret = conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf);
+ ret = conn->vfs_ops.fstat(fsp->fd,&sbuf);
if(ret != 0) {
free_sec_desc(&psd);
@@ -2444,10 +2420,10 @@ security descriptor.\n"));
int ret;
- if(fsp->fd_ptr == NULL)
+ if(fsp->fd == -1)
ret = conn->vfs_ops.stat(dos_to_unix(fsp->fsp_name,False), &sbuf);
else
- ret = conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf);
+ ret = conn->vfs_ops.fstat(fsp->fd,&sbuf);
if(ret != 0)
return(UNIXERROR(ERRDOS,ERRnoaccess));
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 6352233dbc..4c5605fb3b 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -30,274 +30,31 @@ extern BOOL global_client_failed_oplock_break;
/****************************************************************************
fd support routines - attempt to do a dos_open
****************************************************************************/
-static int fd_attempt_open(struct connection_struct *conn, char *fname,
- int flags, mode_t mode)
+static int fd_open(struct connection_struct *conn, char *fname,
+ int flags, mode_t mode)
{
- int fd = conn->vfs_ops.open(dos_to_unix(fname,False),flags,mode);
+ int fd = conn->vfs_ops.open(dos_to_unix(fname,False),flags,mode);
- /* Fix for files ending in '.' */
- if((fd == -1) && (errno == ENOENT) &&
- (strchr(fname,'.')==NULL))
- {
- pstrcat(fname,".");
- fd = conn->vfs_ops.open(dos_to_unix(fname,False),flags,mode);
- }
-
-#if (defined(ENAMETOOLONG) && defined(HAVE_PATHCONF))
- if ((fd == -1) && (errno == ENAMETOOLONG))
- {
- int max_len;
- char *p = strrchr(fname, '/');
-
- if (p == fname) /* name is "/xxx" */
- {
- max_len = pathconf("/", _PC_NAME_MAX);
- p++;
- }
- else if ((p == NULL) || (p == fname))
- {
- p = fname;
- max_len = pathconf(".", _PC_NAME_MAX);
- }
- else
- {
- *p = '\0';
- max_len = pathconf(fname, _PC_NAME_MAX);
- *p = '/';
- p++;
- }
- if (strlen(p) > max_len)
- {
- char tmp = p[max_len];
-
- p[max_len] = '\0';
- if ((fd = conn->vfs_ops.open(dos_to_unix(fname,False),flags,mode)) == -1)
- p[max_len] = tmp;
- }
- }
-#endif
- return fd;
-}
-
-/****************************************************************************
-Cache a uid_t currently with this file open. This is an optimization only
-used when multiple sessionsetup's have been done to one smbd.
-****************************************************************************/
-
-void fd_add_to_uid_cache(file_fd_struct *fd_ptr, uid_t u)
-{
- if(fd_ptr->uid_cache_count >= sizeof(fd_ptr->uid_users_cache)/sizeof(uid_t))
- return;
- fd_ptr->uid_users_cache[fd_ptr->uid_cache_count++] = u;
-}
-
-/****************************************************************************
-Remove a uid_t that currently has this file open. This is an optimization only
-used when multiple sessionsetup's have been done to one smbd.
-****************************************************************************/
-
-static void fd_remove_from_uid_cache(file_fd_struct *fd_ptr, uid_t u)
-{
- int i;
- for(i = 0; i < fd_ptr->uid_cache_count; i++)
- if(fd_ptr->uid_users_cache[i] == u) {
- if(i < (fd_ptr->uid_cache_count-1))
- memmove((char *)&fd_ptr->uid_users_cache[i], (char *)&fd_ptr->uid_users_cache[i+1],
- sizeof(uid_t)*(fd_ptr->uid_cache_count-1-i) );
- fd_ptr->uid_cache_count--;
- }
- return;
-}
-
-/****************************************************************************
-Check if a uid_t that currently has this file open is present. This is an
-optimization only used when multiple sessionsetup's have been done to one smbd.
-****************************************************************************/
-
-static BOOL fd_is_in_uid_cache(file_fd_struct *fd_ptr, uid_t u)
-{
- int i;
- for(i = 0; i < fd_ptr->uid_cache_count; i++)
- if(fd_ptr->uid_users_cache[i] == u)
- return True;
- return False;
-}
-
-/****************************************************************************
-fd support routines - attempt to re-open an already open fd as O_RDWR.
-Save the already open fd (we cannot close due to POSIX file locking braindamage.
-****************************************************************************/
-
-static void fd_attempt_reopen(char *fname, mode_t mode, files_struct *fsp)
-{
- int fd = fsp->conn->vfs_ops.open(dos_to_unix(fname, False), O_RDWR, mode);
- file_fd_struct *fd_ptr = fsp->fd_ptr;
-
- if(fd == -1)
- return;
-
- if(fd_ptr->real_open_flags == O_RDONLY)
- fd_ptr->fd_readonly = fd_ptr->fd;
- if(fd_ptr->real_open_flags == O_WRONLY)
- fd_ptr->fd_writeonly = fd_ptr->fd;
-
- fd_ptr->fd = fd;
- fd_ptr->real_open_flags = O_RDWR;
-}
-
-/****************************************************************************
-fd support routines - attempt to close the file referenced by this fd.
-Decrements the ref_count and returns it.
-****************************************************************************/
-uint16 fd_attempt_close(files_struct *fsp, int *err_ret)
-{
- extern struct current_user current_user;
- file_fd_struct *fd_ptr;
- uint16 ret_ref;
-
- *err_ret = 0;
-
- if ((fsp == NULL) || (fsp->fd_ptr == NULL)) {
- return 0;
- }
-
- fd_ptr = fsp->fd_ptr;
- ret_ref = fd_ptr->ref_count;
-
- DEBUG(3,("fd_attempt_close fd = %d, dev = %x, inode = %.0f, open_flags = %d, ref_count = %d.\n",
- fd_ptr->fd, (unsigned int)fd_ptr->dev, (double)fd_ptr->inode,
- fd_ptr->real_open_flags,
- fd_ptr->ref_count));
-
- SMB_ASSERT(fd_ptr->ref_count != 0);
-
- fd_ptr->ref_count--;
- ret_ref = fd_ptr->ref_count;
-
- if(fd_ptr->ref_count == 0) {
-
- if(fd_ptr->fd != -1) {
- if(fsp->conn->vfs_ops.close(fd_ptr->fd) < 0)
- *err_ret = errno;
- }
-
- if(fd_ptr->fd_readonly != -1) {
- if(fsp->conn->vfs_ops.close(fd_ptr->fd_readonly) < 0) {
- if(*err_ret == 0)
- *err_ret = errno;
- }
- }
-
- if(fd_ptr->fd_writeonly != -1) {
- if(fsp->conn->vfs_ops.close(fd_ptr->fd_writeonly) < 0) {
- if(*err_ret == 0)
- *err_ret = errno;
- }
+ /* Fix for files ending in '.' */
+ if((fd == -1) && (errno == ENOENT) &&
+ (strchr(fname,'.')==NULL)) {
+ pstrcat(fname,".");
+ fd = conn->vfs_ops.open(dos_to_unix(fname,False),flags,mode);
}
- /*
- * Delete this fd_ptr.
- */
- fd_ptr_free(fd_ptr);
- } else {
- fd_remove_from_uid_cache(fd_ptr, (uid_t)current_user.uid);
- }
-
- return ret_ref;
+ return fd;
}
/****************************************************************************
-fd support routines - check that current user has permissions
-to open this file. Used when uid not found in optimization cache.
-This is really ugly code, as due to POSIX locking braindamage we must
-fork and then attempt to open the file, and return success or failure
-via an exit code.
+close the file associated with a fsp
****************************************************************************/
-static BOOL check_access_allowed_for_current_user(struct connection_struct
- *conn, char *fname,
- int accmode )
+void fd_close(files_struct *fsp, int *err_ret)
{
- pid_t child_pid;
-
- /*
- * We need to temporarily stop CatchChild from eating
- * SIGCLD signals as it also eats the exit status code. JRA.
- */
-
- CatchChildLeaveStatus();
-
- if((child_pid = fork()) < 0) {
- DEBUG(0,("check_access_allowed_for_current_user: fork failed.\n"));
- CatchChild();
- return False;
- }
-
- if(child_pid) {
- /*
- * Parent.
- */
- pid_t wpid;
- int status_code;
-
- while ((wpid = sys_waitpid(child_pid, &status_code, 0)) < 0) {
- if(errno == EINTR) {
- errno = 0;
- continue;
- }
- DEBUG(0,("check_access_allowed_for_current_user: The process \
-is no longer waiting ! Error = %s\n", strerror(errno) ));
- CatchChild();
- return(False);
- }
-
- /*
- * Go back to ignoring children.
- */
- CatchChild();
-
- if (child_pid != wpid) {
- DEBUG(0,("check_access_allowed_for_current_user: We were waiting for the wrong process ID\n"));
- return(False);
- }
-#if defined(WIFEXITED) && defined(WEXITSTATUS)
- if (WIFEXITED(status_code) == 0) {
- DEBUG(0,("check_access_allowed_for_current_user: The process exited while we were waiting\n"));
- return(False);
- }
- if (WEXITSTATUS(status_code) != 0) {
- DEBUG(9,("check_access_allowed_for_current_user: The status of the process exiting was %d. Returning access denied.\n", status_code));
- return(False);
- }
-#else /* defined(WIFEXITED) && defined(WEXITSTATUS) */
- if(status_code != 0) {
- DEBUG(9,("check_access_allowed_for_current_user: The status of the process exiting was %d. Returning access denied.\n", status_code));
- return(False);
- }
-#endif /* defined(WIFEXITED) && defined(WEXITSTATUS) */
-
- /*
- * Success - the child could open the file.
- */
- DEBUG(9,("check_access_allowed_for_current_user: The status of the process exiting was %d. Returning access allowed.\n", status_code));
- return True;
- } else {
- /*
- * Child.
- */
- int fd;
- DEBUG(9,("check_access_allowed_for_current_user: Child - attempting to open %s with mode %d.\n", fname, accmode ));
- if((fd = fd_attempt_open(conn, fname, accmode, 0)) < 0) {
- /* Access denied. */
- _exit(EACCES);
- }
- conn->vfs_ops.close(fd);
- DEBUG(9,("check_access_allowed_for_current_user: Child - returning ok.\n"));
- _exit(0);
- }
-
- return False;
+ fsp->conn->vfs_ops.close(fsp->fd);
+ fsp->fd = -1;
}
+
/****************************************************************************
check a filename for the pipe string
****************************************************************************/
@@ -320,278 +77,95 @@ open a file
****************************************************************************/
static void open_file(files_struct *fsp,connection_struct *conn,
- char *fname1,int flags,mode_t mode, SMB_STRUCT_STAT *sbuf)
+ char *fname1,int flags,mode_t mode)
{
- extern struct current_user current_user;
- pstring fname;
- SMB_STRUCT_STAT statbuf;
- file_fd_struct *fd_ptr;
- int accmode = (flags & O_ACCMODE);
-
- fsp->open = False;
- fsp->fd_ptr = 0;
- fsp->oplock_type = NO_OPLOCK;
- errno = EPERM;
-
- pstrcpy(fname,fname1);
-
- /* check permissions */
-
- /*
- * This code was changed after seeing a client open request
- * containing the open mode of (DENY_WRITE/read-only) with
- * the 'create if not exist' bit set. The previous code
- * would fail to open the file read only on a read-only share
- * as it was checking the flags parameter directly against O_RDONLY,
- * this was failing as the flags parameter was set to O_RDONLY|O_CREAT.
- * JRA.
- */
-
- if (!CAN_WRITE(conn) && !conn->printer) {
- /* It's a read-only share - fail if we wanted to write. */
- if(accmode != O_RDONLY) {
- DEBUG(3,("Permission denied opening %s\n",fname));
- check_for_pipe(fname);
- return;
- } else if(flags & O_CREAT) {
- /* We don't want to write - but we must make sure that O_CREAT
- doesn't create the file if we have write access into the
- directory.
- */
- flags &= ~O_CREAT;
- }
- }
-
- /* this handles a bug in Win95 - it doesn't say to create the file when it
- should */
- if (conn->printer) {
- flags |= (O_CREAT|O_EXCL);
- }
-
-/*
- if (flags == O_WRONLY)
- DEBUG(3,("Bug in client? Set O_WRONLY without O_CREAT\n"));
-*/
-
- /*
- * Ensure we have a valid struct stat so we can search the
- * open fd table.
- */
- if(sbuf == 0) {
- if(conn->vfs_ops.stat(dos_to_unix(fname,False), &statbuf) < 0) {
- if(errno != ENOENT) {
- DEBUG(3,("Error doing stat on file %s (%s)\n",
- fname,strerror(errno)));
-
- check_for_pipe(fname);
- return;
- }
- sbuf = 0;
- } else {
- sbuf = &statbuf;
- }
- }
-
- /*
- * Check to see if we have this file already
- * open. If we do, just use the already open fd and increment the
- * reference count (fd_get_already_open increments the ref_count).
- */
- if((fd_ptr = fd_get_already_open(sbuf))!= 0) {
- /*
- * File was already open.
- */
-
- /*
- * Check it wasn't open for exclusive use.
- */
- if((flags & O_CREAT) && (flags & O_EXCL)) {
- fd_ptr->ref_count--;
- errno = EEXIST;
- return;
- }
-
- /*
- * Ensure that the user attempting to open
- * this file has permissions to do so, if
- * the user who originally opened the file wasn't
- * the same as the current user.
- */
+ extern struct current_user current_user;
+ pstring fname;
+ int accmode = (flags & O_ACCMODE);
+ SMB_STRUCT_STAT sbuf;
- if(!fd_is_in_uid_cache(fd_ptr, (uid_t)current_user.uid)) {
- if(!check_access_allowed_for_current_user(conn, fname, accmode )) {
- /* Error - permission denied. */
- DEBUG(3,("Permission denied opening file %s (flags=%d, accmode = %d)\n",
- fname, flags, accmode));
- /* Ensure the ref_count is decremented. */
- fd_ptr->ref_count--;
- fd_remove_from_uid_cache(fd_ptr, (uid_t)current_user.uid);
- errno = EACCES;
- return;
- }
- }
+ fsp->open = False;
+ fsp->fd = 0;
+ fsp->oplock_type = NO_OPLOCK;
+ errno = EPERM;
- fd_add_to_uid_cache(fd_ptr, (uid_t)current_user.uid);
+ pstrcpy(fname,fname1);
- /*
- * If not opened O_RDWR try
- * and do that here - a chmod may have been done
- * between the last open and now.
- */
- if(fd_ptr->real_open_flags != O_RDWR)
- fd_attempt_reopen(fname, mode, fsp);
+ /* check permissions */
- /*
- * Ensure that if we wanted write access
- * it has been opened for write, and if we wanted read it
- * was open for read.
- */
- if(((accmode == O_WRONLY) && (fd_ptr->real_open_flags == O_RDONLY)) ||
- ((accmode == O_RDONLY) && (fd_ptr->real_open_flags == O_WRONLY)) ||
- ((accmode == O_RDWR) && (fd_ptr->real_open_flags != O_RDWR))) {
- DEBUG(3,("Error opening (already open for flags=%d) file %s (%s) (flags=%d)\n",
- fd_ptr->real_open_flags, fname,strerror(EACCES),flags));
- check_for_pipe(fname);
- fd_remove_from_uid_cache(fd_ptr, (uid_t)current_user.uid);
- fd_ptr->ref_count--;
- return;
- }
+ /*
+ * This code was changed after seeing a client open request
+ * containing the open mode of (DENY_WRITE/read-only) with
+ * the 'create if not exist' bit set. The previous code
+ * would fail to open the file read only on a read-only share
+ * as it was checking the flags parameter directly against O_RDONLY,
+ * this was failing as the flags parameter was set to O_RDONLY|O_CREAT.
+ * JRA.
+ */
- } else {
- int open_flags;
- /* We need to allocate a new file_fd_struct (this increments the
- ref_count). */
- if((fd_ptr = fd_get_new()) == 0)
- return;
- /*
- * Whatever the requested flags, attempt read/write access,
- * as we don't know what flags future file opens may require.
- * If this fails, try again with the required flags.
- * Even if we open read/write when only read access was
- * requested the setting of the can_write flag in
- * the file_struct will protect us from errant
- * write requests. We never need to worry about O_APPEND
- * as this is not set anywhere in Samba.
- */
- fd_ptr->real_open_flags = O_RDWR;
- /* Set the flags as needed without the read/write modes. */
- open_flags = flags & ~(O_RDWR|O_WRONLY|O_RDONLY);
- fd_ptr->fd = fd_attempt_open(conn, fname, open_flags|O_RDWR, mode);
- /*
- * On some systems opening a file for R/W access on a read only
- * filesystems sets errno to EROFS.
- */
-#ifdef EROFS
- if((fd_ptr->fd == -1) && ((errno == EACCES) || (errno == EROFS))) {
-#else /* No EROFS */
- if((fd_ptr->fd == -1) && (errno == EACCES)) {
-#endif /* EROFS */
- if(accmode != O_RDWR) {
- fd_ptr->fd = fd_attempt_open(conn, fname, open_flags|accmode, mode);
- fd_ptr->real_open_flags = accmode;
- }
- }
- }
+ if (!CAN_WRITE(conn)) {
+ /* It's a read-only share - fail if we wanted to write. */
+ if(accmode != O_RDONLY) {
+ DEBUG(3,("Permission denied opening %s\n",fname));
+ check_for_pipe(fname);
+ return;
+ } else if(flags & O_CREAT) {
+ /* We don't want to write - but we must make sure that O_CREAT
+ doesn't create the file if we have write access into the
+ directory.
+ */
+ flags &= ~O_CREAT;
+ }
+ }
- if ((fd_ptr->fd >=0) &&
- conn->printer && lp_minprintspace(SNUM(conn))) {
- pstring dname;
- SMB_BIG_UINT dum1,dum2,dum3;
- char *p;
- pstrcpy(dname,fname);
- p = strrchr(dname,'/');
- if (p) *p = 0;
- if (conn->vfs_ops.disk_free(dos_to_unix(dname,False),False,&dum1,&dum2,&dum3) <
- (SMB_BIG_UINT)lp_minprintspace(SNUM(conn))) {
- int err;
- if(fd_attempt_close(fsp, &err) == 0)
- conn->vfs_ops.unlink(dos_to_unix(fname, False));
- fsp->fd_ptr = 0;
- errno = ENOSPC;
- return;
- }
- }
-
- if (fd_ptr->fd < 0)
- {
- int err;
- DEBUG(3,("Error opening file %s (%s) (flags=%d)\n",
- fname,strerror(errno),flags));
- /* Ensure the ref_count is decremented. */
- fd_attempt_close(fsp,&err);
- check_for_pipe(fname);
- return;
- }
+ /* actually do the open */
+ fsp->fd = fd_open(conn, fname, flags, mode);
- if (fd_ptr->fd >= 0)
- {
- if(sbuf == 0) {
- /* Do the fstat */
- if(conn->vfs_ops.fstat(fd_ptr->fd, &statbuf) == -1) {
- int err;
- /* Error - backout !! */
- DEBUG(3,("Error doing fstat on fd %d, file %s (%s)\n",
- fd_ptr->fd, fname,strerror(errno)));
- /* Ensure the ref_count is decremented. */
- fd_attempt_close(fsp,&err);
- return;
- }
- sbuf = &statbuf;
- }
+ if (fsp->fd == -1) {
+ DEBUG(3,("Error opening file %s (%s) (flags=%d)\n",
+ fname,strerror(errno),flags));
+ check_for_pipe(fname);
+ return;
+ }
- /* Set the correct entries in fd_ptr. */
- fd_ptr->dev = sbuf->st_dev;
- fd_ptr->inode = sbuf->st_ino;
-
- fsp->fd_ptr = fd_ptr;
- conn->num_files_open++;
- fsp->mode = sbuf->st_mode;
- GetTimeOfDay(&fsp->open_time);
- fsp->vuid = current_user.vuid;
- fsp->size = 0;
- fsp->pos = -1;
- fsp->open = True;
- fsp->can_lock = True;
- fsp->can_read = ((flags & O_WRONLY)==0);
- fsp->can_write = ((flags & (O_WRONLY|O_RDWR))!=0);
- fsp->share_mode = 0;
- fsp->print_file = conn->printer;
- fsp->modified = False;
- fsp->oplock_type = NO_OPLOCK;
- fsp->sent_oplock_break = NO_BREAK_SENT;
- fsp->is_directory = False;
- fsp->stat_open = False;
- fsp->directory_delete_on_close = False;
- fsp->conn = conn;
- /*
- * Note that the file name here is the *untranslated* name
- * ie. it is still in the DOS codepage sent from the client.
- * All use of this filename will pass though the sys_xxxx
- * functions which will do the dos_to_unix translation before
- * mapping into a UNIX filename. JRA.
- */
- string_set(&fsp->fsp_name,fname);
- fsp->wbmpx_ptr = NULL;
- fsp->wcp = NULL; /* Write cache pointer. */
+ conn->vfs_ops.fstat(fsp->fd, &sbuf);
- /*
- * If the printer is marked as postscript output a leading
- * file identifier to ensure the file is treated as a raw
- * postscript file.
- * This has a similar effect as CtrlD=0 in WIN.INI file.
- * tim@fsg.com 09/06/94
- */
- if (fsp->print_file && lp_postscript(SNUM(conn)) && fsp->can_write) {
- DEBUG(3,("Writing postscript line\n"));
- conn->vfs_ops.write(fsp->fd_ptr->fd,"%!\n",3);
- }
-
- DEBUG(2,("%s opened file %s read=%s write=%s (numopen=%d)\n",
- *sesssetup_user ? sesssetup_user : conn->user,fsp->fsp_name,
- BOOLSTR(fsp->can_read), BOOLSTR(fsp->can_write),
- conn->num_files_open));
+ conn->num_files_open++;
+ fsp->mode = sbuf.st_mode;
+ fsp->inode = sbuf.st_ino;
+ fsp->dev = sbuf.st_dev;
+ GetTimeOfDay(&fsp->open_time);
+ fsp->vuid = current_user.vuid;
+ fsp->size = 0;
+ fsp->pos = -1;
+ fsp->open = True;
+ fsp->can_lock = True;
+ fsp->can_read = ((flags & O_WRONLY)==0);
+ fsp->can_write = ((flags & (O_WRONLY|O_RDWR))!=0);
+ fsp->share_mode = 0;
+ fsp->print_file = False;
+ fsp->modified = False;
+ fsp->oplock_type = NO_OPLOCK;
+ fsp->sent_oplock_break = NO_BREAK_SENT;
+ fsp->is_directory = False;
+ fsp->stat_open = False;
+ fsp->directory_delete_on_close = False;
+ fsp->conn = conn;
+ /*
+ * Note that the file name here is the *untranslated* name
+ * ie. it is still in the DOS codepage sent from the client.
+ * All use of this filename will pass though the sys_xxxx
+ * functions which will do the dos_to_unix translation before
+ * mapping into a UNIX filename. JRA.
+ */
+ string_set(&fsp->fsp_name,fname);
+ fsp->wbmpx_ptr = NULL;
+ fsp->wcp = NULL; /* Write cache pointer. */
- }
+ DEBUG(2,("%s opened file %s read=%s write=%s (numopen=%d)\n",
+ *sesssetup_user ? sesssetup_user : conn->user,fsp->fsp_name,
+ BOOLSTR(fsp->can_read), BOOLSTR(fsp->can_write),
+ conn->num_files_open));
}
/****************************************************************************
@@ -611,8 +185,7 @@ static void truncate_unless_locked(files_struct *fsp, connection_struct *conn, i
/* If share modes are in force for this connection we
have the share entry locked. Unlock it before closing. */
if (*share_locked && lp_share_modes(SNUM(conn)))
- unlock_share_entry( conn, fsp->fd_ptr->dev,
- fsp->fd_ptr->inode);
+ unlock_share_entry_fsp(fsp);
close_file(fsp,False);
/* Share mode no longer locked. */
*share_locked = False;
@@ -620,7 +193,7 @@ static void truncate_unless_locked(files_struct *fsp, connection_struct *conn, i
unix_ERR_class = ERRDOS;
unix_ERR_code = ERRlock;
} else {
- sys_ftruncate(fsp->fd_ptr->fd,0);
+ sys_ftruncate(fsp->fd,0);
}
}
}
@@ -814,11 +387,23 @@ void open_file_shared(files_struct *fsp,connection_struct *conn,char *fname,int
int oplock_contention_count = 0;
BOOL all_current_opens_are_level_II = False;
fsp->open = False;
- fsp->fd_ptr = 0;
+ fsp->fd = -1;
+
+ if (conn->printer) {
+ /* printers are handled completely differently. Most of the passed parameters are
+ ignored */
+ *Access = DOS_OPEN_WRONLY;
+ *action = FILE_WAS_CREATED;
+ print_open_file(fsp, conn, fname);
+ return;
+ }
DEBUG(10,("open_file_shared: fname = %s, share_mode = %x, ofun = %x, mode = %o, oplock request = %d\n",
fname, share_mode, ofun, (int)mode, oplock_request ));
+ if (!check_name(fname,conn)) {
+ return;
+ }
/* ignore any oplock requests if oplocks are disabled */
if (!lp_oplocks(SNUM(conn)) || global_client_failed_oplock_break) {
@@ -1011,11 +596,10 @@ dev = %x, inode = %.0f\n", old_shares[i].op_type, fname, (unsigned int)dev, (dou
DEBUG(4,("calling open_file with flags=0x%X flags2=0x%X mode=0%o\n",
flags,flags2,(int)mode));
- open_file(fsp,conn,fname,flags|(flags2&~(O_TRUNC)),mode,file_existed ? &sbuf : 0);
- if (!fsp->open && flags==O_RDWR && errno!=ENOENT && fcbopen)
- {
- flags = O_RDONLY;
- open_file(fsp,conn,fname,flags,mode,file_existed ? &sbuf : 0 );
+ open_file(fsp,conn,fname,flags|(flags2&~(O_TRUNC)),mode);
+ if (!fsp->open && flags==O_RDWR && errno != ENOENT && fcbopen) {
+ flags = O_RDONLY;
+ open_file(fsp,conn,fname,flags,mode);
}
if (fsp->open)
@@ -1025,9 +609,7 @@ dev = %x, inode = %.0f\n", old_shares[i].op_type, fname, (unsigned int)dev, (dou
if((share_locked == False) && lp_share_modes(SNUM(conn)))
{
/* We created the file - thus we must now lock the share entry before creating it. */
- dev = fsp->fd_ptr->dev;
- inode = fsp->fd_ptr->inode;
- lock_share_entry(conn, dev, inode);
+ lock_share_entry_fsp(fsp);
share_locked = True;
}
@@ -1090,12 +672,12 @@ dev = %x, inode = %.0f\n", old_shares[i].op_type, fname, (unsigned int)dev, (dou
}
if (share_locked && lp_share_modes(SNUM(conn)))
- unlock_share_entry( conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
}
/****************************************************************************
Open a file for permissions read only. Return a pseudo file entry
- with the 'stat_open' flag set and a fd_ptr of NULL.
+ with the 'stat_open' flag set
****************************************************************************/
int open_file_stat(files_struct *fsp,connection_struct *conn,
@@ -1122,7 +704,7 @@ int open_file_stat(files_struct *fsp,connection_struct *conn,
* Setup the files_struct for it.
*/
- fsp->fd_ptr = NULL;
+ fsp->fd = -1;
conn->num_files_open++;
fsp->mode = 0;
GetTimeOfDay(&fsp->open_time);
@@ -1235,7 +817,7 @@ int open_directory(files_struct *fsp,connection_struct *conn,
* Setup the files_struct for it.
*/
- fsp->fd_ptr = NULL;
+ fsp->fd = -1;
conn->num_files_open++;
fsp->mode = 0;
GetTimeOfDay(&fsp->open_time);
diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index c5cab8c225..218961d88c 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -280,22 +280,22 @@ static BOOL set_kernel_oplock(files_struct *fsp, int oplock_type)
#if defined(HAVE_KERNEL_OPLOCKS)
if(lp_kernel_oplocks()) {
- if(fcntl(fsp->fd_ptr->fd, F_OPLKREG, oplock_pipe_write) < 0 ) {
+ if(fcntl(fsp->fd, F_OPLKREG, oplock_pipe_write) < 0 ) {
if(errno != EAGAIN) {
DEBUG(0,("set_file_oplock: Unable to get kernel oplock on file %s, dev = %x, \
inode = %.0f. Error was %s\n",
- fsp->fsp_name, (unsigned int)fsp->fd_ptr->dev, (double)fsp->fd_ptr->inode,
+ fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode,
strerror(errno) ));
} else {
DEBUG(5,("set_file_oplock: Refused oplock on file %s, fd = %d, dev = %x, \
inode = %.0f. Another process had the file open.\n",
- fsp->fsp_name, fsp->fd_ptr->fd, (unsigned int)fsp->fd_ptr->dev, (double)fsp->fd_ptr->inode ));
+ fsp->fsp_name, fsp->fd, (unsigned int)fsp->dev, (double)fsp->inode ));
}
return False;
}
DEBUG(10,("set_file_oplock: got kernel oplock on file %s, dev = %x, inode = %.0f\n",
- fsp->fsp_name, (unsigned int)fsp->fd_ptr->dev, (double)fsp->fd_ptr->inode));
+ fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode));
}
#endif /* HAVE_KERNEL_OPLOCKS */
@@ -320,7 +320,7 @@ BOOL set_file_oplock(files_struct *fsp, int oplock_type)
exclusive_oplocks_open++;
DEBUG(5,("set_file_oplock: granted oplock on file %s, dev = %x, inode = %.0f, tv_sec = %x, tv_usec = %x\n",
- fsp->fsp_name, (unsigned int)fsp->fd_ptr->dev, (double)fsp->fd_ptr->inode,
+ fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode,
(int)fsp->open_time.tv_sec, (int)fsp->open_time.tv_usec ));
return True;
@@ -342,24 +342,24 @@ static void release_kernel_oplock(files_struct *fsp)
* Check and print out the current kernel
* oplock state of this file.
*/
- int state = fcntl(fsp->fd_ptr->fd, F_OPLKACK, -1);
+ int state = fcntl(fsp->fd, F_OPLKACK, -1);
dbgtext("release_kernel_oplock: file %s, dev = %x, inode = %.0f has kernel \
-oplock state of %x.\n", fsp->fsp_name, (unsigned int)fsp->fd_ptr->dev,
- (double)fsp->fd_ptr->inode, state );
+oplock state of %x.\n", fsp->fsp_name, (unsigned int)fsp->dev,
+ (double)fsp->inode, state );
}
/*
* Remove the kernel oplock on this file.
*/
- if(fcntl(fsp->fd_ptr->fd, F_OPLKACK, OP_REVOKE) < 0)
+ if(fcntl(fsp->fd, F_OPLKACK, OP_REVOKE) < 0)
{
if( DEBUGLVL( 0 ))
{
dbgtext("release_kernel_oplock: Error when removing kernel oplock on file " );
dbgtext("%s, dev = %x, inode = %.0f. Error was %s\n",
- fsp->fsp_name, (unsigned int)fsp->fd_ptr->dev,
- (double)fsp->fd_ptr->inode, strerror(errno) );
+ fsp->fsp_name, (unsigned int)fsp->dev,
+ (double)fsp->inode, strerror(errno) );
}
}
}
@@ -406,12 +406,12 @@ static void downgrade_file_oplock(files_struct *fsp)
BOOL remove_oplock(files_struct *fsp)
{
- SMB_DEV_T dev = fsp->fd_ptr->dev;
- SMB_INO_T inode = fsp->fd_ptr->inode;
+ SMB_DEV_T dev = fsp->dev;
+ SMB_INO_T inode = fsp->inode;
BOOL ret = True;
/* Remove the oplock flag from the sharemode. */
- if (lock_share_entry(fsp->conn, dev, inode) == False) {
+ if (lock_share_entry_fsp(fsp) == False) {
DEBUG(0,("remove_oplock: failed to lock share entry for file %s\n",
fsp->fsp_name ));
ret = False;
@@ -446,7 +446,7 @@ dev = %x, inode = %.0f\n", fsp->fsp_name, fsp->fnum, (unsigned int)dev, (double)
downgrade_file_oplock(fsp);
}
- unlock_share_entry(fsp->conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
return ret;
}
@@ -757,8 +757,8 @@ BOOL oplock_break_level2(files_struct *fsp, BOOL local_request, int token)
extern uint32 global_client_caps;
char outbuf[128];
BOOL got_lock = False;
- SMB_DEV_T dev = fsp->fd_ptr->dev;
- SMB_INO_T inode = fsp->fd_ptr->inode;
+ SMB_DEV_T dev = fsp->dev;
+ SMB_INO_T inode = fsp->inode;
/*
* We can have a level II oplock even if the client is not
@@ -791,7 +791,7 @@ BOOL oplock_break_level2(files_struct *fsp, BOOL local_request, int token)
* the existing lock on the shared memory area.
*/
- if(!local_request && lock_share_entry(fsp->conn, dev, inode) == False) {
+ if(!local_request && lock_share_entry_fsp(fsp) == False) {
DEBUG(0,("oplock_break_level2: unable to lock share entry for file %s\n", fsp->fsp_name ));
} else {
got_lock = True;
@@ -802,7 +802,7 @@ BOOL oplock_break_level2(files_struct *fsp, BOOL local_request, int token)
}
if (!local_request && got_lock)
- unlock_share_entry(fsp->conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
fsp->oplock_type = NO_OPLOCK;
level_II_oplocks_open--;
@@ -1308,14 +1308,12 @@ BOOL attempt_close_oplocked_file(files_struct *fsp)
DEBUG(5,("attempt_close_oplocked_file: checking file %s.\n", fsp->fsp_name));
- if (fsp->open && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !fsp->sent_oplock_break && (fsp->fd_ptr != NULL)) {
-
- /* Try and break the oplock. */
- file_fd_struct *fd_ptr = fsp->fd_ptr;
- if(oplock_break( fd_ptr->dev, fd_ptr->inode, &fsp->open_time, True)) {
- if(!fsp->open) /* Did the oplock break close the file ? */
- return True;
- }
+ if (fsp->open && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !fsp->sent_oplock_break && (fsp->fd != -1)) {
+ /* Try and break the oplock. */
+ if (oplock_break(fsp->dev, fsp->inode, &fsp->open_time, True)) {
+ if(!fsp->open) /* Did the oplock break close the file ? */
+ return True;
+ }
}
return False;
diff --git a/source3/smbd/predict.c b/source3/smbd/predict.c
deleted file mode 100644
index 34044b82f2..0000000000
--- a/source3/smbd/predict.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- Unix SMB/Netbios implementation.
- Version 1.9.
- file read prediction routines
- Copyright (C) Andrew Tridgell 1992-1998
-
- 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;
-
-#if USE_READ_PREDICTION
-
-/* variables used by the read prediction module */
-static int rp_fd = -1;
-static SMB_OFF_T rp_offset = 0;
-static ssize_t rp_length = 0;
-static ssize_t rp_alloced = 0;
-static int rp_predict_fd = -1;
-static SMB_OFF_T rp_predict_offset = 0;
-static size_t rp_predict_length = 0;
-static int rp_timeout = 5;
-static time_t rp_time = 0;
-static char *rp_buffer = NULL;
-static BOOL predict_skip=False;
-extern struct timeval smb_last_time;
-
-/****************************************************************************
-handle read prediction on a file
-****************************************************************************/
-ssize_t read_predict(files_struct *fsp, int fd,SMB_OFF_T offset,char *buf,char **ptr,size_t num)
-{
- ssize_t ret = 0;
- ssize_t possible = rp_length - (offset - rp_offset);
-
- possible = MIN(possible,num);
-
- /* give data if possible */
- if (fd == rp_fd &&
- offset >= rp_offset &&
- possible>0 &&
- smb_last_time.tv_secs - rp_time < rp_timeout)
- {
- ret = possible;
- if (buf)
- memcpy(buf,rp_buffer + (offset-rp_offset),possible);
- else
- *ptr = rp_buffer + (offset-rp_offset);
- DEBUG(5,("read-prediction gave %d bytes of %d\n",ret,num));
- }
-
- if (ret == num) {
- predict_skip = True;
- } else {
- SMB_STRUCT_STAT rp_stat;
-
- /* Find the end of the file - ensure we don't
- read predict beyond it. */
- if(fsp->conn->vfs_ops.fstat(fd,&rp_stat) < 0)
- {
- DEBUG(0,("read-prediction failed on fstat. Error was %s\n", strerror(errno)));
- predict_skip = True;
- }
- else
- {
- predict_skip = False;
-
- /* prepare the next prediction */
- rp_predict_fd = fd;
- /* Make sure we don't seek beyond the end of the file. */
- rp_predict_offset = MIN((offset + num),rp_stat.st_size);
- rp_predict_length = num;
- }
- }
-
- if (ret < 0) ret = 0;
-
- return(ret);
-}
-
-/****************************************************************************
-pre-read some data
-****************************************************************************/
-void do_read_prediction(connection_struct *conn)
-{
- static size_t readsize = 0;
-
- if (predict_skip) return;
-
- if (rp_predict_fd == -1)
- return;
-
- rp_fd = rp_predict_fd;
- rp_offset = rp_predict_offset;
- rp_length = 0;
-
- rp_predict_fd = -1;
-
- if (readsize == 0) {
- readsize = lp_readsize();
- readsize = MAX(readsize,1024);
- }
-
- rp_predict_length = MIN(rp_predict_length,2*readsize);
- rp_predict_length = MAX(rp_predict_length,1024);
- rp_offset = (rp_offset/1024)*1024;
- rp_predict_length = (rp_predict_length/1024)*1024;
-
- if (rp_predict_length > rp_alloced)
- {
- rp_buffer = Realloc(rp_buffer,rp_predict_length);
- rp_alloced = rp_predict_length;
- if (!rp_buffer)
- {
- DEBUG(0,("can't allocate read-prediction buffer\n"));
- rp_predict_fd = -1;
- rp_fd = -1;
- rp_alloced = 0;
- return;
- }
- }
-
- if (conn->vfs_ops.lseek(rp_fd,rp_offset,SEEK_SET) != rp_offset) {
- rp_fd = -1;
- rp_predict_fd = -1;
- return;
- }
-
- rp_length = conn->vfs_ops.read(rp_fd,rp_buffer,rp_predict_length);
- rp_time = time(NULL);
- if (rp_length < 0)
- rp_length = 0;
-}
-
-/****************************************************************************
-invalidate read-prediction on a fd
-****************************************************************************/
-void invalidate_read_prediction(int fd)
-{
- if (rp_fd == fd)
- rp_fd = -1;
- if (rp_predict_fd == fd)
- rp_predict_fd = -1;
-}
-
-#else
- void read_prediction_dummy(void) ;
-#endif
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 0092d6b397..81d3ef32b3 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -1549,17 +1549,6 @@ int reply_open(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
if (!fsp)
return(ERROR(ERRSRV,ERRnofids));
- if (!check_name(fname,conn))
- {
- if((errno == ENOENT) && bad_path)
- {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadpath;
- }
- file_free(fsp);
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
-
unixmode = unix_mode(conn,aARCH,fname);
open_file_shared(fsp,conn,fname,share_mode,(FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN),
@@ -1576,7 +1565,7 @@ int reply_open(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
return(UNIXERROR(ERRDOS,ERRnoaccess));
}
- if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf) != 0) {
+ if (fsp->conn->vfs_ops.fstat(fsp->fd,&sbuf) != 0) {
close_file(fsp,False);
return(ERROR(ERRDOS,ERRnoaccess));
}
@@ -1654,17 +1643,6 @@ int reply_open_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt
if (!fsp)
return(ERROR(ERRSRV,ERRnofids));
- if (!check_name(fname,conn))
- {
- if((errno == ENOENT) && bad_path)
- {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadpath;
- }
- file_free(fsp);
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
-
unixmode = unix_mode(conn,smb_attr | aARCH, fname);
open_file_shared(fsp,conn,fname,smb_mode,smb_ofun,unixmode,
@@ -1681,7 +1659,7 @@ int reply_open_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt
return(UNIXERROR(ERRDOS,ERRnoaccess));
}
- if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf) != 0) {
+ if (fsp->conn->vfs_ops.fstat(fsp->fd,&sbuf) != 0) {
close_file(fsp,False);
return(ERROR(ERRDOS,ERRnoaccess));
}
@@ -1798,17 +1776,6 @@ int reply_mknew(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
if (!fsp)
return(ERROR(ERRSRV,ERRnofids));
- if (!check_name(fname,conn))
- {
- if((errno == ENOENT) && bad_path)
- {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadpath;
- }
- file_free(fsp);
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
-
if(com == SMBmknew)
{
/* We should fail if file exists. */
@@ -1847,7 +1814,7 @@ int reply_mknew(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
DEBUG( 2, ( "new file %s\n", fname ) );
DEBUG( 3, ( "mknew %s fd=%d dmode=%d umode=%o\n",
- fname, fsp->fd_ptr->fd, createmode, (int)unixmode ) );
+ fname, fsp->fd, createmode, (int)unixmode ) );
return(outsize);
}
@@ -1881,17 +1848,6 @@ int reply_ctemp(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
if (fsp)
return(ERROR(ERRSRV,ERRnofids));
- if (!check_name(fname,conn))
- {
- if((errno == ENOENT) && bad_path)
- {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadpath;
- }
- file_free(fsp);
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
-
pstrcpy(fname2,(char *)smbd_mktemp(fname));
/* Open file in dos compatibility share mode. */
@@ -1924,7 +1880,7 @@ int reply_ctemp(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
DEBUG( 2, ( "created temp file %s\n", fname2 ) );
DEBUG( 3, ( "ctemp %s fd=%d dmode=%d umode=%o\n",
- fname2, fsp->fd_ptr->fd, createmode, (int)unixmode ) );
+ fname2, fsp->fd, createmode, (int)unixmode ) );
return(outsize);
}
@@ -2161,7 +2117,7 @@ int reply_readbraw(connection_struct *conn, char *inbuf, char *outbuf, int dum_s
if (size < sizeneeded)
{
SMB_STRUCT_STAT st;
- if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd,&st) == 0)
+ if (fsp->conn->vfs_ops.fstat(fsp->fd,&st) == 0)
size = st.st_size;
if (!fsp->can_write)
fsp->size = size;
@@ -2185,7 +2141,7 @@ int reply_readbraw(connection_struct *conn, char *inbuf, char *outbuf, int dum_s
#if USE_READ_PREDICTION
if (!fsp->can_write)
- predict = read_predict(fsp, fsp->fd_ptr->fd,startpos,header+4,NULL,nread);
+ predict = read_predict(fsp, fsp->fd,startpos,header+4,NULL,nread);
#endif /* USE_READ_PREDICTION */
if ((nread-predict) > 0) {
@@ -2197,7 +2153,7 @@ int reply_readbraw(connection_struct *conn, char *inbuf, char *outbuf, int dum_s
}
if(!seek_fail)
- ret = (ssize_t)vfs_transfer_file(-1, fsp->fd_ptr->fd, Client, NULL,
+ ret = (ssize_t)vfs_transfer_file(-1, fsp->fd, Client, NULL,
(SMB_OFF_T)(nread-predict),header,4+predict,
startpos+predict);
}
@@ -2480,7 +2436,7 @@ int reply_writebraw(connection_struct *conn, char *inbuf,char *outbuf, int size,
if ((lp_syncalways(SNUM(conn)) || write_through) &&
lp_strict_sync(SNUM(conn)))
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
DEBUG(3,("writebraw2 fnum=%d start=%.0f num=%d wrote=%d\n",
fsp->fnum, (double)startpos, (int)numtowrite,(int)total_written));
@@ -2528,7 +2484,7 @@ int reply_writeunlock(connection_struct *conn, char *inbuf,char *outbuf, int siz
nwritten = write_file(fsp,data,startpos,numtowrite);
if (lp_syncalways(SNUM(conn)))
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0))
return(UNIXERROR(ERRDOS,ERRnoaccess));
@@ -2577,13 +2533,13 @@ int reply_write(connection_struct *conn, char *inbuf,char *outbuf,int size,int d
zero then the file size should be extended or
truncated to the size given in smb_vwv[2-3] */
if(numtowrite == 0) {
- if((nwritten = set_filelen(fsp->fd_ptr->fd, (SMB_OFF_T)startpos)) >= 0) /* tpot vfs */
+ if((nwritten = set_filelen(fsp->fd, (SMB_OFF_T)startpos)) >= 0) /* tpot vfs */
set_filelen_write_cache(fsp, startpos);
} else
nwritten = write_file(fsp,data,startpos,numtowrite);
if (lp_syncalways(SNUM(conn)))
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0))
return(UNIXERROR(ERRDOS,ERRnoaccess));
@@ -2677,7 +2633,7 @@ int reply_write_and_X(connection_struct *conn, char *inbuf,char *outbuf,int leng
fsp->fnum, (int)numtowrite, (int)nwritten));
if (lp_syncalways(SNUM(conn)) || write_through)
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
return chain_reply(inbuf,outbuf,length,bufsize);
}
@@ -2711,7 +2667,7 @@ int reply_lseek(connection_struct *conn, char *inbuf,char *outbuf, int size, int
umode = SEEK_SET; break;
}
- if((res = conn->vfs_ops.lseek(fsp->fd_ptr->fd,startpos,umode)) == -1) {
+ if((res = conn->vfs_ops.lseek(fsp->fd,startpos,umode)) == -1) {
/*
* Check for the special case where a seek before the start
* of the file sets the offset to zero. Added in the CIFS spec,
@@ -2723,7 +2679,7 @@ int reply_lseek(connection_struct *conn, char *inbuf,char *outbuf, int size, int
if(umode == SEEK_CUR) {
- if((current_pos = conn->vfs_ops.lseek(fsp->fd_ptr->fd,0,SEEK_CUR)) == -1)
+ if((current_pos = conn->vfs_ops.lseek(fsp->fd,0,SEEK_CUR)) == -1)
return(UNIXERROR(ERRDOS,ERRnoaccess));
current_pos += startpos;
@@ -2732,14 +2688,14 @@ int reply_lseek(connection_struct *conn, char *inbuf,char *outbuf, int size, int
SMB_STRUCT_STAT sbuf;
- if(conn->vfs_ops.fstat(fsp->fd_ptr->fd, &sbuf) == -1)
+ if(conn->vfs_ops.fstat(fsp->fd, &sbuf) == -1)
return(UNIXERROR(ERRDOS,ERRnoaccess));
current_pos += sbuf.st_size;
}
if(current_pos < 0)
- res = conn->vfs_ops.lseek(fsp->fd_ptr->fd,0,SEEK_SET);
+ res = conn->vfs_ops.lseek(fsp->fd,0,SEEK_SET);
}
if(res == -1)
@@ -2774,7 +2730,7 @@ int reply_flush(connection_struct *conn, char *inbuf,char *outbuf, int size, int
if (!fsp) {
file_sync_all(conn);
} else {
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
}
DEBUG(3,("flush\n"));
@@ -2855,7 +2811,7 @@ int reply_close(connection_struct *conn, char *inbuf,char *outbuf, int size,
set_filetime(conn, fsp->fsp_name,mtime);
DEBUG(3,("close fd=%d fnum=%d (numopen=%d)\n",
- fsp->fd_ptr ? fsp->fd_ptr->fd : -1, fsp->fnum,
+ fsp->fd, fsp->fnum,
conn->num_files_open));
/*
@@ -2950,7 +2906,7 @@ int reply_lock(connection_struct *conn,
offset = IVAL(inbuf,smb_vwv3);
DEBUG(3,("lock fd=%d fnum=%d offset=%.0f count=%.0f\n",
- fsp->fd_ptr->fd, fsp->fnum, (double)offset, (double)count));
+ fsp->fd, fsp->fnum, (double)offset, (double)count));
if (!do_lock(fsp, conn, count, offset, WRITE_LOCK, &eclass, &ecode)) {
if((ecode == ERRlock) && lp_blocking_locks(SNUM(conn))) {
@@ -2990,7 +2946,7 @@ int reply_unlock(connection_struct *conn, char *inbuf,char *outbuf, int size, in
return (ERROR(eclass,ecode));
DEBUG( 3, ( "unlock fd=%d fnum=%d offset=%.0f count=%.0f\n",
- fsp->fd_ptr->fd, fsp->fnum, (double)offset, (double)count ) );
+ fsp->fd, fsp->fnum, (double)offset, (double)count ) );
return(outsize);
}
@@ -3063,60 +3019,29 @@ int reply_echo(connection_struct *conn,
int reply_printopen(connection_struct *conn,
char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
{
- pstring fname;
- pstring fname2;
int outsize = 0;
files_struct *fsp;
- *fname = *fname2 = 0;
-
if (!CAN_PRINT(conn))
return(ERROR(ERRDOS,ERRnoaccess));
- {
- pstring s;
- char *p;
- pstrcpy(s,smb_buf(inbuf)+1);
- p = s;
- while (*p) {
- if (!(isalnum((int)*p) || strchr("._-",*p)))
- *p = 'X';
- p++;
- }
-
- if (strlen(s) > 10) s[10] = 0;
-
- slprintf(fname,sizeof(fname)-1, "%s.XXXXXX",s);
- }
-
fsp = file_new();
if (!fsp)
return(ERROR(ERRSRV,ERRnofids));
- pstrcpy(fname2,(char *)smbd_mktemp(fname));
-
- if (!check_name(fname2,conn)) {
- file_free(fsp);
- return(ERROR(ERRDOS,ERRnoaccess));
- }
-
/* Open for exclusive use, write only. */
- open_file_shared(fsp,conn,fname2, SET_DENY_MODE(DENY_ALL)|SET_OPEN_MODE(DOS_OPEN_WRONLY),
- (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_FAIL), unix_mode(conn,0,fname2), 0, NULL, NULL);
+ print_open_file(fsp,conn,"dos.prn");
if (!fsp->open) {
file_free(fsp);
return(UNIXERROR(ERRDOS,ERRnoaccess));
}
- /* force it to be a print file */
- fsp->print_file = True;
-
outsize = set_message(outbuf,1,0,True);
SSVAL(outbuf,smb_vwv0,fsp->fnum);
- DEBUG(3,("openprint %s fd=%d fnum=%d\n",
- fname2, fsp->fd_ptr->fd, fsp->fnum));
+ DEBUG(3,("openprint fd=%d fnum=%d\n",
+ fsp->fd, fsp->fnum));
return(outsize);
}
@@ -3139,7 +3064,7 @@ int reply_printclose(connection_struct *conn,
return(ERROR(ERRDOS,ERRnoaccess));
DEBUG(3,("printclose fd=%d fnum=%d\n",
- fsp->fd_ptr->fd,fsp->fnum));
+ fsp->fd,fsp->fnum));
close_err = close_file(fsp,True);
@@ -3851,7 +3776,7 @@ static BOOL copy_file(char *src,char *dest1,connection_struct *conn, int ofun,
}
if ((ofun&3) == 1) {
- if(conn->vfs_ops.lseek(fsp2->fd_ptr->fd,0,SEEK_END) == -1) {
+ if(conn->vfs_ops.lseek(fsp2->fd,0,SEEK_END) == -1) {
DEBUG(0,("copy_file: error - sys_lseek returned error %s\n",
strerror(errno) ));
/*
@@ -4469,7 +4394,7 @@ int reply_writebmpx(connection_struct *conn, char *inbuf,char *outbuf, int size,
nwritten = write_file(fsp,data,startpos,numtowrite);
if(lp_syncalways(SNUM(conn)) || write_through)
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
if(nwritten < (ssize_t)numtowrite)
return(UNIXERROR(ERRHRD,ERRdiskfull));
@@ -4570,7 +4495,7 @@ int reply_writebs(connection_struct *conn, char *inbuf,char *outbuf, int dum_siz
nwritten = write_file(fsp,data,startpos,numtowrite);
if(lp_syncalways(SNUM(conn)) || write_through)
- conn->vfs_ops.fsync(fsp->fd_ptr->fd);
+ conn->vfs_ops.fsync(fsp->fd);
if (nwritten < (ssize_t)numtowrite)
{
@@ -4677,7 +4602,7 @@ int reply_getattrE(connection_struct *conn, char *inbuf,char *outbuf, int size,
CHECK_ERROR(fsp);
/* Do an fstat on this file */
- if(fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd, &sbuf))
+ if(fsp->conn->vfs_ops.fstat(fsp->fd, &sbuf))
return(UNIXERROR(ERRDOS,ERRnoaccess));
mode = dos_mode(conn,fsp->fsp_name,&sbuf);
diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index f90ce2ede4..f1fa30b0c6 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -253,7 +253,7 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf,
return(UNIXERROR(ERRDOS,ERRnoaccess));
}
- if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf) != 0) {
+ if (fsp->conn->vfs_ops.fstat(fsp->fd,&sbuf) != 0) {
close_file(fsp,False);
return(UNIXERROR(ERRDOS,ERRnoaccess));
}
@@ -1332,14 +1332,14 @@ static int call_trans2qfilepathinfo(connection_struct *conn,
CHECK_ERROR(fsp);
fname = fsp->fsp_name;
- if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf) != 0) {
+ if (fsp->conn->vfs_ops.fstat(fsp->fd,&sbuf) != 0) {
DEBUG(3,("fstat of fnum %d failed (%s)\n",fsp->fnum, strerror(errno)));
return(UNIXERROR(ERRDOS,ERRbadfid));
}
- if((pos = fsp->conn->vfs_ops.lseek(fsp->fd_ptr->fd,0,SEEK_CUR)) == -1)
+ if((pos = fsp->conn->vfs_ops.lseek(fsp->fd,0,SEEK_CUR)) == -1)
return(UNIXERROR(ERRDOS,ERRnoaccess));
- delete_pending = fsp->fd_ptr->delete_on_close;
+ delete_pending = fsp->delete_on_close;
}
} else {
/* qpathinfo */
@@ -1612,7 +1612,7 @@ static int call_trans2setfilepathinfo(connection_struct *conn,
CHECK_ERROR(fsp);
fname = fsp->fsp_name;
- fd = fsp->fd_ptr->fd;
+ fd = fsp->fd;
if (fsp->conn->vfs_ops.fstat(fd,&st) != 0) {
DEBUG(3,("fstat of fnum %d failed (%s)\n",fsp->fnum, strerror(errno)));
@@ -1811,12 +1811,12 @@ static int call_trans2setfilepathinfo(connection_struct *conn,
{
int i;
files_struct *iterate_fsp;
- SMB_DEV_T dev = fsp->fd_ptr->dev;
- SMB_INO_T inode = fsp->fd_ptr->inode;
+ SMB_DEV_T dev = fsp->dev;
+ SMB_INO_T inode = fsp->inode;
int num_share_modes;
share_mode_entry *current_shares = NULL;
- if(lock_share_entry(fsp->conn, dev, inode) == False)
+ if (lock_share_entry_fsp(fsp) == False)
return(ERROR(ERRDOS,ERRnoaccess));
/*
@@ -1838,7 +1838,7 @@ file %s as a share exists that was not opened with FILE_DELETE access.\n",
* Release the lock.
*/
- unlock_share_entry(fsp->conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
/*
* current_shares was malloced by get_share_modes - free it here.
@@ -1893,9 +1893,9 @@ dev = %x, inode = %.0f\n", iterate_fsp->fnum, (unsigned int)dev, (double)inode))
* counted struct. Delete when the last reference
* goes away.
*/
- fsp->fd_ptr->delete_on_close = delete_on_close;
+ fsp->delete_on_close = delete_on_close;
- unlock_share_entry(fsp->conn, dev, inode);
+ unlock_share_entry_fsp(fsp);
DEBUG(10, ("call_trans2setfilepathinfo: %s delete on close flag for fnum = %d, file %s\n",
delete_on_close ? "Added" : "Removed", fsp->fnum, fsp->fsp_name ));
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index 44f44bd169..e92235e230 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -251,11 +251,10 @@ ssize_t vfs_write_data(files_struct *fsp,char *buffer,size_t N)
{
size_t total=0;
ssize_t ret;
- int fd = fsp->fd_ptr->fd;
while (total < N)
{
- ret = fsp->conn->vfs_ops.write(fd,buffer + total,N - total);
+ ret = fsp->conn->vfs_ops.write(fsp->fd,buffer + total,N - total);
if (ret == -1) return -1;
if (ret == 0) return total;
@@ -331,13 +330,13 @@ SMB_OFF_T vfs_transfer_file(int in_fd, files_struct *in_fsp,
if (s > ret) {
ret += in_fsp ?
- in_fsp->conn->vfs_ops.read(in_fsp->fd_ptr->fd,buf1+ret,s-ret) : read(in_fd,buf1+ret,s-ret);
+ in_fsp->conn->vfs_ops.read(in_fsp->fd,buf1+ret,s-ret) : read(in_fd,buf1+ret,s-ret);
}
if (ret > 0)
{
if (out_fsp) {
- ret2 = out_fsp->conn->vfs_ops.write(out_fsp->fd_ptr->fd,buf1,ret);
+ ret2 = out_fsp->conn->vfs_ops.write(out_fsp->fd,buf1,ret);
} else {
ret2= (out_fd != -1) ? write_data(out_fd,buf1,ret) : ret;
}