*/
#include "includes.h"
+#include "smbd/globals.h"
struct notify_change_request {
struct notify_change_request *prev, *next;
struct files_struct *fsp; /* backpointer for cancel by mid */
- uint8 request_buf[smb_size];
+ struct smb_request *req;
uint32 filter;
uint32 max_param;
struct notify_mid_map *mid_map;
static void notify_fsp(files_struct *fsp, uint32 action, const char *name);
-static struct notify_mid_map *notify_changes_by_mid;
-
/*
* For NTCancel, we need to find the notify_change_request indexed by
* mid. Separate list here.
int i;
UNISTR uni_name;
+ uni_name.buffer = NULL;
+
for (i=0; i<num_changes; i++) {
struct notify_change *c;
size_t namelen;
c = &changes[i];
- namelen = convert_string_allocate(
- NULL, CH_UNIX, CH_UTF16LE, c->name, strlen(c->name)+1,
- &uni_name.buffer, True);
- if ((namelen == -1) || (uni_name.buffer == NULL)) {
+ if (!convert_string_talloc(talloc_tos(), CH_UNIX, CH_UTF16LE,
+ c->name, strlen(c->name)+1, &uni_name.buffer,
+ &namelen, True) || (uni_name.buffer == NULL)) {
goto fail;
}
*/
prs_set_offset(ps, prs_offset(ps)-2);
- SAFE_FREE(uni_name.buffer);
+ TALLOC_FREE(uni_name.buffer);
if (prs_offset(ps) > max_offset) {
/* Too much data for client. */
+ DEBUG(10, ("Client only wanted %d bytes, trying to "
+ "marshall %d bytes\n", (int)max_offset,
+ (int)prs_offset(ps)));
return False;
}
}
return True;
fail:
- SAFE_FREE(uni_name.buffer);
+ TALLOC_FREE(uni_name.buffer);
return False;
}
*****************************************************************************/
static void change_notify_reply_packet(connection_struct *conn,
- const uint8 *request_buf,
+ struct smb_request *req,
NTSTATUS error_code)
{
- char outbuf[smb_size+38];
-
- memset(outbuf, '\0', sizeof(outbuf));
- construct_reply_common((char *)request_buf, outbuf);
-
- ERROR_NT(error_code);
+ reply_outbuf(req, 18, 0);
- /*
- * Seems NT needs a transact command with an error code
- * in it. This is a longer packet than a simple error.
- */
- srv_set_message(outbuf,18,0,False);
+ if (!NT_STATUS_IS_OK(error_code)) {
+ error_packet_set((char *)req->outbuf, 0, 0, error_code,
+ __LINE__,__FILE__);
+ }
- show_msg(outbuf);
+ show_msg((char *)req->outbuf);
if (!srv_send_smb(smbd_server_fd(),
- outbuf,
- IS_CONN_ENCRYPTED(conn)))
+ (char *)req->outbuf,
+ true, req->seqnum+1,
+ req->encrypted, &req->pcd)) {
exit_server_cleanly("change_notify_reply_packet: srv_send_smb "
"failed.");
+ }
+ TALLOC_FREE(req->outbuf);
}
void change_notify_reply(connection_struct *conn,
- const uint8 *request_buf, uint32 max_param,
+ struct smb_request *req, uint32 max_param,
struct notify_change_buf *notify_buf)
{
prs_struct ps;
- struct smb_request *req = NULL;
- uint8 tmp_request[smb_size];
if (notify_buf->num_changes == -1) {
- change_notify_reply_packet(conn, request_buf, NT_STATUS_OK);
+ change_notify_reply_packet(conn, req, NT_STATUS_OK);
notify_buf->num_changes = 0;
return;
}
- prs_init(&ps, 0, NULL, MARSHALL);
+ prs_init_empty(&ps, NULL, MARSHALL);
if (!notify_marshall_changes(notify_buf->num_changes, max_param,
notify_buf->changes, &ps)) {
* We exceed what the client is willing to accept. Send
* nothing.
*/
- change_notify_reply_packet(conn, request_buf, NT_STATUS_OK);
+ change_notify_reply_packet(conn, req, NT_STATUS_OK);
goto done;
}
- if (!(req = talloc(talloc_tos(), struct smb_request))) {
- change_notify_reply_packet(conn, request_buf, NT_STATUS_NO_MEMORY);
- goto done;
- }
-
- memcpy(tmp_request, request_buf, smb_size);
-
- /*
- * We're only interested in the header fields here
- */
-
- smb_setlen((char *)tmp_request, smb_size);
- SCVAL(tmp_request, smb_wct, 0);
-
- init_smb_request(req, tmp_request,0, conn->encrypted_tid);
-
send_nt_replies(conn, req, NT_STATUS_OK, prs_data_p(&ps),
prs_offset(&ps), NULL, 0);
done:
- TALLOC_FREE(req);
prs_mem_free(&ps);
TALLOC_FREE(notify_buf->changes);
if (asprintf(&fullpath, "%s/%s", fsp->conn->connectpath,
fsp->fsp_name) == -1) {
DEBUG(0, ("asprintf failed\n"));
+ TALLOC_FREE(fsp->notify);
return NT_STATUS_NO_MEMORY;
}
+ ZERO_STRUCT(e);
e.path = fullpath;
+ e.dir_fd = fsp->fh->fd;
+ e.dir_id = fsp->file_id;
e.filter = filter;
e.subdir_filter = 0;
if (recursive) {
return status;
}
-NTSTATUS change_notify_add_request(const struct smb_request *req,
+NTSTATUS change_notify_add_request(struct smb_request *req,
uint32 max_param,
uint32 filter, bool recursive,
struct files_struct *fsp)
struct notify_change_request *request = NULL;
struct notify_mid_map *map = NULL;
- if (!(request = SMB_MALLOC_P(struct notify_change_request))
- || !(map = SMB_MALLOC_P(struct notify_mid_map))) {
- SAFE_FREE(request);
+ DEBUG(10, ("change_notify_add_request: Adding request for %s: "
+ "max_param = %d\n", fsp->fsp_name, (int)max_param));
+
+ if (!(request = talloc(NULL, struct notify_change_request))
+ || !(map = talloc(request, struct notify_mid_map))) {
+ TALLOC_FREE(request);
return NT_STATUS_NO_MEMORY;
}
request->mid_map = map;
map->req = request;
- memcpy(request->request_buf, req->inbuf, sizeof(request->request_buf));
+ request->req = talloc_move(request, &req);
request->max_param = max_param;
request->filter = filter;
request->fsp = fsp;
DLIST_ADD_END(fsp->notify->requests, request,
struct notify_change_request *);
- map->mid = SVAL(req->inbuf, smb_mid);
+ map->mid = request->req->mid;
DLIST_ADD(notify_changes_by_mid, map);
- /* Push the MID of this packet on the signing queue. */
- srv_defer_sign_response(SVAL(req->inbuf,smb_mid));
-
return NT_STATUS_OK;
}
DLIST_REMOVE(fsp->notify->requests, req);
DLIST_REMOVE(notify_changes_by_mid, req->mid_map);
- SAFE_FREE(req->mid_map);
- TALLOC_FREE(req->backend_data);
- SAFE_FREE(req);
+ TALLOC_FREE(req);
}
/****************************************************************************
return;
}
- change_notify_reply_packet(map->req->fsp->conn,
- map->req->request_buf, NT_STATUS_CANCELLED);
+ change_notify_reply_packet(map->req->fsp->conn, map->req->req,
+ NT_STATUS_CANCELLED);
change_notify_remove_request(map->req);
}
}
while (fsp->notify->requests != NULL) {
- change_notify_reply_packet(fsp->conn,
- fsp->notify->requests->request_buf, status);
+ change_notify_reply_packet(
+ fsp->conn, fsp->notify->requests->req, status);
change_notify_remove_request(fsp->notify->requests);
}
}
const char *path)
{
char *fullpath;
+ char *parent;
+ const char *name;
+
+ if (path[0] == '.' && path[1] == '/') {
+ path += 2;
+ }
+ if (parent_dirname(talloc_tos(), path, &parent, &name)) {
+ struct smb_filename *smb_fname_parent = NULL;
+ NTSTATUS status;
+
+ status = create_synthetic_smb_fname(talloc_tos(), parent, NULL,
+ NULL, &smb_fname_parent);
+ if (!NT_STATUS_IS_OK(status)) {
+ return;
+ }
+ if (SMB_VFS_STAT(conn, smb_fname_parent) != -1) {
+ notify_onelevel(conn->notify_ctx, action, filter,
+ SMB_VFS_FILE_ID_CREATE(conn, &smb_fname_parent->st),
+ name);
+ }
+ TALLOC_FREE(smb_fname_parent);
+ }
- if (asprintf(&fullpath, "%s/%s", conn->connectpath, path) == -1) {
+ fullpath = talloc_asprintf(talloc_tos(), "%s/%s", conn->connectpath,
+ path);
+ if (fullpath == NULL) {
DEBUG(0, ("asprintf failed\n"));
return;
}
-
notify_trigger(conn->notify_ctx, action, filter, fullpath);
- SAFE_FREE(fullpath);
+ TALLOC_FREE(fullpath);
}
static void notify_fsp(files_struct *fsp, uint32 action, const char *name)
if ((fsp->notify->num_changes > 1000) || (name == NULL)) {
/*
* The real number depends on the client buf, just provide a
- * guard against a DoS here.
+ * guard against a DoS here. If name == NULL the CN backend is
+ * alerting us to a problem. Possibly dropped events. Clear
+ * queued changes and send the catch-all response to the client
+ * if a request is pending.
*/
TALLOC_FREE(fsp->notify->changes);
fsp->notify->num_changes = -1;
+ if (fsp->notify->requests != NULL) {
+ change_notify_reply(fsp->conn,
+ fsp->notify->requests->req,
+ fsp->notify->requests->max_param,
+ fsp->notify);
+ change_notify_remove_request(fsp->notify->requests);
+ }
return;
}
+ /* If we've exceeded the server side queue or received a NULL name
+ * from the underlying CN implementation, don't queue up any more
+ * requests until we can send a catch-all response to the client */
if (fsp->notify->num_changes == -1) {
return;
}
*/
change_notify_reply(fsp->conn,
- fsp->notify->requests->request_buf,
+ fsp->notify->requests->req,
fsp->notify->requests->max_param,
fsp->notify);