From: Volker Lendecke Date: Tue, 21 Apr 2015 08:16:16 +0000 (+0200) Subject: smbd: Cancel pending notifies if the directory goes away X-Git-Tag: tdb-1.3.5~40 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=50a1247927cb68303701a11517811deda10364f7;p=thirdparty%2Fsamba.git smbd: Cancel pending notifies if the directory goes away Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/librpc/idl/messaging.idl b/librpc/idl/messaging.idl index 04dfa1eff8f..2b902ec0a1d 100644 --- a/librpc/idl/messaging.idl +++ b/librpc/idl/messaging.idl @@ -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, diff --git a/source3/locking/locking.c b/source3/locking/locking.c index bcc9bfeff85..ce595e12d0d 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -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; inum_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, diff --git a/source3/smbd/notify.c b/source3/smbd/notify.c index 5ac8c0c791d..8cb44df3c1d 100644 --- a/source3/smbd/notify.c +++ b/source3/smbd/notify.c @@ -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. *****************************************************************************/ diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index f01bbbdfedc..a5144d5e078 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -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, diff --git a/source3/smbd/service.c b/source3/smbd/service.c index ada2d07aa7c..d11987e63ee 100644 --- a/source3/smbd/service.c +++ b/source3/smbd/service.c @@ -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(