diff options
author | Volker Lendecke <vl@samba.org> | 2012-09-02 20:47:46 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2012-09-04 15:15:00 -0700 |
commit | 63279e374a26e4b855b5089b8d616f199609d8fe (patch) | |
tree | ec7ad353188bfc8ad5223dc2f6319f602be8264c | |
parent | f67a6c463cbe14dfaaeb8a6255cfb587eea1b5a2 (diff) | |
download | samba-63279e374a26e4b855b5089b8d616f199609d8fe.tar.gz samba-63279e374a26e4b855b5089b8d616f199609d8fe.tar.bz2 samba-63279e374a26e4b855b5089b8d616f199609d8fe.zip |
s3: Factor out disposition_to_open_flags
Signed-off-by: Jeremy Allison <jra@samba.org>
-rw-r--r-- | source3/smbd/open.c | 81 |
1 files changed, 57 insertions, 24 deletions
diff --git a/source3/smbd/open.c b/source3/smbd/open.c index e801a7873d..27e0128582 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -1794,6 +1794,59 @@ static bool clear_ads(uint32_t create_disposition) return ret; } +static int disposition_to_open_flags(uint32_t create_disposition) +{ + int ret = 0; + + /* + * Currently we're using FILE_SUPERSEDE as the same as + * FILE_OVERWRITE_IF but they really are + * different. FILE_SUPERSEDE deletes an existing file + * (requiring delete access) then recreates it. + */ + + switch (create_disposition) { + case FILE_SUPERSEDE: + case FILE_OVERWRITE_IF: + /* + * If file exists replace/overwrite. If file doesn't + * exist create. + */ + ret = O_CREAT|O_TRUNC; + break; + + case FILE_OPEN: + /* + * If file exists open. If file doesn't exist error. + */ + ret = 0; + break; + + case FILE_OVERWRITE: + /* + * If file exists overwrite. If file doesn't exist + * error. + */ + ret = O_TRUNC; + break; + + case FILE_CREATE: + /* + * If file exists error. If file doesn't exist create. + */ + ret = O_CREAT|O_EXCL; + break; + + case FILE_OPEN_IF: + /* + * If file exists open. If file doesn't exist create. + */ + ret = O_CREAT; + break; + } + return ret; +} + /**************************************************************************** Open a file with a share mode. Passed in an already created files_struct *. ****************************************************************************/ @@ -1948,24 +2001,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn, } switch( create_disposition ) { - /* - * Currently we're using FILE_SUPERSEDE as the same as - * FILE_OVERWRITE_IF but they really are - * different. FILE_SUPERSEDE deletes an existing file - * (requiring delete access) then recreates it. - */ - case FILE_SUPERSEDE: - /* If file exists replace/overwrite. If file doesn't - * exist create. */ - flags2 = (O_CREAT | O_TRUNC); - break; - - case FILE_OVERWRITE_IF: - /* If file exists replace/overwrite. If file doesn't - * exist create. */ - flags2 = (O_CREAT | O_TRUNC); - break; - case FILE_OPEN: /* If file exists open. If file doesn't exist error. */ if (!file_existed) { @@ -1989,7 +2024,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn, errno = ENOENT; return NT_STATUS_OBJECT_NAME_NOT_FOUND; } - flags2 = O_TRUNC; break; case FILE_CREATE: @@ -2007,19 +2041,18 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn, } return map_nt_error_from_unix(errno); } - flags2 = (O_CREAT|O_EXCL); break; + case FILE_SUPERSEDE: + case FILE_OVERWRITE_IF: case FILE_OPEN_IF: - /* If file exists open. If file doesn't exist - * create. */ - flags2 = O_CREAT; break; - default: return NT_STATUS_INVALID_PARAMETER; } + flags2 = disposition_to_open_flags(create_disposition); + /* We only care about matching attributes on file exists and * overwrite. */ |