svn commit: samba r3133 - in branches/SAMBA_4_0/source/ntvfs/posix: .

tridge at samba.org tridge at samba.org
Fri Oct 22 06:55:25 GMT 2004


Author: tridge
Date: 2004-10-22 06:55:18 +0000 (Fri, 22 Oct 2004)
New Revision: 3133

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source/ntvfs/posix&rev=3133&nolog=1

Log:
- more consistent error checking in rename and setfileinfo

- add paranoid checking of device/inode change during open to detect race conditions


Modified:
   branches/SAMBA_4_0/source/ntvfs/posix/pvfs_rename.c
   branches/SAMBA_4_0/source/ntvfs/posix/pvfs_resolve.c
   branches/SAMBA_4_0/source/ntvfs/posix/pvfs_setfileinfo.c


Changeset:
Modified: branches/SAMBA_4_0/source/ntvfs/posix/pvfs_rename.c
===================================================================
--- branches/SAMBA_4_0/source/ntvfs/posix/pvfs_rename.c	2004-10-22 06:53:18 UTC (rev 3132)
+++ branches/SAMBA_4_0/source/ntvfs/posix/pvfs_rename.c	2004-10-22 06:55:18 UTC (rev 3133)
@@ -62,7 +62,7 @@
 		return NT_STATUS_OBJECT_NAME_COLLISION;
 	}
 
-	if (rename(name1->full_name, name2->full_name) != 0) {
+	if (rename(name1->full_name, name2->full_name) == -1) {
 		return pvfs_map_errno(pvfs, errno);
 	}
 	

Modified: branches/SAMBA_4_0/source/ntvfs/posix/pvfs_resolve.c
===================================================================
--- branches/SAMBA_4_0/source/ntvfs/posix/pvfs_resolve.c	2004-10-22 06:53:18 UTC (rev 3132)
+++ branches/SAMBA_4_0/source/ntvfs/posix/pvfs_resolve.c	2004-10-22 06:55:18 UTC (rev 3133)
@@ -364,10 +364,29 @@
 NTSTATUS pvfs_resolve_name_fd(struct pvfs_state *pvfs, int fd,
 			      struct pvfs_filename *name)
 {
+	dev_t device;
+	ino_t inode;
+
+	if (name->exists) {
+		device = name->st.st_dev;
+		inode = name->st.st_ino;
+	}
+
 	if (fstat(fd, &name->st) == -1) {
 		return NT_STATUS_INVALID_HANDLE;
 	}
 
+	if (name->exists &&
+	    (device != name->st.st_dev || inode != name->st.st_ino)) {
+		/* the file we are looking at has changed! this could
+		 be someone trying to exploit a race
+		 condition. Certainly we don't want to continue
+		 operating on this file */
+		DEBUG(0,("pvfs: WARNING: file '%s' changed during resole - failing\n",
+			 name->full_name));
+		return NT_STATUS_UNEXPECTED_IO_ERROR;
+	}
+
 	name->exists = True;
 	
 	return pvfs_fill_dos_info(pvfs, name);

Modified: branches/SAMBA_4_0/source/ntvfs/posix/pvfs_setfileinfo.c
===================================================================
--- branches/SAMBA_4_0/source/ntvfs/posix/pvfs_setfileinfo.c	2004-10-22 06:53:18 UTC (rev 3132)
+++ branches/SAMBA_4_0/source/ntvfs/posix/pvfs_setfileinfo.c	2004-10-22 06:55:18 UTC (rev 3133)
@@ -43,7 +43,7 @@
 	case RAW_SFILEINFO_END_OF_FILE_INFO:
 	case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
 		if (ftruncate(f->fd,
-			      info->end_of_file_info.in.size) != 0) {
+			      info->end_of_file_info.in.size) == -1) {
 			return pvfs_map_errno(pvfs, errno);
 		}
 		break;



More information about the samba-cvs mailing list