From 5e876f697ef6a76925927faf6f77871832c129f0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 29 Jul 2011 15:03:03 -0700 Subject: [PATCH] s3: Make map_open_params_to_ntcreate() available in lib/ (cherry picked from commit aa0c6eb76a6e16652a2ef46560eaffb881792cf6) --- source3/include/proto.h | 12 ++--- source3/lib/util.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ source3/smbd/open.c | 141 ------------------------------------------------ 3 files changed, 147 insertions(+), 147 deletions(-) diff --git a/source3/include/proto.h b/source3/include/proto.h index b62d7b57ef1..c5065e2c173 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -1243,6 +1243,12 @@ bool tevent_req_poll_ntstatus(struct tevent_req *req, struct tevent_context *ev, NTSTATUS *status); bool is_executable(const char *fname); +bool map_open_params_to_ntcreate(const char *smb_base_fname, + int deny_mode, int open_func, + uint32 *paccess_mask, + uint32 *pshare_mode, + uint32 *pcreate_disposition, + uint32 *pcreate_options); /* The following definitions come from lib/util_file.c */ @@ -6628,12 +6634,6 @@ NTSTATUS fcb_or_dos_open(struct smb_request *req, uint32 access_mask, uint32 share_access, uint32 create_options); -bool map_open_params_to_ntcreate(const char *smb_base_fname, - int deny_mode, int open_func, - uint32 *paccess_mask, - uint32 *pshare_mode, - uint32 *pcreate_disposition, - uint32 *pcreate_options); NTSTATUS open_file_fchmod(connection_struct *conn, struct smb_filename *smb_fname, files_struct **result); diff --git a/source3/lib/util.c b/source3/lib/util.c index 343a763f976..c7dfa287304 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -3092,3 +3092,144 @@ bool is_executable(const char *fname) } return False; } + +/**************************************************************************** + Open a file with a share mode - old openX method - map into NTCreate. +****************************************************************************/ + +bool map_open_params_to_ntcreate(const char *smb_base_fname, + int deny_mode, int open_func, + uint32 *paccess_mask, + uint32 *pshare_mode, + uint32 *pcreate_disposition, + uint32 *pcreate_options) +{ + uint32 access_mask; + uint32 share_mode; + uint32 create_disposition; + uint32 create_options = FILE_NON_DIRECTORY_FILE; + + DEBUG(10,("map_open_params_to_ntcreate: fname = %s, deny_mode = 0x%x, " + "open_func = 0x%x\n", + smb_base_fname, (unsigned int)deny_mode, + (unsigned int)open_func )); + + /* Create the NT compatible access_mask. */ + switch (GET_OPENX_MODE(deny_mode)) { + case DOS_OPEN_EXEC: /* Implies read-only - used to be FILE_READ_DATA */ + case DOS_OPEN_RDONLY: + access_mask = FILE_GENERIC_READ; + break; + case DOS_OPEN_WRONLY: + access_mask = FILE_GENERIC_WRITE; + break; + case DOS_OPEN_RDWR: + case DOS_OPEN_FCB: + access_mask = FILE_GENERIC_READ|FILE_GENERIC_WRITE; + break; + default: + DEBUG(10,("map_open_params_to_ntcreate: bad open mode = 0x%x\n", + (unsigned int)GET_OPENX_MODE(deny_mode))); + return False; + } + + /* Create the NT compatible create_disposition. */ + switch (open_func) { + case OPENX_FILE_EXISTS_FAIL|OPENX_FILE_CREATE_IF_NOT_EXIST: + create_disposition = FILE_CREATE; + break; + + case OPENX_FILE_EXISTS_OPEN: + create_disposition = FILE_OPEN; + break; + + case OPENX_FILE_EXISTS_OPEN|OPENX_FILE_CREATE_IF_NOT_EXIST: + create_disposition = FILE_OPEN_IF; + break; + + case OPENX_FILE_EXISTS_TRUNCATE: + create_disposition = FILE_OVERWRITE; + break; + + case OPENX_FILE_EXISTS_TRUNCATE|OPENX_FILE_CREATE_IF_NOT_EXIST: + create_disposition = FILE_OVERWRITE_IF; + break; + + default: + /* From samba4 - to be confirmed. */ + if (GET_OPENX_MODE(deny_mode) == DOS_OPEN_EXEC) { + create_disposition = FILE_CREATE; + break; + } + DEBUG(10,("map_open_params_to_ntcreate: bad " + "open_func 0x%x\n", (unsigned int)open_func)); + return False; + } + + /* Create the NT compatible share modes. */ + switch (GET_DENY_MODE(deny_mode)) { + case DENY_ALL: + share_mode = FILE_SHARE_NONE; + break; + + case DENY_WRITE: + share_mode = FILE_SHARE_READ; + break; + + case DENY_READ: + share_mode = FILE_SHARE_WRITE; + break; + + case DENY_NONE: + share_mode = FILE_SHARE_READ|FILE_SHARE_WRITE; + break; + + case DENY_DOS: + create_options |= NTCREATEX_OPTIONS_PRIVATE_DENY_DOS; + if (is_executable(smb_base_fname)) { + share_mode = FILE_SHARE_READ|FILE_SHARE_WRITE; + } else { + if (GET_OPENX_MODE(deny_mode) == DOS_OPEN_RDONLY) { + share_mode = FILE_SHARE_READ; + } else { + share_mode = FILE_SHARE_NONE; + } + } + break; + + case DENY_FCB: + create_options |= NTCREATEX_OPTIONS_PRIVATE_DENY_FCB; + share_mode = FILE_SHARE_NONE; + break; + + default: + DEBUG(10,("map_open_params_to_ntcreate: bad deny_mode 0x%x\n", + (unsigned int)GET_DENY_MODE(deny_mode) )); + return False; + } + + DEBUG(10,("map_open_params_to_ntcreate: file %s, access_mask = 0x%x, " + "share_mode = 0x%x, create_disposition = 0x%x, " + "create_options = 0x%x\n", + smb_base_fname, + (unsigned int)access_mask, + (unsigned int)share_mode, + (unsigned int)create_disposition, + (unsigned int)create_options )); + + if (paccess_mask) { + *paccess_mask = access_mask; + } + if (pshare_mode) { + *pshare_mode = share_mode; + } + if (pcreate_disposition) { + *pcreate_disposition = create_disposition; + } + if (pcreate_options) { + *pcreate_options = create_options; + } + + return True; + +} diff --git a/source3/smbd/open.c b/source3/smbd/open.c index e0cb944f114..9048d6b74e9 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -1205,147 +1205,6 @@ NTSTATUS fcb_or_dos_open(struct smb_request *req, create_options, fsp_to_dup_into); } -/**************************************************************************** - Open a file with a share mode - old openX method - map into NTCreate. -****************************************************************************/ - -bool map_open_params_to_ntcreate(const char *smb_base_fname, - int deny_mode, int open_func, - uint32 *paccess_mask, - uint32 *pshare_mode, - uint32 *pcreate_disposition, - uint32 *pcreate_options) -{ - uint32 access_mask; - uint32 share_mode; - uint32 create_disposition; - uint32 create_options = FILE_NON_DIRECTORY_FILE; - - DEBUG(10,("map_open_params_to_ntcreate: fname = %s, deny_mode = 0x%x, " - "open_func = 0x%x\n", - smb_base_fname, (unsigned int)deny_mode, - (unsigned int)open_func )); - - /* Create the NT compatible access_mask. */ - switch (GET_OPENX_MODE(deny_mode)) { - case DOS_OPEN_EXEC: /* Implies read-only - used to be FILE_READ_DATA */ - case DOS_OPEN_RDONLY: - access_mask = FILE_GENERIC_READ; - break; - case DOS_OPEN_WRONLY: - access_mask = FILE_GENERIC_WRITE; - break; - case DOS_OPEN_RDWR: - case DOS_OPEN_FCB: - access_mask = FILE_GENERIC_READ|FILE_GENERIC_WRITE; - break; - default: - DEBUG(10,("map_open_params_to_ntcreate: bad open mode = 0x%x\n", - (unsigned int)GET_OPENX_MODE(deny_mode))); - return False; - } - - /* Create the NT compatible create_disposition. */ - switch (open_func) { - case OPENX_FILE_EXISTS_FAIL|OPENX_FILE_CREATE_IF_NOT_EXIST: - create_disposition = FILE_CREATE; - break; - - case OPENX_FILE_EXISTS_OPEN: - create_disposition = FILE_OPEN; - break; - - case OPENX_FILE_EXISTS_OPEN|OPENX_FILE_CREATE_IF_NOT_EXIST: - create_disposition = FILE_OPEN_IF; - break; - - case OPENX_FILE_EXISTS_TRUNCATE: - create_disposition = FILE_OVERWRITE; - break; - - case OPENX_FILE_EXISTS_TRUNCATE|OPENX_FILE_CREATE_IF_NOT_EXIST: - create_disposition = FILE_OVERWRITE_IF; - break; - - default: - /* From samba4 - to be confirmed. */ - if (GET_OPENX_MODE(deny_mode) == DOS_OPEN_EXEC) { - create_disposition = FILE_CREATE; - break; - } - DEBUG(10,("map_open_params_to_ntcreate: bad " - "open_func 0x%x\n", (unsigned int)open_func)); - return False; - } - - /* Create the NT compatible share modes. */ - switch (GET_DENY_MODE(deny_mode)) { - case DENY_ALL: - share_mode = FILE_SHARE_NONE; - break; - - case DENY_WRITE: - share_mode = FILE_SHARE_READ; - break; - - case DENY_READ: - share_mode = FILE_SHARE_WRITE; - break; - - case DENY_NONE: - share_mode = FILE_SHARE_READ|FILE_SHARE_WRITE; - break; - - case DENY_DOS: - create_options |= NTCREATEX_OPTIONS_PRIVATE_DENY_DOS; - if (is_executable(smb_base_fname)) { - share_mode = FILE_SHARE_READ|FILE_SHARE_WRITE; - } else { - if (GET_OPENX_MODE(deny_mode) == DOS_OPEN_RDONLY) { - share_mode = FILE_SHARE_READ; - } else { - share_mode = FILE_SHARE_NONE; - } - } - break; - - case DENY_FCB: - create_options |= NTCREATEX_OPTIONS_PRIVATE_DENY_FCB; - share_mode = FILE_SHARE_NONE; - break; - - default: - DEBUG(10,("map_open_params_to_ntcreate: bad deny_mode 0x%x\n", - (unsigned int)GET_DENY_MODE(deny_mode) )); - return False; - } - - DEBUG(10,("map_open_params_to_ntcreate: file %s, access_mask = 0x%x, " - "share_mode = 0x%x, create_disposition = 0x%x, " - "create_options = 0x%x\n", - smb_base_fname, - (unsigned int)access_mask, - (unsigned int)share_mode, - (unsigned int)create_disposition, - (unsigned int)create_options )); - - if (paccess_mask) { - *paccess_mask = access_mask; - } - if (pshare_mode) { - *pshare_mode = share_mode; - } - if (pcreate_disposition) { - *pcreate_disposition = create_disposition; - } - if (pcreate_options) { - *pcreate_options = create_options; - } - - return True; - -} - static void schedule_defer_open(struct share_mode_lock *lck, struct timeval request_time, struct smb_request *req) -- 2.11.4.GIT