summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/blocking.c10
-rw-r--r--source3/smbd/close.c44
-rw-r--r--source3/smbd/connection.c2
-rw-r--r--source3/smbd/nttrans.c8
-rw-r--r--source3/smbd/open.c18
-rw-r--r--source3/smbd/oplock.c6
-rw-r--r--source3/smbd/process.c2
-rw-r--r--source3/smbd/reply.c12
-rw-r--r--source3/smbd/sec_ctx.c17
-rw-r--r--source3/smbd/server.c14
-rw-r--r--source3/smbd/service.c8
-rw-r--r--source3/smbd/trans2.c27
-rw-r--r--source3/smbd/vfs.c42
13 files changed, 103 insertions, 107 deletions
diff --git a/source3/smbd/blocking.c b/source3/smbd/blocking.c
index 4e0d5289f8..479361a8c1 100644
--- a/source3/smbd/blocking.c
+++ b/source3/smbd/blocking.c
@@ -625,7 +625,7 @@ void remove_pending_lock_requests_by_mid(int mid)
next = blr->next;
if(SVAL(blr->inbuf,smb_mid) == mid) {
files_struct *fsp = blr->fsp;
- struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+ struct byte_range_lock *br_lck = brl_get_locks(talloc_tos(), fsp);
if (br_lck) {
DEBUG(10,("remove_pending_lock_requests_by_mid - removing request type %d for \
@@ -715,7 +715,7 @@ static void process_blocking_lock_queue(void)
fsp->fnum, fsp->fsp_name ));
if(!change_to_user(conn,vuid)) {
- struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+ struct byte_range_lock *br_lck = brl_get_locks(talloc_tos(), fsp);
/*
* Remove the entry and return an error to the client.
@@ -741,7 +741,7 @@ static void process_blocking_lock_queue(void)
}
if(!set_current_service(conn,SVAL(blr->inbuf,smb_flg),True)) {
- struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+ struct byte_range_lock *br_lck = brl_get_locks(talloc_tos(), fsp);
/*
* Remove the entry and return an error to the client.
@@ -773,7 +773,7 @@ static void process_blocking_lock_queue(void)
*/
if(blocking_lock_record_process(blr)) {
- struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+ struct byte_range_lock *br_lck = brl_get_locks(talloc_tos(), fsp);
if (br_lck) {
brl_lock_cancel(br_lck,
@@ -800,7 +800,7 @@ static void process_blocking_lock_queue(void)
*/
if (!timeval_is_zero(&blr->expire_time) && timeval_compare(&blr->expire_time, &tv_curr) <= 0) {
- struct byte_range_lock *br_lck = brl_get_locks(NULL, fsp);
+ struct byte_range_lock *br_lck = brl_get_locks(talloc_tos(), fsp);
/*
* Lock expired - throw away all previously
diff --git a/source3/smbd/close.c b/source3/smbd/close.c
index 5d30e467d0..4c385d7611 100644
--- a/source3/smbd/close.c
+++ b/source3/smbd/close.c
@@ -163,7 +163,8 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
enum file_close_type close_type)
{
connection_struct *conn = fsp->conn;
- bool delete_file = False;
+ bool delete_file = false;
+ bool changed_user = false;
struct share_mode_lock *lck;
SMB_STRUCT_STAT sbuf;
NTSTATUS status = NT_STATUS_OK;
@@ -176,7 +177,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
* This prevents race conditions with the file being created. JRA.
*/
- lck = get_share_mode_lock(NULL, fsp->file_id, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL);
if (lck == NULL) {
DEBUG(0, ("close_remove_share_mode: Could not get share mode "
@@ -246,18 +247,27 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
DEBUG(5,("close_remove_share_mode: file %s. Delete on close was set "
"- deleting file.\n", fsp->fsp_name));
- /* Become the user who requested the delete. */
+ if (!unix_token_equal(lck->delete_token, &current_user.ut)) {
+ /* Become the user who requested the delete. */
- if (!push_sec_ctx()) {
- smb_panic("close_remove_share_mode: file %s. failed to push "
- "sec_ctx.\n");
- }
+ DEBUG(5,("close_remove_share_mode: file %s. "
+ "Change user to uid %u\n",
+ fsp->fsp_name,
+ (unsigned int)lck->delete_token->uid));
- set_sec_ctx(lck->delete_token->uid,
- lck->delete_token->gid,
- lck->delete_token->ngroups,
- lck->delete_token->groups,
- NULL);
+ if (!push_sec_ctx()) {
+ smb_panic("close_remove_share_mode: file %s. failed to push "
+ "sec_ctx.\n");
+ }
+
+ set_sec_ctx(lck->delete_token->uid,
+ lck->delete_token->gid,
+ lck->delete_token->ngroups,
+ lck->delete_token->groups,
+ NULL);
+
+ changed_user = true;
+ }
/* We can only delete the file if the name we have is still valid and
hasn't been renamed. */
@@ -326,9 +336,11 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
done:
- /* unbecome user. */
- pop_sec_ctx();
-
+ if (changed_user) {
+ /* unbecome user. */
+ pop_sec_ctx();
+ }
+
TALLOC_FREE(lck);
return status;
}
@@ -441,7 +453,7 @@ static NTSTATUS close_directory(files_struct *fsp, enum file_close_type close_ty
* reference to a directory also.
*/
- lck = get_share_mode_lock(NULL, fsp->file_id, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL);
if (lck == NULL) {
DEBUG(0, ("close_directory: Could not get share mode lock for %s\n", fsp->fsp_name));
diff --git a/source3/smbd/connection.c b/source3/smbd/connection.c
index 95e45a6990..016c8adb1b 100644
--- a/source3/smbd/connection.c
+++ b/source3/smbd/connection.c
@@ -132,7 +132,7 @@ bool claim_connection(connection_struct *conn, const char *name,
DEBUG(5,("claiming [%s]\n", name));
- if (!(rec = connections_fetch_entry(NULL, conn, name))) {
+ if (!(rec = connections_fetch_entry(talloc_tos(), conn, name))) {
DEBUG(0, ("connections_fetch_entry failed\n"));
return False;
}
diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c
index ae64c06215..e8df732ea2 100644
--- a/source3/smbd/nttrans.c
+++ b/source3/smbd/nttrans.c
@@ -1604,7 +1604,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
SEC_DESC *psd = NULL;
size_t sd_size;
uint32 security_info_wanted;
- TALLOC_CTX *frame;
files_struct *fsp = NULL;
NTSTATUS status;
DATA_BLOB blob;
@@ -1631,8 +1630,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
return;
}
- frame = talloc_stackframe();
-
/*
* Get the permissions to return.
*/
@@ -1651,7 +1648,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
}
if (!NT_STATUS_IS_OK(status)) {
- TALLOC_FREE(frame);
reply_nterror(req, status);
return;
}
@@ -1665,7 +1661,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
if (max_data_count < sd_size) {
send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
params, 4, *ppdata, 0);
- TALLOC_FREE(frame);
return;
}
@@ -1675,7 +1670,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
data = nttrans_realloc(ppdata, sd_size);
if(data == NULL) {
- TALLOC_FREE(frame);
reply_doserror(req, ERRDOS, ERRnomem);
return;
}
@@ -1684,7 +1678,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
&blob.data, &blob.length);
if (!NT_STATUS_IS_OK(status)) {
- TALLOC_FREE(frame);
reply_nterror(req, status);
return;
}
@@ -1694,7 +1687,6 @@ static void call_nt_transact_query_security_desc(connection_struct *conn,
send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
- TALLOC_FREE(frame);
return;
}
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 4abe017380..59699dfbd0 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -125,7 +125,7 @@ static NTSTATUS change_dir_owner_to_parent(connection_struct *conn,
char *saved_dir = NULL;
SMB_STRUCT_STAT sbuf;
SMB_STRUCT_STAT parent_st;
- TALLOC_CTX *ctx = talloc_stackframe();
+ TALLOC_CTX *ctx = talloc_tos();
NTSTATUS status = NT_STATUS_OK;
int ret;
@@ -135,7 +135,6 @@ static NTSTATUS change_dir_owner_to_parent(connection_struct *conn,
DEBUG(0,("change_dir_owner_to_parent: failed to stat parent "
"directory %s. Error was %s\n",
inherit_from_dir, strerror(errno) ));
- TALLOC_FREE(ctx);
return status;
}
@@ -152,7 +151,6 @@ static NTSTATUS change_dir_owner_to_parent(connection_struct *conn,
DEBUG(0,("change_dir_owner_to_parent: failed to get "
"current working directory. Error was %s\n",
strerror(errno)));
- TALLOC_FREE(ctx);
return status;
}
@@ -202,7 +200,6 @@ static NTSTATUS change_dir_owner_to_parent(connection_struct *conn,
out:
- TALLOC_FREE(ctx);
vfs_ChDir(conn,saved_dir);
return status;
}
@@ -1224,7 +1221,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
request_time = pml->request_time;
/* Remove the deferred open entry under lock. */
- lck = get_share_mode_lock(NULL, state->id, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), state->id, NULL, NULL);
if (lck == NULL) {
DEBUG(0, ("could not get share mode lock\n"));
} else {
@@ -1454,7 +1451,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
if (file_existed) {
id = vfs_file_id_from_sbuf(conn, psbuf);
- lck = get_share_mode_lock(NULL, id,
+ lck = get_share_mode_lock(talloc_tos(), id,
conn->connectpath,
fname);
@@ -1681,7 +1678,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
id = fsp->file_id;
- lck = get_share_mode_lock(NULL, id,
+ lck = get_share_mode_lock(talloc_tos(), id,
conn->connectpath,
fname);
@@ -2215,7 +2212,7 @@ NTSTATUS open_directory(connection_struct *conn,
string_set(&fsp->fsp_name,fname);
- lck = get_share_mode_lock(NULL, fsp->file_id,
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id,
conn->connectpath,
fname);
@@ -2707,7 +2704,6 @@ NTSTATUS create_file(connection_struct *conn,
int *pinfo,
SMB_STRUCT_STAT *psbuf)
{
- TALLOC_CTX *frame = talloc_stackframe();
struct case_semantics_state *case_state = NULL;
SMB_STRUCT_STAT sbuf;
int info = FILE_WAS_OPENED;
@@ -2845,6 +2841,8 @@ NTSTATUS create_file(connection_struct *conn,
goto fail;
}
+ SET_STAT_INVALID(sbuf);
+
goto done;
}
}
@@ -2916,7 +2914,6 @@ NTSTATUS create_file(connection_struct *conn,
if (psbuf != NULL) {
*psbuf = sbuf;
}
- TALLOC_FREE(frame);
return NT_STATUS_OK;
fail:
@@ -2926,6 +2923,5 @@ NTSTATUS create_file(connection_struct *conn,
close_file(fsp, ERROR_CLOSE);
fsp = NULL;
}
- TALLOC_FREE(frame);
return status;
}
diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index 277e07c178..420aa94fe6 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -181,7 +181,7 @@ bool remove_oplock(files_struct *fsp)
struct share_mode_lock *lck;
/* Remove the oplock flag from the sharemode. */
- lck = get_share_mode_lock(NULL, fsp->file_id, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL);
if (lck == NULL) {
DEBUG(0,("remove_oplock: failed to lock share entry for "
"file %s\n", fsp->fsp_name ));
@@ -206,7 +206,7 @@ bool downgrade_oplock(files_struct *fsp)
bool ret;
struct share_mode_lock *lck;
- lck = get_share_mode_lock(NULL, fsp->file_id, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL);
if (lck == NULL) {
DEBUG(0,("downgrade_oplock: failed to lock share entry for "
"file %s\n", fsp->fsp_name ));
@@ -757,7 +757,7 @@ void release_level_2_oplocks_on_change(files_struct *fsp)
if (!LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
return;
- lck = get_share_mode_lock(NULL, fsp->file_id, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL);
if (lck == NULL) {
DEBUG(0,("release_level_2_oplocks_on_change: failed to lock "
"share mode entry for file %s.\n", fsp->fsp_name ));
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index fe32d57ff7..2d3cf7fbd8 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -2071,7 +2071,7 @@ void smbd_process(void)
char *inbuf;
size_t inbuf_len;
bool encrypted = false;
- TALLOC_CTX *frame = talloc_stackframe();
+ TALLOC_CTX *frame = talloc_stackframe_pool(8192);
errno = 0;
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index a796a3193b..8149f5aeb6 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -592,7 +592,8 @@ void reply_tcon_and_X(struct smb_request *req)
}
if (global_encrypted_passwords_negotiated) {
- password = data_blob(smb_buf(req->inbuf),passlen);
+ password = data_blob_talloc(talloc_tos(), smb_buf(req->inbuf),
+ passlen);
if (lp_security() == SEC_SHARE) {
/*
* Security = share always has a pad byte
@@ -603,7 +604,8 @@ void reply_tcon_and_X(struct smb_request *req)
p = smb_buf(req->inbuf) + passlen;
}
} else {
- password = data_blob(smb_buf(req->inbuf),passlen+1);
+ password = data_blob_talloc(talloc_tos(), smb_buf(req->inbuf),
+ passlen+1);
/* Ensure correct termination */
password.data[passlen]=0;
p = smb_buf(req->inbuf) + passlen + 1;
@@ -2652,7 +2654,7 @@ void send_file_readbraw(connection_struct *conn,
_smb_setlen(header,nread);
header_blob = data_blob_const(header, 4);
- if ( SMB_VFS_SENDFILE( smbd_server_fd(), fsp, fsp->fh->fd,
+ if (SMB_VFS_SENDFILE(smbd_server_fd(), fsp,
&header_blob, startpos, nread) == -1) {
/* Returning ENOSYS means no data at all was sent.
* Do this as a normal read. */
@@ -3135,7 +3137,7 @@ static void send_file_readX(connection_struct *conn, struct smb_request *req,
construct_reply_common((char *)req->inbuf, (char *)headerbuf);
setup_readX_header((char *)headerbuf, smb_maxcnt);
- if ((nread = SMB_VFS_SENDFILE( smbd_server_fd(), fsp, fsp->fh->fd, &header, startpos, smb_maxcnt)) == -1) {
+ if ((nread = SMB_VFS_SENDFILE(smbd_server_fd(), fsp, &header, startpos, smb_maxcnt)) == -1) {
/* Returning ENOSYS means no data at all was sent. Do this as a normal read. */
if (errno == ENOSYS) {
goto normal_read;
@@ -5508,7 +5510,7 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
return NT_STATUS_ACCESS_DENIED;
}
- lck = get_share_mode_lock(NULL, fsp->file_id, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL);
/*
* We have the file open ourselves, so not being able to get the
diff --git a/source3/smbd/sec_ctx.c b/source3/smbd/sec_ctx.c
index 6edcc36764..0f307f6a64 100644
--- a/source3/smbd/sec_ctx.c
+++ b/source3/smbd/sec_ctx.c
@@ -33,6 +33,23 @@ static struct sec_ctx sec_ctx_stack[MAX_SEC_CTX_DEPTH + 1];
static int sec_ctx_stack_ndx;
/****************************************************************************
+ Are two UNIX tokens equal ?
+****************************************************************************/
+
+bool unix_token_equal(const UNIX_USER_TOKEN *t1, const UNIX_USER_TOKEN *t2)
+{
+ if (t1->uid != t2->uid || t1->gid != t2->gid ||
+ t1->ngroups != t2->ngroups) {
+ return false;
+ }
+ if (memcmp(t1->groups, t2->groups,
+ t1->ngroups*sizeof(gid_t)) != 0) {
+ return false;
+ }
+ return true;
+}
+
+/****************************************************************************
Become the specified uid.
****************************************************************************/
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 43a6d62a28..8371d17f10 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -390,8 +390,11 @@ static bool open_sockets_smbd(bool is_daemon, bool interactive, const char *smb_
}
s = fd_listenset[num_sockets] =
- open_socket_in(SOCK_STREAM, port, 0,
- ifss, True);
+ open_socket_in(SOCK_STREAM,
+ port,
+ num_sockets == 0 ? 0 : 2,
+ ifss,
+ true);
if(s == -1) {
continue;
}
@@ -467,8 +470,11 @@ static bool open_sockets_smbd(bool is_daemon, bool interactive, const char *smb_
continue;
}
- s = open_socket_in(SOCK_STREAM, port, 0,
- &ss, true);
+ s = open_socket_in(SOCK_STREAM,
+ port,
+ num_sockets == 0 ? 0 : 2,
+ &ss,
+ true);
if (s == -1) {
continue;
}
diff --git a/source3/smbd/service.c b/source3/smbd/service.c
index 65fc818144..2588a66b8b 100644
--- a/source3/smbd/service.c
+++ b/source3/smbd/service.c
@@ -357,7 +357,6 @@ void load_registry_shares(void)
int find_service(fstring service)
{
int iService;
- TALLOC_CTX *frame = talloc_stackframe();
all_string_sub(service,"\\","/",0);
@@ -463,8 +462,6 @@ int find_service(fstring service)
if (iService < 0)
DEBUG(3,("find_service() failed to find service %s\n", service));
- TALLOC_FREE(frame);
-
return (iService);
}
@@ -1150,20 +1147,17 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
#if SOFTLINK_OPTIMISATION
/* resolve any soft links early if possible */
if (vfs_ChDir(conn,conn->connectpath) == 0) {
- TALLOC_CTX *ctx = talloc_stackframe();
+ TALLOC_CTX *ctx = talloc_tos();
char *s = vfs_GetWd(ctx,s);
if (!s) {
*status = map_nt_error_from_unix(errno);
- TALLOC_FREE(ctx);
goto err_root_exit;
}
if (!set_conn_connectpath(conn,s)) {
*status = NT_STATUS_NO_MEMORY;
- TALLOC_FREE(ctx);
goto err_root_exit;
}
vfs_ChDir(conn,conn->connectpath);
- TALLOC_FREE(ctx);
}
#endif
diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index 485513c734..bf6802f2a6 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -297,9 +297,8 @@ static unsigned int estimate_ea_size(connection_struct *conn, files_struct *fsp,
if (!lp_ea_support(SNUM(conn))) {
return 0;
}
- mem_ctx = talloc_init("estimate_ea_size");
+ mem_ctx = talloc_tos();
(void)get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
- talloc_destroy(mem_ctx);
return total_ea_len;
}
@@ -310,7 +309,7 @@ static unsigned int estimate_ea_size(connection_struct *conn, files_struct *fsp,
static void canonicalize_ea_name(connection_struct *conn, files_struct *fsp, const char *fname, fstring unix_ea_name)
{
size_t total_ea_len;
- TALLOC_CTX *mem_ctx = talloc_init("canonicalize_ea_name");
+ TALLOC_CTX *mem_ctx = talloc_tos();
struct ea_list *ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
for (; ea_list; ea_list = ea_list->next) {
@@ -321,7 +320,6 @@ static void canonicalize_ea_name(connection_struct *conn, files_struct *fsp, con
break;
}
}
- talloc_destroy(mem_ctx);
}
/****************************************************************************
@@ -1955,9 +1953,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
out_of_space = True;
finished = False;
} else {
- TALLOC_CTX *sub_ctx = talloc_stackframe();
-
- finished = !get_lanman2_dir_entry(sub_ctx,
+ finished = !get_lanman2_dir_entry(ctx,
conn,
req->flags2,
mask,dirtype,info_level,
@@ -1966,8 +1962,6 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
space_remaining, &out_of_space,
&got_exact_match,
&last_entry_off, ea_list);
-
- TALLOC_FREE(sub_ctx);
}
if (finished && out_of_space)
@@ -2303,9 +2297,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
out_of_space = True;
finished = False;
} else {
- TALLOC_CTX *sub_ctx = talloc_stackframe();
-
- finished = !get_lanman2_dir_entry(sub_ctx,
+ finished = !get_lanman2_dir_entry(ctx,
conn,
req->flags2,
mask,dirtype,info_level,
@@ -2314,8 +2306,6 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
space_remaining, &out_of_space,
&got_exact_match,
&last_entry_off, ea_list);
-
- TALLOC_FREE(sub_ctx);
}
if (finished && out_of_space)
@@ -4759,17 +4749,12 @@ static NTSTATUS smb_info_set_ea(connection_struct *conn,
return NT_STATUS_INVALID_PARAMETER;
}
- ctx = talloc_init("SMB_INFO_SET_EA");
- if (!ctx) {
- return NT_STATUS_NO_MEMORY;
- }
+ ctx = talloc_tos();
ea_list = read_ea_list(ctx, pdata + 4, total_data - 4);
if (!ea_list) {
- talloc_destroy(ctx);
return NT_STATUS_INVALID_PARAMETER;
}
status = set_ea(conn, fsp, fname, ea_list);
- talloc_destroy(ctx);
return status;
}
@@ -6208,7 +6193,7 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
* non-POSIX opens return SHARING_VIOLATION.
*/
- lck = get_share_mode_lock(NULL, fsp->file_id, NULL, NULL);
+ lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL);
if (lck == NULL) {
DEBUG(0, ("smb_posix_unlink: Could not get share mode "
"lock for file %s\n", fsp->fsp_name));
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index 9a5e0aff60..33a3a43aa4 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -389,8 +389,8 @@ ssize_t vfs_read_data(files_struct *fsp, char *buf, size_t byte_count)
while (total < byte_count)
{
- ssize_t ret = SMB_VFS_READ(fsp, fsp->fh->fd, buf + total,
- byte_count - total);
+ ssize_t ret = SMB_VFS_READ(fsp, buf + total,
+ byte_count - total);
if (ret == 0) return total;
if (ret == -1) {
@@ -445,13 +445,12 @@ ssize_t vfs_write_data(struct smb_request *req,
req->unread_bytes = 0;
return SMB_VFS_RECVFILE(smbd_server_fd(),
fsp,
- fsp->fh->fd,
(SMB_OFF_T)-1,
N);
}
while (total < N) {
- ret = SMB_VFS_WRITE(fsp,fsp->fh->fd,buffer + total,N - total);
+ ret = SMB_VFS_WRITE(fsp, buffer + total, N - total);
if (ret == -1)
return -1;
@@ -479,7 +478,6 @@ ssize_t vfs_pwrite_data(struct smb_request *req,
req->unread_bytes = 0;
return SMB_VFS_RECVFILE(smbd_server_fd(),
fsp,
- fsp->fh->fd,
offset,
N);
}
@@ -662,25 +660,24 @@ int vfs_fill_sparse(files_struct *fsp, SMB_OFF_T len)
Transfer some data (n bytes) between two file_struct's.
****************************************************************************/
-static files_struct *in_fsp;
-static files_struct *out_fsp;
-
-static ssize_t read_fn(int fd, void *buf, size_t len)
+static ssize_t vfs_read_fn(void *file, void *buf, size_t len)
{
- return SMB_VFS_READ(in_fsp, fd, buf, len);
+ struct files_struct *fsp = (struct files_struct *)file;
+
+ return SMB_VFS_READ(fsp, buf, len);
}
-static ssize_t write_fn(int fd, const void *buf, size_t len)
+static ssize_t vfs_write_fn(void *file, const void *buf, size_t len)
{
- return SMB_VFS_WRITE(out_fsp, fd, buf, len);
+ struct files_struct *fsp = (struct files_struct *)file;
+
+ return SMB_VFS_WRITE(fsp, buf, len);
}
SMB_OFF_T vfs_transfer_file(files_struct *in, files_struct *out, SMB_OFF_T n)
{
- in_fsp = in;
- out_fsp = out;
-
- return transfer_file_internal(in_fsp->fh->fd, out_fsp->fh->fd, n, read_fn, write_fn);
+ return transfer_file_internal((void *)in, (void *)out, n,
+ vfs_read_fn, vfs_write_fn);
}
/*******************************************************************
@@ -869,14 +866,13 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
return map_nt_error_from_unix(errno);
case ENOENT:
{
- TALLOC_CTX *tmp_ctx = talloc_stackframe();
+ TALLOC_CTX *ctx = talloc_tos();
char *tmp_fname = NULL;
char *last_component = NULL;
/* Last component didn't exist. Remove it and try and canonicalise the directory. */
- tmp_fname = talloc_strdup(tmp_ctx, fname);
+ tmp_fname = talloc_strdup(ctx, fname);
if (!tmp_fname) {
- TALLOC_FREE(tmp_ctx);
return NT_STATUS_NO_MEMORY;
}
p = strrchr_m(tmp_fname, '/');
@@ -885,10 +881,9 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
last_component = p;
} else {
last_component = tmp_fname;
- tmp_fname = talloc_strdup(tmp_ctx,
+ tmp_fname = talloc_strdup(ctx,
".");
if (!tmp_fname) {
- TALLOC_FREE(tmp_ctx);
return NT_STATUS_NO_MEMORY;
}
}
@@ -900,15 +895,13 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
#endif
if (!resolved_name) {
DEBUG(3,("reduce_name: couldn't get realpath for %s\n", fname));
- TALLOC_FREE(tmp_ctx);
return map_nt_error_from_unix(errno);
}
- tmp_fname = talloc_asprintf(tmp_ctx,
+ tmp_fname = talloc_asprintf(ctx,
"%s/%s",
resolved_name,
last_component);
if (!tmp_fname) {
- TALLOC_FREE(tmp_ctx);
return NT_STATUS_NO_MEMORY;
}
#ifdef REALPATH_TAKES_NULL
@@ -922,7 +915,6 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
safe_strcpy(resolved_name_buf, tmp_fname, PATH_MAX);
resolved_name = resolved_name_buf;
#endif
- TALLOC_FREE(tmp_ctx);
break;
}
default: