From 53850c51caf1c4d53ff285b2e5505e0615beeeee Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 14 Apr 2001 00:19:12 +0000 Subject: configure: configure.in: include/config.h.in: include/profile.h: smbd/vfs-wrap.c: smbd/vfs.c: Added fchmod and fchown to VFS (sorry Gerald - but we needed them anyway). smbd/dosmode.c: smbd/files.c: printing/printfsp.c: smbd/close.c: smbd/open.c: Fixed "dos filemode" correctly so there are no race conditions. Forces test of open of file O_WRONLY before allowing fchmod as root. Afterwards, calls standard close function that preserves POSIX locks due to POSIX-me-harder braindamage. :-). Andrew please review this code. Also - in removing the tmpdir param in smbrun an extra NULL parameter was missed in each print_run_command() call (which is a varargs fn.). Now fixed. Jeremy. (This used to be commit 32397e5bc6d995ce7ca37c82d6aedc1e5b1b6fbd) --- source3/smbd/open.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 7 deletions(-) (limited to 'source3/smbd/open.c') diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 007a169f9e..f450e74e58 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -583,13 +583,10 @@ files_struct *open_file_shared(connection_struct *conn,char *fname, SMB_STRUCT_S return print_fsp_open(conn, fname); } - fsp = file_new(); + fsp = file_new(conn); if(!fsp) return NULL; - fsp->fd = -1; - fsp->conn = conn; /* The vfs_fXXX() macros need this. */ - 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 )); @@ -870,7 +867,7 @@ files_struct *open_file_stat(connection_struct *conn, char *fname, return NULL; } - fsp = file_new(); + fsp = file_new(conn); if(!fsp) return NULL; @@ -918,6 +915,49 @@ files_struct *open_file_stat(connection_struct *conn, char *fname, return fsp; } +/**************************************************************************** + Open a file for for write to ensure that we can fchmod it. +****************************************************************************/ + +files_struct *open_file_fchmod(connection_struct *conn, char *fname, SMB_STRUCT_STAT *psbuf) +{ + files_struct *fsp = NULL; + BOOL fsp_open; + + if (!VALID_STAT(*psbuf)) + return NULL; + + fsp = file_new(conn); + if(!fsp) + return NULL; + + fsp_open = open_file(fsp,conn,fname,psbuf,O_WRONLY,0); + + /* + * This is not a user visible file open. + * Don't set a share mode and don't increment + * the conn->num_files_open. + */ + + if (!fsp_open) { + file_free(fsp); + return NULL; + } + + return fsp; +} + +/**************************************************************************** + Close the fchmod file fd - ensure no locks are lost. +****************************************************************************/ + +int close_file_fchmod(files_struct *fsp) +{ + int ret = fd_close(fsp->conn, fsp); + file_free(fsp); + return ret; +} + /**************************************************************************** Open a directory from an NT SMB call. ****************************************************************************/ @@ -927,12 +967,12 @@ files_struct *open_directory(connection_struct *conn, char *fname, { extern struct current_user current_user; BOOL got_stat = False; - files_struct *fsp = file_new(); + files_struct *fsp = file_new(conn); if(!fsp) return NULL; - fsp->conn = conn; /* THe vfs_fXXX() macros need this. */ + fsp->conn = conn; /* The vfs_fXXX() macros need this. */ if (VALID_STAT(*psbuf)) got_stat = True; -- cgit