mirror of
https://github.com/samba-team/samba.git
synced 2025-01-17 02:05:21 +03:00
r3133: - more consistent error checking in rename and setfileinfo
- add paranoid checking of device/inode change during open to detect race conditions
This commit is contained in:
parent
c33cdd0d55
commit
043361fed4
@ -62,7 +62,7 @@ NTSTATUS pvfs_rename(struct ntvfs_module_context *ntvfs,
|
|||||||
return NT_STATUS_OBJECT_NAME_COLLISION;
|
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);
|
return pvfs_map_errno(pvfs, errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,
|
NTSTATUS pvfs_resolve_name_fd(struct pvfs_state *pvfs, int fd,
|
||||||
struct pvfs_filename *name)
|
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) {
|
if (fstat(fd, &name->st) == -1) {
|
||||||
return NT_STATUS_INVALID_HANDLE;
|
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;
|
name->exists = True;
|
||||||
|
|
||||||
return pvfs_fill_dos_info(pvfs, name);
|
return pvfs_fill_dos_info(pvfs, name);
|
||||||
|
@ -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_INFO:
|
||||||
case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
|
case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
|
||||||
if (ftruncate(f->fd,
|
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);
|
return pvfs_map_errno(pvfs, errno);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user