1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-22 22:04:08 +03:00

smbd: Cancel pending notifies if the directory goes away

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke 2015-04-21 10:16:16 +02:00 committed by Jeremy Allison
parent b0d4a7daa1
commit 50a1247927
5 changed files with 83 additions and 1 deletions

View File

@ -96,6 +96,9 @@ interface messaging
MSG_SMB_TELL_NUM_CHILDREN = 0x0317,
MSG_SMB_NUM_CHILDREN = 0x0318,
/* Cancel a notify, directory got deleted */
MSG_SMB_NOTIFY_CANCEL_DELETED = 0x0319,
/* winbind messages */
MSG_WINBIND_FINISHED = 0x0401,
MSG_WINBIND_FORGET_STATE = 0x0402,

View File

@ -46,6 +46,7 @@
#include "messages.h"
#include "util_tdb.h"
#include "../librpc/gen_ndr/ndr_open_files.h"
#include "librpc/gen_ndr/ndr_file_id.h"
#include "locking/leases_db.h"
#undef DBGC_CLASS
@ -1118,9 +1119,12 @@ void set_delete_on_close_lck(files_struct *fsp,
const struct security_token *nt_tok,
const struct security_unix_token *tok)
{
struct messaging_context *msg_ctx = fsp->conn->sconn->msg_ctx;
struct share_mode_data *d = lck->data;
int i;
uint32_t i;
bool ret;
DATA_BLOB fid_blob = {};
enum ndr_err_code ndr_err;
SMB_ASSERT(nt_tok != NULL);
SMB_ASSERT(tok != NULL);
@ -1144,6 +1148,31 @@ void set_delete_on_close_lck(files_struct *fsp,
ret = add_delete_on_close_token(lck->data, fsp->name_hash, nt_tok, tok);
SMB_ASSERT(ret);
ndr_err = ndr_push_struct_blob(&fid_blob, talloc_tos(), &fsp->file_id,
(ndr_push_flags_fn_t)ndr_push_file_id);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
DEBUG(10, ("ndr_push_file_id failed: %s\n",
ndr_errstr(ndr_err)));
}
for (i=0; i<d->num_share_modes; i++) {
struct share_mode_entry *e = &d->share_modes[i];
NTSTATUS status;
status = messaging_send(
msg_ctx, e->pid, MSG_SMB_NOTIFY_CANCEL_DELETED,
&fid_blob);
if (!NT_STATUS_IS_OK(status)) {
struct server_id_buf tmp;
DEBUG(10, ("%s: messaging_send to %s returned %s\n",
__func__, server_id_str_buf(e->pid, &tmp),
nt_errstr(status)));
}
}
TALLOC_FREE(fid_blob.data);
}
bool set_delete_on_close(files_struct *fsp, bool delete_on_close,

View File

@ -23,6 +23,7 @@
#include "smbd/smbd.h"
#include "smbd/globals.h"
#include "../librpc/gen_ndr/ndr_notify.h"
#include "librpc/gen_ndr/ndr_file_id.h"
struct notify_change_event {
struct timespec when;
@ -418,6 +419,48 @@ void smbd_notify_cancel_by_smbreq(const struct smb_request *smbreq)
change_notify_remove_request(sconn, map->req);
}
static struct files_struct *smbd_notify_cancel_deleted_fn(
struct files_struct *fsp, void *private_data)
{
struct file_id *fid = talloc_get_type_abort(
private_data, struct file_id);
if (file_id_equal(&fsp->file_id, fid)) {
remove_pending_change_notify_requests_by_fid(
fsp, NT_STATUS_DELETE_PENDING);
}
return NULL;
}
void smbd_notify_cancel_deleted(struct messaging_context *msg,
void *private_data, uint32_t msg_type,
struct server_id server_id, DATA_BLOB *data)
{
struct smbd_server_connection *sconn = talloc_get_type_abort(
private_data, struct smbd_server_connection);
struct file_id *fid;
enum ndr_err_code ndr_err;
fid = talloc(talloc_tos(), struct file_id);
if (fid == NULL) {
DEBUG(1, ("talloc failed\n"));
return;
}
ndr_err = ndr_pull_struct_blob_all(
data, fid, fid, (ndr_pull_flags_fn_t)ndr_pull_file_id);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
DEBUG(10, ("%s: ndr_pull_file_id failed: %s\n", __func__,
ndr_errstr(ndr_err)));
goto done;
}
files_forall(sconn, smbd_notify_cancel_deleted_fn, fid);
done:
TALLOC_FREE(fid);
}
/****************************************************************************
Delete entries by fnum from the change notify pending queue.
*****************************************************************************/

View File

@ -517,6 +517,9 @@ NTSTATUS change_notify_add_request(struct smb_request *req,
void (*reply_fn)(struct smb_request *req,
NTSTATUS error_code,
uint8_t *buf, size_t len));
void smbd_notify_cancel_deleted(struct messaging_context *msg,
void *private_data, uint32_t msg_type,
struct server_id server_id, DATA_BLOB *data);
void remove_pending_change_notify_requests_by_mid(
struct smbd_server_connection *sconn, uint64_t mid);
void remove_pending_change_notify_requests_by_fid(files_struct *fsp,

View File

@ -682,6 +682,10 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
if (sconn->notify_ctx == NULL) {
sconn->notify_ctx = notify_init(
sconn, sconn->msg_ctx, sconn->ev_ctx);
status = messaging_register(
sconn->msg_ctx, sconn,
MSG_SMB_NOTIFY_CANCEL_DELETED,
smbd_notify_cancel_deleted);
}
if (sconn->sys_notify_ctx == NULL) {
sconn->sys_notify_ctx = sys_notify_context_create(