diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/include/proto.h | 7 | ||||
-rw-r--r-- | source3/lib/util.c | 148 | ||||
-rw-r--r-- | source3/smbd/open.c | 147 | ||||
-rw-r--r-- | source3/smbd/proto.h | 7 |
4 files changed, 155 insertions, 154 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index 9eff02606d..095c52c7c0 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -607,6 +607,13 @@ bool any_nt_status_not_ok(NTSTATUS err1, NTSTATUS err2, NTSTATUS *result); int timeval_to_msec(struct timeval t); char *valid_share_pathname(TALLOC_CTX *ctx, const char *dos_pathname); 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, + uint32_t *pprivate_flags); /* The following definitions come from lib/util_cmdline.c */ diff --git a/source3/lib/util.c b/source3/lib/util.c index b320931146..689d41ed17 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -29,6 +29,7 @@ #include "../lib/util/util_pw.h" #include "messages.h" #include <ccan/hash/hash.h> +#include "libcli/security/security.h" /* Max allowable allococation - 256mb - 0x10000000 */ #define MAX_ALLOC_SIZE (1024*1024*256) @@ -2255,3 +2256,150 @@ 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_t *pprivate_flags) +{ + uint32 access_mask; + uint32 share_mode; + uint32 create_disposition; + uint32 create_options = FILE_NON_DIRECTORY_FILE; + uint32_t private_flags = 0; + + 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: + private_flags |= 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: + private_flags |= 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 private_flags = 0x%x\n", + smb_base_fname, + (unsigned int)access_mask, + (unsigned int)share_mode, + (unsigned int)create_disposition, + (unsigned int)create_options, + (unsigned int)private_flags)); + + 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; + } + if (pprivate_flags) { + *pprivate_flags = private_flags; + } + + return True; + +} diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 2529cbe0ce..510dfe030c 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -1318,153 +1318,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_t *pprivate_flags) -{ - uint32 access_mask; - uint32 share_mode; - uint32 create_disposition; - uint32 create_options = FILE_NON_DIRECTORY_FILE; - uint32_t private_flags = 0; - - 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: - private_flags |= 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: - private_flags |= 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 private_flags = 0x%x\n", - smb_base_fname, - (unsigned int)access_mask, - (unsigned int)share_mode, - (unsigned int)create_disposition, - (unsigned int)create_options, - (unsigned int)private_flags)); - - 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; - } - if (pprivate_flags) { - *pprivate_flags = private_flags; - } - - return True; - -} - static void schedule_defer_open(struct share_mode_lock *lck, struct timeval request_time, struct smb_request *req) diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 02c82f7d2a..b2acaa0ee7 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -608,13 +608,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, - uint32_t *pprivate_flags); void remove_deferred_open_entry(struct file_id id, uint64_t mid, struct server_id pid); NTSTATUS open_file_fchmod(connection_struct *conn, |