*/
#include "includes.h"
+#include "smbd/smbd.h"
#include "onefs.h"
#include "onefs_config.h"
#include "oplock_onefs.h"
uint32_t file_attributes,
uint32_t oplock_request,
uint64_t allocation_size,
+ uint32_t private_flags,
struct security_descriptor *sd,
struct ea_list *ea_list,
files_struct **result,
struct security_descriptor *sd,
int *granted_oplock)
{
- char *path = NULL;
struct smb_filename *smb_fname_onefs = NULL;
NTSTATUS status = NT_STATUS_OK;
int accmode = (flags & O_ACCMODE);
fsp->fh->fd = -1;
errno = EPERM;
- status = get_full_smb_filename(talloc_tos(), smb_fname,
- &path);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
-
/* Check permissions */
/*
* wildcard characters are allowed in stream names
* only test the basefilename
*/
- wild = fsp->base_fsp->fsp_name;
+ wild = fsp->base_fsp->fsp_name->base_name;
} else {
- wild = path;
+ wild = smb_fname->base_name;
}
if ((local_flags & O_CREAT) && !file_existed &&
ms_has_wild(wild)) {
/* Inherit the ACL if required */
if (lp_inherit_perms(SNUM(conn))) {
- inherit_access_posix_acl(conn, parent_dir, path,
- unx_mode);
+ inherit_access_posix_acl(conn, parent_dir,
+ smb_fname->base_name, unx_mode);
}
/* Change the owner if required. */
}
notify_fname(conn, NOTIFY_ACTION_ADDED,
- FILE_NOTIFY_CHANGE_FILE_NAME, path);
+ FILE_NOTIFY_CHANGE_FILE_NAME, smb_fname->base_name);
}
if (!file_existed) {
fsp->can_write = (access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) ?
True : False;
}
- fsp->print_file = False;
+ fsp->print_file = NULL;
fsp->modified = False;
fsp->sent_oplock_break = NO_BREAK_SENT;
fsp->is_directory = False;
if (conn->aio_write_behind_list &&
- is_in_path(path, conn->aio_write_behind_list, conn->case_sensitive)) {
+ is_in_path(smb_fname->base_name, conn->aio_write_behind_list,
+ conn->case_sensitive)) {
fsp->aio_write_behind = True;
}
- string_set(&fsp->fsp_name, path);
fsp->wcp = NULL; /* Write cache pointer. */
DEBUG(2,("%s opened file %s read=%s write=%s (numopen=%d)\n",
- conn->server_info->unix_name,
- fsp->fsp_name,
+ conn->session_info->unix_info->unix_name,
+ smb_fname_str_dbg(smb_fname),
BOOLSTR(fsp->can_read), BOOLSTR(fsp->can_write),
conn->num_files_open));
if (procid_is_me(&e->pid) && (e->op_mid == req->mid)) {
DEBUG(0, ("Trying to defer an already deferred "
- "request: mid=%d, exiting\n", req->mid));
+ "request: mid=%llu, exiting\n",
+ (unsigned long long)req->mid));
exit_server("attempt to defer a deferred request");
}
}
/* End paranoia check */
DEBUG(10,("defer_open_sharing_error: time [%u.%06u] adding deferred "
- "open entry for mid %u\n",
+ "open entry for mid %llu\n",
(unsigned int)request_time.tv_sec,
(unsigned int)request_time.tv_usec,
- (unsigned int)req->mid));
+ (unsigned long long)req->mid));
- if (!push_deferred_smb_message(req, request_time, timeout,
- (char *)state, sizeof(*state))) {
- exit_server("push_deferred_smb_message failed");
+ if (!push_deferred_open_message_smb(req, request_time, timeout,
+ state->id, (char *)state, sizeof(*state))) {
+ exit_server("push_deferred_open_message_smb failed");
}
add_deferred_open(lck, req->mid, request_time, state->id);
}
if (!request_timed_out(request_time, timeout)) {
defer_open(lck, request_time, timeout, req, &state);
+ } else {
+ /* A delayed-for-oplocks deferred open timing out should only
+ * happen if there is a bug or extreme load, since we set the
+ * timeout to 300 seconds. */
+ DEBUG(0, ("Deferred open timeout! request_time=%d.%d, "
+ "mid=%d\n", request_time.tv_sec, request_time.tv_usec,
+ req->mid));
}
}
uint32 create_options,
uint32 new_dos_attributes,
int oplock_request,
+ uint32_t private_flags,
struct security_descriptor *sd,
files_struct *fsp,
int *pinfo,
mode_t unx_mode = (mode_t)0;
int info;
uint32 existing_dos_attributes = 0;
- struct pending_message_list *pml = NULL;
struct timeval request_time = timeval_zero();
struct share_mode_lock *lck = NULL;
uint32 open_access_mask = access_mask;
int granted_oplock;
uint64_t oplock_callback_id = 0;
uint32 createfile_attributes = 0;
- char *fname = NULL;
ZERO_STRUCT(id);
- status = get_full_smb_filename(talloc_tos(), smb_fname,
- &fname);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
-
if (conn->printer) {
/*
* Printers are handled completely differently.
DEBUG(10, ("onefs_open_file_ntcreate: printer open fname=%s\n",
smb_fname_str_dbg(smb_fname)));
- return print_fsp_open(req, conn, fname, req->vuid, fsp,
- &smb_fname->st);
+ return print_spool_open(fsp, smb_fname->base_name,
+ req->vuid);
}
if (!parent_dirname(talloc_tos(), smb_fname->base_name, &parent_dir,
unx_mode = (mode_t)(new_dos_attributes & ~FILE_FLAG_POSIX_SEMANTICS);
new_dos_attributes = 0;
} else {
- /* We add aARCH to this as this mode is only used if the file is
+ /* We add FILE_ATTRIBUTE_ARCHIVE to this as this mode is only used if the file is
* created new. */
- unx_mode = unix_mode(conn, new_dos_attributes | aARCH,
+ unx_mode = unix_mode(conn, new_dos_attributes | FILE_ATTRIBUTE_ARCHIVE,
smb_fname, parent_dir);
}
* Only non-internal opens can be deferred at all
*/
- if ((req != NULL)
- && ((pml = get_open_deferred_message(req->mid)) != NULL)) {
- struct deferred_open_record *state =
- (struct deferred_open_record *)pml->private_data.data;
+ if (req) {
+ void *ptr;
+ if (get_deferred_open_message_state(req,
+ &request_time,
+ &ptr)) {
+ struct deferred_open_record *state = (struct deferred_open_record *)ptr;
- /* Remember the absolute time of the original
- request with this mid. We'll use it later to
- see if this has timed out. */
+ /* Remember the absolute time of the original
+ request with this mid. We'll use it later to
+ see if this has timed out. */
- request_time = pml->request_time;
+ /* Remove the deferred open entry under lock. */
+ remove_deferred_open_entry(state->id, req->mid);
- /* Remove the deferred open entry under lock. */
- lck = get_share_mode_lock(talloc_tos(), state->id, NULL, NULL,
- NULL);
- if (lck == NULL) {
- DEBUG(0, ("could not get share mode lock\n"));
- } else {
- del_deferred_open_entry(lck, req->mid);
- TALLOC_FREE(lck);
- }
+ /* Ensure we don't reprocess this message. */
+ remove_deferred_open_message_smb(req->mid);
- /* Ensure we don't reprocess this message. */
- remove_deferred_open_smb_message(req->mid);
-
- /*
- * When receiving a semlock_async_failure message, the
- * deferred open will be marked as "failed". Returning
- * INTERNAL_ERROR.
- */
- if (state->failed) {
- DEBUG(0, ("onefs_open_file_ntcreate: "
- "semlock_async_failure detected!\n"));
- return NT_STATUS_INTERNAL_ERROR;
+ /*
+ * When receiving a semlock_async_failure message, the
+ * deferred open will be marked as "failed". Returning
+ * INTERNAL_ERROR.
+ */
+ if (state->failed) {
+ DEBUG(0, ("onefs_open_file_ntcreate: "
+ "semlock_async_failure detected!\n"));
+ return NT_STATUS_INTERNAL_ERROR;
+ }
}
}
/* Setup dos_attributes to be set by ifs_createfile */
if (lp_store_dos_attributes(SNUM(conn))) {
- createfile_attributes = (new_dos_attributes | aARCH) &
+ createfile_attributes = (new_dos_attributes | FILE_ATTRIBUTE_ARCHIVE) &
~(FILE_ATTRIBUTE_NONINDEXED | FILE_ATTRIBUTE_COMPRESSED);
}
/* Ignore oplock requests if oplocks are disabled. */
- if (!lp_oplocks(SNUM(conn)) || global_client_failed_oplock_break ||
+ if (!lp_oplocks(SNUM(conn)) ||
IS_VETO_OPLOCK_PATH(conn, smb_fname->base_name)) {
/* Mask off everything except the private Samba bits. */
oplock_request &= SAMBA_PRIVATE_OPLOCK_MASK;
DEBUG(10, ("fsp = %p\n", fsp));
- fsp->file_id = vfs_file_id_from_sbuf(conn, &smb_fname->st);
fsp->share_access = share_access;
- fsp->fh->private_options = create_options;
+ fsp->fh->private_options = private_flags;
fsp->access_mask = open_access_mask; /* We change this to the
* requested access_mask after
* the open is done. */
lck = get_share_mode_lock(talloc_tos(), id,
conn->connectpath,
- fname, &old_write_time);
+ smb_fname, &old_write_time);
if (lck == NULL) {
DEBUG(0, ("Could not get share mode lock\n"));
* stat-only open at this point.
*/
SMB_ASSERT(fsp->oplock_type == NO_OPLOCK);
+
+ /* The kernel and Samba's version of stat-only differs
+ * slightly: The kernel doesn't think its stat-only if we're
+ * truncating. We'd better have a req in order to defer the
+ * open. */
+ SMB_ASSERT(!((flags|flags2) & O_TRUNC));
}
/* Do the open. */
/* OneFS Oplock Handling */
if (errno == EINPROGRESS) {
+ /* If we get EINPROGRESS, the kernel will send us an
+ * asynchronous semlock event back. Ensure we can defer
+ * the open, by asserting req. */
+ SMB_ASSERT(req);
+
if (lck == NULL) {
+ /*
+ * We hit the race that when we did the stat
+ * on the file it did not exist, and someone
+ * has created it in between the stat and the
+ * open_file() call. Defer our open waiting,
+ * to break the oplock of the first opener.
+ */
- struct deferred_open_record state;
struct timespec old_write_time;
- old_write_time = smb_fname->st.st_ex_mtime;
-
DEBUG(3, ("Someone created file %s with an "
"oplock after we looked: Retrying\n",
smb_fname_str_dbg(smb_fname)));
id = vfs_file_id_from_sbuf(conn,
&smb_fname->st);
if (!(lck = get_share_mode_lock(talloc_tos(),
- id, conn->connectpath, fname,
+ id, conn->connectpath, smb_fname,
&old_write_time))) {
/*
* Emergency exit
"lock for %s\n",
smb_fname_str_dbg(smb_fname)));
status = NT_STATUS_SHARING_VIOLATION;
+
+ /* XXXZLK: This will cause us to get a
+ * semlock event when we aren't
+ * expecting one. */
goto cleanup_destroy;
}
- state.delayed_for_oplocks = False;
- state.id = id;
-
- if (req != NULL) {
- defer_open(lck, request_time,
- timeval_zero(), req, &state);
- }
- goto cleanup_destroy;
+ schedule_defer_open(lck, request_time, req);
+ goto cleanup;
}
/* Waiting for an oplock */
DEBUG(5,("Async createfile because a client has an "
uint32 can_access_mask;
bool can_access = True;
+ /* If we raced on open we may not have a valid file_id
+ * or stat buf. Get them again. */
+ if (SMB_VFS_STAT(conn, fname, psbuf) == -1) {
+ DEBUG(0,("Error doing stat on file %s "
+ "(%s)\n", fname, strerror(errno)));
+ status = NT_STATUS_SHARING_VIOLATION;
+ goto cleanup_destroy;
+ }
+ id = vfs_file_id_from_sbuf(conn, psbuf);
+
/* Check if this can be done with the deny_dos and fcb
* calls. */
/* Try to find dup fsp if possible. */
- if (create_options &
+ if (private_flags &
(NTCREATEX_OPTIONS_PRIVATE_DENY_DOS|
NTCREATEX_OPTIONS_PRIVATE_DENY_FCB)) {
status = fcb_or_dos_open(req,
conn,
fsp,
- fname,
+ smb_fname,
id,
req->smbpid,
req->vuid,
if (((can_access_mask & FILE_WRITE_DATA) &&
!CAN_WRITE(conn)) ||
- !can_access_file_data(conn, smb_fname,
- can_access_mask)) {
+ !NT_STATUS_IS_OK(smbd_check_access_rights(conn,
+ smb_fname, can_access_mask))) {
can_access = False;
}
state.id = id;
state.failed = false;
- if ((req != NULL)
- && !request_timed_out(request_time,
- timeout)) {
+ /*
+ * We hit the race that when we did the stat
+ * on the file it did not exist, and someone
+ * has created it in between the stat and the
+ * open_file() call. Retrieve the share_mode
+ * lock on the newly opened file so we can
+ * defer our request.
+ */
+ if (lck == NULL) {
+ struct timespec old_write_time;
+ old_write_time = get_mtimespec(psbuf);
+
+ lck = get_share_mode_lock(talloc_tos(),
+ id, conn->connectpath, fname,
+ &old_write_time);
+ if (lck == NULL) {
+ DEBUG(0,
+ ("onefs_open_file_ntcreate:"
+ " Could not get share "
+ "mode lock for %s\n",
+ fname));
+ /* This will cause us to return
+ * immediately skipping the
+ * the 1 second delay, which
+ * isn't a big deal */
+ status = NT_STATUS_SHARING_VIOLATION;
+ goto cleanup_destroy;
+ }
+ }
+
+ if ((req != NULL) &&
+ !request_timed_out(request_time, timeout))
+ {
defer_open(lck, request_time, timeout,
req, &state);
}
/*
* Now the file exists and fsp is successfully opened,
- * fsp->dev and fsp->inode are valid and should replace the
- * dev=0,inode=0 from a non existent file. Spotted by
+ * fsp->file_id is valid and should replace the
+ * dev=0, inode=0 from a non existent file. Spotted by
* Nadav Danieli <nadavd@exanet.com>. JRA.
*/
lck = get_share_mode_lock(talloc_tos(), id,
conn->connectpath,
- fname, &old_write_time);
+ smb_fname, &old_write_time);
if (lck == NULL) {
DEBUG(0, ("onefs_open_file_ntcreate: Could not get "
note that GPFS supports it as well - jmcd */
if (fsp->fh->fd != -1) {
- ret_flock = SMB_VFS_KERNEL_FLOCK(fsp, share_access);
+ ret_flock = SMB_VFS_KERNEL_FLOCK(fsp, share_access, access_mask);
if(ret_flock == -1 ){
TALLOC_FREE(lck);
* deny mode is compatible with all current opens.
*/
- /* Record the options we were opened with. */
- fsp->share_access = share_access;
- fsp->fh->private_options = create_options;
/*
* According to Samba4, SEC_FILE_READ_ATTRIBUTE is always granted,
*/
new_file_created = True;
}
- set_share_mode(lck, fsp, conn->server_info->utok.uid, 0,
+ set_share_mode(lck, fsp, get_current_uid(conn),
+ req ? req->mid : 0,
fsp->oplock_type);
/* Handle strange delete on close create semantics. */
if (create_options & FILE_DELETE_ON_CLOSE) {
- status = can_set_delete_on_close(fsp, True, new_dos_attributes);
+ status = can_set_delete_on_close(fsp, new_dos_attributes);
if (!NT_STATUS_IS_OK(status)) {
/* Remember to delete the mode we just added. */
mode = (mode_t)(file_attributes & ~FILE_FLAG_POSIX_SEMANTICS);
file_attributes = 0;
} else {
- mode = unix_mode(conn, aDIR, smb_dname, parent_dir);
+ mode = unix_mode(conn, FILE_ATTRIBUTE_DIRECTORY, smb_dname, parent_dir);
}
/*
fsp->can_write = False;
fsp->share_access = share_access;
- fsp->fh->private_options = create_options;
+ fsp->fh->private_options = 0;
/*
* According to Samba4, SEC_FILE_READ_ATTRIBUTE is always granted,
*/
fsp->access_mask = access_mask | FILE_READ_ATTRIBUTES;
- fsp->print_file = False;
+ fsp->print_file = NULL;
fsp->modified = False;
fsp->oplock_type = NO_OPLOCK;
fsp->sent_oplock_break = NO_BREAK_SENT;
fsp->is_directory = True;
fsp->posix_open = posix_open;
- string_set(&fsp->fsp_name, smb_dname->base_name);
+ status = fsp_set_smb_fname(fsp, smb_dname);
+ if (!NT_STATUS_IS_OK(status)) {
+ fd_close(fsp);
+ file_free(req, fsp);
+ return status;
+ }
mtimespec = smb_dname->st.st_ex_mtime;
* semantics and to make smbstatus more useful.
*/
lck = get_share_mode_lock(talloc_tos(), fsp->file_id,
- conn->connectpath, smb_dname->base_name,
- &mtimespec);
+ conn->connectpath, smb_dname, &mtimespec);
if (lck == NULL) {
DEBUG(0, ("onefs_open_directory: Could not get share mode "
return NT_STATUS_DELETE_PENDING;
}
- set_share_mode(lck, fsp, conn->server_info->utok.uid, 0, NO_OPLOCK);
+ set_share_mode(lck, fsp, get_current_uid(conn),
+ req ? req->mid : 0, NO_OPLOCK);
/*
* For directories the delete on close bit at open time seems
* always to be honored on close... See test 19 in Samba4 BASE-DELETE.
*/
if (create_options & FILE_DELETE_ON_CLOSE) {
- status = can_set_delete_on_close(fsp, True, 0);
+ status = can_set_delete_on_close(fsp, 0);
if (!NT_STATUS_IS_OK(status) &&
!NT_STATUS_EQUAL(status, NT_STATUS_DIRECTORY_NOT_EMPTY)) {
TALLOC_FREE(lck);
uint32_t file_attributes,
uint32_t oplock_request,
uint64_t allocation_size,
+ uint32_t private_flags,
struct security_descriptor *sd,
struct ea_list *ea_list,
files_struct **result,
DEBUG(10,("onefs_create_file_unixpath: access_mask = 0x%x "
"file_attributes = 0x%x, share_access = 0x%x, "
"create_disposition = 0x%x create_options = 0x%x "
- "oplock_request = 0x%x ea_list = 0x%p, sd = 0x%p, "
+ "oplock_request = 0x%x private_flags = 0x%x "
+ "ea_list = 0x%p, sd = 0x%p, "
"fname = %s\n",
(unsigned int)access_mask,
(unsigned int)file_attributes,
(unsigned int)create_disposition,
(unsigned int)create_options,
(unsigned int)oplock_request,
+ (unsigned int)private_flags,
ea_list, sd, smb_fname_str_dbg(smb_fname)));
if (create_options & FILE_OPEN_BY_FILE_ID) {
file_attributes, /* file_attributes */
NO_OPLOCK, /* oplock_request */
0, /* allocation_size */
+ 0, /* private_flags */
NULL, /* sd */
NULL, /* ea_list */
&base_fsp, /* result */
uint32_t file_attributes,
uint32_t oplock_request,
uint64_t allocation_size,
+ uint32_t private_flags,
struct security_descriptor *sd,
struct ea_list *ea_list,
files_struct **result,
DEBUG(10,("onefs_create_file: access_mask = 0x%x "
"file_attributes = 0x%x, share_access = 0x%x, "
"create_disposition = 0x%x create_options = 0x%x "
- "oplock_request = 0x%x "
+ "oplock_request = 0x%x private_flags = 0x%x"
"root_dir_fid = 0x%x, ea_list = 0x%p, sd = 0x%p, "
"fname = %s\n",
(unsigned int)access_mask,
(unsigned int)create_disposition,
(unsigned int)create_options,
(unsigned int)oplock_request,
+ (unsigned int)private_flags,
(unsigned int)root_dir_fid,
ea_list, sd, smb_fname_str_dbg(smb_fname)));
/* Get the file name if root_dir_fid was specified. */
if (root_dir_fid != 0) {
+ struct smb_filename *smb_fname_out = NULL;
status = get_relative_fid_filename(conn, req, root_dir_fid,
- smb_fname);
+ smb_fname, &smb_fname_out);
if (!NT_STATUS_IS_OK(status)) {
goto fail;
}
+ smb_fname = smb_fname_out;
}
/* All file access must go through check_name() */
goto fail;
}
+ if (is_ntfs_stream_smb_fname(smb_fname)) {
+ if (!(conn->fs_capabilities & FILE_NAMED_STREAMS)) {
+ status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ goto fail;
+ }
+
+ if (is_ntfs_default_stream_smb_fname(smb_fname)) {
+ int ret;
+ smb_fname->stream_name = NULL;
+ /* We have to handle this error here. */
+ if (create_options & FILE_DIRECTORY_FILE) {
+ status = NT_STATUS_NOT_A_DIRECTORY;
+ goto fail;
+ }
+ if (lp_posix_pathnames()) {
+ ret = SMB_VFS_LSTAT(conn, smb_fname);
+ } else {
+ ret = SMB_VFS_STAT(conn, smb_fname);
+ }
+
+ if (ret == 0 && VALID_STAT_OF_DIR(smb_fname->st)) {
+ status = NT_STATUS_FILE_IS_A_DIRECTORY;
+ goto fail;
+ }
+ }
+ }
+
status = onefs_create_file_unixpath(
conn, /* conn */
req, /* req */
file_attributes, /* file_attributes */
oplock_request, /* oplock_request */
allocation_size, /* allocation_size */
+ private_flags,
sd, /* sd */
ea_list, /* ea_list */
&fsp, /* result */