summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-10-22 06:55:18 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:02:25 -0500
commitf71e7ae1e34510081c393f5ae73a279e8c4d0641 (patch)
tree47de7aec83d0ff0649758cacc046f2aeb2133c0c
parent6e8867bff5ac95a7f509e3fdc60183cc64d921eb (diff)
downloadsamba-f71e7ae1e34510081c393f5ae73a279e8c4d0641.tar.gz
samba-f71e7ae1e34510081c393f5ae73a279e8c4d0641.tar.bz2
samba-f71e7ae1e34510081c393f5ae73a279e8c4d0641.zip
r3133: - more consistent error checking in rename and setfileinfo
- add paranoid checking of device/inode change during open to detect race conditions (This used to be commit 043361fed487ed494fa497ffde1007b3f3bc0c29)
-rw-r--r--source4/ntvfs/posix/pvfs_rename.c2
-rw-r--r--source4/ntvfs/posix/pvfs_resolve.c19
-rw-r--r--source4/ntvfs/posix/pvfs_setfileinfo.c2
3 files changed, 21 insertions, 2 deletions
diff --git a/source4/ntvfs/posix/pvfs_rename.c b/source4/ntvfs/posix/pvfs_rename.c
index 51393c9499..80b6a510b0 100644
--- a/source4/ntvfs/posix/pvfs_rename.c
+++ b/source4/ntvfs/posix/pvfs_rename.c
@@ -62,7 +62,7 @@ NTSTATUS pvfs_rename(struct ntvfs_module_context *ntvfs,
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);
}
diff --git a/source4/ntvfs/posix/pvfs_resolve.c b/source4/ntvfs/posix/pvfs_resolve.c
index 97068c3d03..5b86cd3a73 100644
--- a/source4/ntvfs/posix/pvfs_resolve.c
+++ b/source4/ntvfs/posix/pvfs_resolve.c
@@ -364,10 +364,29 @@ NTSTATUS pvfs_resolve_partial(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
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);
diff --git a/source4/ntvfs/posix/pvfs_setfileinfo.c b/source4/ntvfs/posix/pvfs_setfileinfo.c
index f1d5d14089..8892c92c3c 100644
--- a/source4/ntvfs/posix/pvfs_setfileinfo.c
+++ b/source4/ntvfs/posix/pvfs_setfileinfo.c
@@ -43,7 +43,7 @@ NTSTATUS pvfs_setfileinfo(struct ntvfs_module_context *ntvfs,
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;