summaryrefslogtreecommitdiff
path: root/source/locking/locking.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1997-10-17 23:08:07 +0000
committerJeremy Allison <jra@samba.org>1997-10-17 23:08:07 +0000
commit6904c2de080b2a9702800e9e4126386ced20569d (patch)
tree1d8d96383035c3fbec9b3c1085960586b98394a5 /source/locking/locking.c
parent92e7092af1daf9349ca9fb00cd27c0ddc21b37d9 (diff)
downloadsamba-6904c2de080b2a9702800e9e4126386ced20569d.tar.gz
.cvsignore: Added make_smbcodepage
interface.c: Added is_local_net(). locking.c: Added Fix for zero length share files from Gerald Werner <wernerg@mfldclin.edu> plus a race condition fix for the fix. nameannounce.c: Made function static. namedbresp.c: extern int ClientDGRAM removed - not used. namedbserver.c: extern int ClientDGRAM removed - not used. namedbsubnet.c: Added code to make sockets per subnet. namepacket.c: Added code to read from all sockets & filter. nameresp.c: extern int ClientDGRAM removed - not used. nameserv.c: Indentation tidyup :-). nameserv.h: Added sockets to struct subnet. nameservresp.c: Improved debug message. nmbd.c: Changed to terminte on listen_for_packets exiting. nmbsync.c: extern int ClientDGRAM & ClientNMB removed - not used. proto.h: The usual. util.c: Fixed debug message. Jeremy (jallison@whistle.com)
Diffstat (limited to 'source/locking/locking.c')
-rw-r--r--source/locking/locking.c75
1 files changed, 50 insertions, 25 deletions
diff --git a/source/locking/locking.c b/source/locking/locking.c
index 5071121bed0..bbc0c0033ff 100644
--- a/source/locking/locking.c
+++ b/source/locking/locking.c
@@ -716,6 +716,31 @@ static BOOL share_name(int cnum, uint32 dev, uint32 inode, char *name)
}
/*******************************************************************
+Force a share file to be deleted.
+********************************************************************/
+
+static int delete_share_file( int cnum, char *fname )
+{
+ /* the share file could be owned by anyone, so do this as root */
+ become_root(False);
+
+ if(unlink(fname) != 0)
+ {
+ DEBUG(0,("delete_share_file: Can't delete share file %s (%s)\n",
+ fname, strerror(errno)));
+ }
+ else
+ {
+ DEBUG(5,("delete_share_file: Deleted share file %s\n", fname));
+ }
+
+ /* return to our previous privilage level */
+ unbecome_root(False);
+
+ return 0;
+}
+
+/*******************************************************************
lock a share mode file.
******************************************************************/
BOOL lock_share_entry(int cnum, uint32 dev, uint32 inode, share_lock_token *ptok)
@@ -820,6 +845,31 @@ BOOL unlock_share_entry(int cnum, uint32 dev, uint32 inode, share_lock_token tok
{
int fd = (int)token;
int ret = True;
+ struct stat sb;
+ pstring fname;
+
+ /* Fix for zero length share files from
+ Gerald Werner <wernerg@mfldclin.edu> */
+
+ share_name(cnum, dev, inode, fname);
+
+ /* get the share mode file size */
+ if(fstat((int)token, &sb) != 0)
+ {
+ DEBUG(0,("ERROR: unlock_share_entry: Failed to do stat on share file %s (%s)\n",
+ fname, strerror(errno)));
+ sb.st_size = 1;
+ ret = False;
+ }
+
+ /* If the file was zero length, we must delete before
+ doing the unlock to avoid a race condition (see
+ the code in lock_share_mode_entry for details.
+ */
+
+ /* remove the share file if zero length */
+ if(sb.st_size == 0)
+ delete_share_file(cnum, fname);
/* token is the fd of the open share mode file. */
/* Unlock the first byte. */
@@ -835,31 +885,6 @@ BOOL unlock_share_entry(int cnum, uint32 dev, uint32 inode, share_lock_token tok
}
/*******************************************************************
-Force a share file to be deleted.
-********************************************************************/
-
-static int delete_share_file( int cnum, char *fname )
-{
- /* the share file could be owned by anyone, so do this as root */
- become_root(False);
-
- if(unlink(fname) != 0)
- {
- DEBUG(0,("delete_share_file: Can't delete share file %s (%s)\n",
- fname, strerror(errno)));
- }
- else
- {
- DEBUG(5,("delete_share_file: Deleted share file %s\n", fname));
- }
-
- /* return to our previous privilage level */
- unbecome_root(False);
-
- return 0;
-}
-
-/*******************************************************************
Read a share file into a buffer.
********************************************************************/