From fa2ec3651ec88777930e478c888096907006fd8b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 24 Aug 2005 13:15:01 +0000 Subject: r9584: Fix a race condition in Samba 3. If two files are opened simultaneously with NTCREATEX_DISP_CREATE (create if not exists, else fail) they might end up with two or more times NT_STATUS_OK as EEXIST is not correctly handled. Jeremy, please look closely at this. You can easily verify this by adding a smb_msleep(100) to the top of open_file_ntcreate and run the new samba4 torture test. It does also happen without the msleep, but not as reliably. Thanks, Volker (This used to be commit 58b9e48df03098160f39607d869a3c8e10860ba4) --- source3/smbd/open.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source3/smbd') diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 3cd553f55b..98c2997a97 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -1585,6 +1585,15 @@ files_struct *open_file_ntcreate(connection_struct *conn, fsp_open = open_file(fsp,conn,fname,psbuf,flags|flags2,unx_mode,access_mask); + if (!fsp_open && (flags2 & O_EXCL) && (errno == EEXIST)) { + /* + * Two smbd's tried to open exclusively, but only one of them + * succeeded. + */ + file_free(fsp); + return NULL; + } + if (!fsp_open && (flags == O_RDWR) && (errno != ENOENT)) { if((fsp_open = open_file(fsp,conn,fname,psbuf, O_RDONLY,unx_mode,access_mask)) == True) { -- cgit