From 0ac30f5598f1f03b992151dac04f4a6ffc99099f Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Thu, 20 Jan 2011 02:15:18 -0500 Subject: [PATCH] vol: fix CreateFile params nt_unlink and nt_open nt_unlink: when opening a file handle to assign delete on close status the caller must request DELETE permission. nt_open: make sure that DELETE permission along with FILE_SHARE_DELETE is requested if we wish to permit another CreateFile call in the future to assign delete on close. Reviewed-on: http://gerrit.openafs.org/3711 Reviewed-by: Andrew Deason Tested-by: BuildBot Reviewed-by: Rod Widdowson Reviewed-by: Derrick Brashear (cherry picked from commit 5fdc2679dc973fa45bf4b3bc7f21a527492868db) Change-Id: I63855a65c5e209dc7b601e5b5b67ccb21bfb653c Reviewed-on: http://gerrit.openafs.org/3856 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/vol/ntops.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/vol/ntops.c b/src/vol/ntops.c index 4155e1367..18a847ccb 100644 --- a/src/vol/ntops.c +++ b/src/vol/ntops.c @@ -45,20 +45,21 @@ * * This nt_unlink has the delete on last close semantics of the Unix unlink * with a minor twist. Subsequent CreateFile calls on this file can succeed - * if they open for delete. It's also unclear what happens if a CreateFile - * call tries to create a new file with the same name. Fortunately, neither - * case should occur as part of nt_dec. + * if they open for delete. If a CreateFile call tries to create a new file + * with the same name it will fail. Fortunately, neither case should occur + * as part of nt_dec. */ int nt_unlink(char *name) { HANDLE fh; - fh = CreateFile(name, GENERIC_READ | GENERIC_WRITE, + fh = CreateFile(name, + GENERIC_READ | GENERIC_WRITE | DELETE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, - BASEFILEATTRIBUTE | FILE_FLAG_DELETE_ON_CLOSE | - FILE_FLAG_POSIX_SEMANTICS, NULL); + BASEFILEATTRIBUTE | FILE_FLAG_DELETE_ON_CLOSE | FILE_FLAG_POSIX_SEMANTICS, + NULL); if (fh != INVALID_HANDLE_VALUE) CloseHandle(fh); else { @@ -78,14 +79,16 @@ nt_open(char *name, int flags, int mode) { HANDLE fh; DWORD nt_access = 0; - DWORD nt_share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; + DWORD nt_share = FILE_SHARE_READ; DWORD nt_create = 0; /* Really use the sequential one for data files, random for meta data. */ DWORD FandA = BASEFILEATTRIBUTE | FILE_FLAG_SEQUENTIAL_SCAN; /* set access */ - if ((flags & O_RDWR) || (flags & O_WRONLY)) + if ((flags & O_RDWR) || (flags & O_WRONLY)) { nt_access |= GENERIC_WRITE; + nt_share |= FILE_SHARE_WRITE | FILE_SHARE_DELETE; + } if ((flags & O_RDWR) || (flags == O_RDONLY)) nt_access |= GENERIC_READ; -- 2.39.5