This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
-extern struct generic_mapping file_generic_mapping;
+extern const struct generic_mapping file_generic_mapping;
extern struct current_user current_user;
extern userdom_struct current_user_info;
extern BOOL global_client_failed_oplock_break;
(unsigned int)parent_st.st_uid ));
}
-static void change_dir_owner_to_parent(connection_struct *conn,
+static NTSTATUS change_dir_owner_to_parent(connection_struct *conn,
const char *inherit_from_dir,
const char *fname,
SMB_STRUCT_STAT *psbuf)
{
- pstring saved_dir;
+ char *saved_dir = NULL;
SMB_STRUCT_STAT sbuf;
SMB_STRUCT_STAT parent_st;
+ TALLOC_CTX *ctx = talloc_stackframe();
+ NTSTATUS status = NT_STATUS_OK;
int ret;
ret = SMB_VFS_STAT(conn, inherit_from_dir, &parent_st);
if (ret == -1) {
+ status = map_nt_error_from_unix(errno);
DEBUG(0,("change_dir_owner_to_parent: failed to stat parent "
"directory %s. Error was %s\n",
inherit_from_dir, strerror(errno) ));
- return;
+ TALLOC_FREE(ctx);
+ return status;
}
/* We've already done an lstat into psbuf, and we know it's a
should work on any UNIX (thanks tridge :-). JRA.
*/
- if (!vfs_GetWd(conn,saved_dir)) {
+ saved_dir = vfs_GetWd(ctx,conn);
+ if (!saved_dir) {
+ status = map_nt_error_from_unix(errno);
DEBUG(0,("change_dir_owner_to_parent: failed to get "
- "current working directory\n"));
- return;
+ "current working directory. Error was %s\n",
+ strerror(errno)));
+ TALLOC_FREE(ctx);
+ return status;
}
/* Chdir into the new path. */
if (vfs_ChDir(conn, fname) == -1) {
+ status = map_nt_error_from_unix(errno);
DEBUG(0,("change_dir_owner_to_parent: failed to change "
"current working directory to %s. Error "
"was %s\n", fname, strerror(errno) ));
}
if (SMB_VFS_STAT(conn,".",&sbuf) == -1) {
+ status = map_nt_error_from_unix(errno);
DEBUG(0,("change_dir_owner_to_parent: failed to stat "
"directory '.' (%s) Error was %s\n",
fname, strerror(errno)));
DEBUG(0,("change_dir_owner_to_parent: "
"device/inode/mode on directory %s changed. "
"Refusing to chown !\n", fname ));
+ status = NT_STATUS_ACCESS_DENIED;
goto out;
}
ret = SMB_VFS_CHOWN(conn, ".", parent_st.st_uid, (gid_t)-1);
unbecome_root();
if (ret == -1) {
+ status = map_nt_error_from_unix(errno);
DEBUG(10,("change_dir_owner_to_parent: failed to chown "
"directory %s to parent directory uid %u. "
"Error was %s\n", fname,
out:
+ TALLOC_FREE(ctx);
vfs_ChDir(conn,saved_dir);
+ return status;
}
/****************************************************************************
}
fsp->mode = psbuf->st_mode;
- fsp->file_id = file_id_sbuf(psbuf);
+ fsp->file_id = vfs_file_id_from_sbuf(conn, psbuf);
fsp->vuid = req ? req->vuid : UID_FIELD_INVALID;
fsp->file_pid = req ? req->smbpid : 0;
fsp->can_lock = True;
fsp->sent_oplock_break = NO_BREAK_SENT;
fsp->is_directory = False;
fsp->is_stat = False;
+ if (conn->aio_write_behind_list &&
+ is_in_path(path, 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. */
if (is_deferred_open_entry(share_entry) &&
!open_was_deferred(share_entry->op_mid)) {
- pstring str;
- pstr_sprintf(str, "Got a deferred entry without a request: "
- "PANIC: %s\n", share_mode_str(num, share_entry));
+ char *str = talloc_asprintf(talloc_tos(),
+ "Got a deferred entry without a request: "
+ "PANIC: %s\n",
+ share_mode_str(num, share_entry));
smb_panic(str);
}
panic:
{
- pstring str;
+ char *str;
DEBUG(0,("validate_my_share_entries: PANIC : %s\n",
share_mode_str(num, share_entry) ));
- slprintf(str, sizeof(str)-1, "validate_my_share_entries: "
- "file %s, oplock_type = 0x%x, op_type = 0x%x\n",
+ str = talloc_asprintf(talloc_tos(),
+ "validate_my_share_entries: "
+ "file %s, oplock_type = 0x%x, op_type = 0x%x\n",
fsp->fsp_name, (unsigned int)fsp->oplock_type,
(unsigned int)share_entry->op_type );
smb_panic(str);
static BOOL delay_for_oplocks(struct share_mode_lock *lck,
files_struct *fsp,
+ uint16 mid,
int pass_number,
int oplock_request)
{
DEBUG(10, ("Sending break request to PID %s\n",
procid_str_static(&exclusive->pid)));
- exclusive->op_mid = get_current_mid();
+ exclusive->op_mid = mid;
/* Create the message. */
share_mode_entry_to_message(msg, exclusive);
static void defer_open(struct share_mode_lock *lck,
struct timeval request_time,
struct timeval timeout,
+ struct smb_request *req,
struct deferred_open_record *state)
{
- uint16 mid = get_current_mid();
int i;
/* Paranoia check */
continue;
}
- if (procid_is_me(&e->pid) && (e->op_mid == mid)) {
+ if (procid_is_me(&e->pid) && (e->op_mid == req->mid)) {
DEBUG(0, ("Trying to defer an already deferred "
- "request: mid=%d, exiting\n", mid));
+ "request: mid=%d, exiting\n", req->mid));
exit_server("attempt to defer a deferred request");
}
}
"open entry for mid %u\n",
(unsigned int)request_time.tv_sec,
(unsigned int)request_time.tv_usec,
- (unsigned int)mid));
+ (unsigned int)req->mid));
- if (!push_deferred_smb_message(mid, request_time, timeout,
+ if (!push_deferred_smb_message(req, request_time, timeout,
(char *)state, sizeof(*state))) {
exit_server("push_deferred_smb_message failed");
}
- add_deferred_open(lck, mid, request_time, state->id);
+ add_deferred_open(lck, req->mid, request_time, state->id);
/*
* Push the MID of this packet on the signing queue.
* of incrementing the response sequence number.
*/
- srv_defer_sign_response(mid);
+ srv_defer_sign_response(req->mid);
}
}
-static void schedule_defer_open(struct share_mode_lock *lck, struct timeval request_time)
+static void schedule_defer_open(struct share_mode_lock *lck,
+ struct timeval request_time,
+ struct smb_request *req)
{
struct deferred_open_record state;
state.id = lck->id;
if (!request_timed_out(request_time, timeout)) {
- defer_open(lck, request_time, timeout, &state);
+ defer_open(lck, request_time, timeout, req, &state);
}
}
return print_fsp_open(conn, fname, result);
}
- if (!parent_dirname_talloc(tmp_talloc_ctx(), fname, &parent_dir,
+ if (!parent_dirname_talloc(talloc_tos(), fname, &parent_dir,
&newname)) {
return NT_STATUS_NO_MEMORY;
}
return status;
}
- fsp->file_id = file_id_sbuf(psbuf);
+ fsp->file_id = vfs_file_id_from_sbuf(conn, psbuf);
fsp->share_access = share_access;
fsp->fh->private_options = create_options;
fsp->access_mask = open_access_mask; /* We change this to the
}
if (file_existed) {
- id = file_id_sbuf(psbuf);
+ id = vfs_file_id_from_sbuf(conn, psbuf);
lck = get_share_mode_lock(NULL, id,
conn->connectpath,
}
/* First pass - send break only on batch oplocks. */
- if (delay_for_oplocks(lck, fsp, 1, oplock_request)) {
- schedule_defer_open(lck, request_time);
+ if ((req != NULL)
+ && delay_for_oplocks(lck, fsp, req->mid, 1,
+ oplock_request)) {
+ schedule_defer_open(lck, request_time, req);
TALLOC_FREE(lck);
file_free(fsp);
return NT_STATUS_SHARING_VIOLATION;
* status again. */
/* Second pass - send break for both batch or
* exclusive oplocks. */
- if (delay_for_oplocks(lck, fsp, 2, oplock_request)) {
- schedule_defer_open(lck, request_time);
+ if ((req != NULL)
+ && delay_for_oplocks(lck, fsp, req->mid, 2,
+ oplock_request)) {
+ schedule_defer_open(lck, request_time, req);
TALLOC_FREE(lck);
file_free(fsp);
return NT_STATUS_SHARING_VIOLATION;
state.delayed_for_oplocks = False;
state.id = id;
- if (!request_timed_out(request_time,
- timeout)) {
+ if ((req != NULL)
+ && !request_timed_out(request_time,
+ timeout)) {
defer_open(lck, request_time, timeout,
- &state);
+ req, &state);
}
}
}
/* First pass - send break only on batch oplocks. */
- if (delay_for_oplocks(lck, fsp, 1, oplock_request)) {
- schedule_defer_open(lck, request_time);
+ if ((req != NULL)
+ && delay_for_oplocks(lck, fsp, req->mid, 1,
+ oplock_request)) {
+ schedule_defer_open(lck, request_time, req);
TALLOC_FREE(lck);
fd_close(conn, fsp);
file_free(fsp);
* status again. */
/* Second pass - send break for both batch or
* exclusive oplocks. */
- if (delay_for_oplocks(lck, fsp, 2, oplock_request)) {
- schedule_defer_open(lck, request_time);
+ if ((req != NULL)
+ && delay_for_oplocks(lck, fsp, req->mid, 2,
+ oplock_request)) {
+ schedule_defer_open(lck, request_time, req);
TALLOC_FREE(lck);
fd_close(conn, fsp);
file_free(fsp);
* "goto top of this function", but don't tell
* anybody... */
- defer_open(lck, request_time, timeval_zero(),
- &state);
+ if (req != NULL) {
+ defer_open(lck, request_time, timeval_zero(),
+ req, &state);
+ }
TALLOC_FREE(lck);
return status;
}
char *parent_dir;
const char *dirname;
NTSTATUS status;
+ bool posix_open = false;
if(!CAN_WRITE(conn)) {
DEBUG(5,("mkdir_internal: failing create on read-only share "
return status;
}
- if (!parent_dirname_talloc(tmp_talloc_ctx(), name, &parent_dir,
+ if (!parent_dirname_talloc(talloc_tos(), name, &parent_dir,
&dirname)) {
return NT_STATUS_NO_MEMORY;
}
if (file_attributes & FILE_FLAG_POSIX_SEMANTICS) {
+ posix_open = true;
mode = (mode_t)(file_attributes & ~FILE_FLAG_POSIX_SEMANTICS);
} else {
mode = unix_mode(conn, aDIR, name, parent_dir);
return NT_STATUS_ACCESS_DENIED;
}
+ if (lp_store_dos_attributes(SNUM(conn))) {
+ if (!posix_open) {
+ file_set_dosmode(conn, name,
+ file_attributes | aDIR, NULL,
+ parent_dir);
+ }
+ }
+
if (lp_inherit_perms(SNUM(conn))) {
inherit_access_acl(conn, parent_dir, name, mode);
}
*/
fsp->mode = psbuf->st_mode;
- fsp->file_id = file_id_sbuf(psbuf);
+ fsp->file_id = vfs_file_id_from_sbuf(conn, psbuf);
fsp->vuid = req ? req->vuid : UID_FIELD_INVALID;
fsp->file_pid = req ? req->smbpid : 0;
fsp->can_lock = False;
*/
fsp->mode = psbuf->st_mode;
- fsp->file_id = file_id_sbuf(psbuf);
+ fsp->file_id = vfs_file_id_from_sbuf(conn, psbuf);
fsp->vuid = req ? req->vuid : UID_FIELD_INVALID;
fsp->file_pid = req ? req->smbpid : 0;
fsp->can_lock = False;
DEBUG(10,("msg_file_was_renamed: Got rename message for sharepath %s, new name %s, "
"file_id %s\n",
- sharepath, newname, file_id_static_string(&id)));
+ sharepath, newname, file_id_string_tos(&id)));
for(fsp = file_find_di_first(id); fsp; fsp = file_find_di_next(fsp)) {
if (memcmp(fsp->conn->connectpath, sharepath, sp_len) == 0) {