return true;
}
- DEBUG(10,("pid[%d] wait for socket lock\n", (int)sys_getpid()));
+ DEBUG(10,("pid[%d] wait for socket lock\n", (int)getpid()));
do {
ok = fcntl_lock(
return false;
}
- DEBUG(10,("pid[%d] got for socket lock\n", (int)sys_getpid()));
+ DEBUG(10,("pid[%d] got for socket lock\n", (int)getpid()));
return true;
}
return false;
}
- DEBUG(10,("pid[%d] unlocked socket\n", (int)sys_getpid()));
+ DEBUG(10,("pid[%d] unlocked socket\n", (int)getpid()));
return true;
}
* client failed.
*/
DEBUG(1,("pid[%d] Error writing %d bytes to client %s. %d. (%s)\n",
- (int)sys_getpid(), (int)len,
+ (int)getpid(), (int)len,
get_peer_addr(sconn->sock, addr, sizeof(addr)),
(int)ret, strerror(errno) ));
req->sconn = sconn;
req->conn = conn_find(sconn,req->tid);
req->chain_fsp = NULL;
- req->chain_outbuf = NULL;
- req->done = false;
req->smb2req = NULL;
req->priv_paths = NULL;
+ req->chain = NULL;
smb_init_perfcount_data(&req->pcd);
/* Ensure we have at least wct words and 2 bytes of bcc. */
len = smb_len_tcp(data)+4;
for (i=1;i<100;i++) {
- if (asprintf(&fname, "/tmp/%s.%d.%s", name, i,
- type ? "req" : "resp") == -1) {
+ fname = talloc_asprintf(talloc_tos(),
+ "/tmp/%s.%d.%s",
+ name,
+ i,
+ type ? "req" : "resp");
+ if (fname == NULL) {
return;
}
fd = open(fname, O_WRONLY|O_CREAT|O_EXCL, 0644);
if (fd != -1 || errno != EEXIST) break;
+ TALLOC_FREE(fname);
}
if (fd != -1) {
ssize_t ret = write(fd, data, len);
close(fd);
DEBUG(0,("created %s len %lu\n", fname, (unsigned long)len));
}
- SAFE_FREE(fname);
+ TALLOC_FREE(fname);
}
/****************************************************************************
conn = req->conn;
DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n", smb_fn_name(type),
- (int)sys_getpid(), (unsigned long)conn));
+ (int)getpid(), (unsigned long)conn));
smb_dump(smb_fn_name(type), 1, (const char *)req->inbuf);
conn = switch_message(req->cmd, req);
- if (req->done) {
- TALLOC_FREE(req);
- return;
- }
-
if (req->outbuf == NULL) {
return;
}
bool encrypted,
struct smb_perfcount_data *deferred_pcd)
{
- struct connection_struct *conn = NULL;
struct smb_request **reqs = NULL;
- struct smb_request *req, *first_req, *last_req;
- unsigned i, num_reqs;
- NTSTATUS status;
+ struct smb_request *req;
+ unsigned num_reqs;
bool ok;
ok = smb1_parse_chain(talloc_tos(), (uint8_t *)inbuf, sconn, encrypted,
seqnum, &reqs, &num_reqs);
if (!ok) {
- status = NT_STATUS_INVALID_PARAMETER;
- goto error;
+ char errbuf[smb_size];
+ error_packet(errbuf, 0, 0, NT_STATUS_INVALID_PARAMETER,
+ __LINE__, __FILE__);
+ if (!srv_send_smb(sconn, errbuf, true, seqnum, encrypted,
+ NULL)) {
+ exit_server_cleanly("construct_reply_chain: "
+ "srv_send_smb failed.");
+ }
+ return;
}
- for (i=0; i<num_reqs; i++) {
- req = reqs[i];
+ req = reqs[0];
+ req->inbuf = (uint8_t *)talloc_move(reqs, &inbuf);
- if (i > 0) {
- /*
- * Get the session and tree ids and chain fsp
- * from the previous request into the current
- * one
- */
- struct smb_request *prev_req = reqs[i-1];
- const uint8_t *prev_outbuf = prev_req->outbuf;
+ req->conn = switch_message(req->cmd, req);
- req->vuid = SVAL(prev_outbuf, smb_uid);
- req->tid = SVAL(prev_outbuf, smb_tid);
- req->conn = conn_find(req->sconn, req->tid);
- req->chain_fsp = prev_req->chain_fsp;
- }
- req->inbuf = (uint8_t *)inbuf;
- conn = switch_message(req->cmd, req);
+ if (req->outbuf == NULL) {
+ /*
+ * Request has suspended itself, will come
+ * back here.
+ */
+ return;
+ }
+ smb_request_done(req);
+}
- if (req->outbuf == NULL) {
- if (open_was_deferred(req->sconn, req->mid)) {
- TALLOC_FREE(reqs);
- return;
- }
- status = NT_STATUS_INTERNAL_ERROR;
- goto error;
- }
- if (IVAL(req->outbuf, smb_rcls) != 0) {
- break;
- }
+/*
+ * To be called from an async SMB handler that is potentially chained
+ * when it is finished for shipping.
+ */
+
+void smb_request_done(struct smb_request *req)
+{
+ struct smb_request **reqs = NULL;
+ struct smb_request *first_req;
+ size_t i, num_reqs, next_index;
+ NTSTATUS status;
+
+ if (req->chain == NULL) {
+ first_req = req;
+ goto shipit;
}
- first_req = reqs[0];
- last_req = req;
+ reqs = req->chain;
+ num_reqs = talloc_array_length(reqs);
- if (i == 0) {
+ for (i=0; i<num_reqs; i++) {
+ if (reqs[i] == req) {
+ break;
+ }
+ }
+ if (i == num_reqs) {
/*
- * The first request already gave an error, no need to
- * do any splicing
+ * Invalid chain, should not happen
*/
- goto shipit;
+ status = NT_STATUS_INTERNAL_ERROR;
+ goto error;
+ }
+ next_index = i+1;
+
+ while ((next_index < num_reqs) && (IVAL(req->outbuf, smb_rcls) == 0)) {
+ struct smb_request *next = reqs[next_index];
+
+ next->vuid = SVAL(req->outbuf, smb_uid);
+ next->tid = SVAL(req->outbuf, smb_tid);
+ next->conn = conn_find(req->sconn, req->tid);
+ next->chain_fsp = req->chain_fsp;
+ next->inbuf = (uint8_t *)req->inbuf;
+
+ req = next;
+ req->conn = switch_message(req->cmd, req);
+
+ if (req->outbuf == NULL) {
+ /*
+ * Request has suspended itself, will come
+ * back here.
+ */
+ return;
+ }
+ next_index += 1;
}
+ first_req = reqs[0];
+
for (i=1; i<next_index; i++) {
- req = reqs[i];
+ bool ok;
- ok = smb_splice_chain(&first_req->outbuf, req->outbuf);
+ ok = smb_splice_chain(&first_req->outbuf, reqs[i]->outbuf);
if (!ok) {
status = NT_STATUS_INTERNAL_ERROR;
goto error;
}
- if (req == last_req) {
- break;
- }
}
- SSVAL(first_req->outbuf, smb_uid, SVAL(last_req->outbuf, smb_uid));
- SSVAL(first_req->outbuf, smb_tid, SVAL(last_req->outbuf, smb_tid));
+ SSVAL(first_req->outbuf, smb_uid, SVAL(req->outbuf, smb_uid));
+ SSVAL(first_req->outbuf, smb_tid, SVAL(req->outbuf, smb_tid));
/*
* This scary statement intends to set the
*/
SSVAL(first_req->outbuf, smb_flg2,
(SVAL(first_req->outbuf, smb_flg2) & ~FLAGS2_32_BIT_ERROR_CODES)
- |(SVAL(last_req->outbuf, smb_flg2) & FLAGS2_32_BIT_ERROR_CODES));
+ |(SVAL(req->outbuf, smb_flg2) & FLAGS2_32_BIT_ERROR_CODES));
/*
* Transfer the error codes from the subrequest to the main one
*/
- SSVAL(first_req->outbuf, smb_rcls, SVAL(last_req->outbuf, smb_rcls));
- SSVAL(first_req->outbuf, smb_err, SVAL(last_req->outbuf, smb_err));
+ SSVAL(first_req->outbuf, smb_rcls, SVAL(req->outbuf, smb_rcls));
+ SSVAL(first_req->outbuf, smb_err, SVAL(req->outbuf, smb_err));
- goto shipit;
+ _smb_setlen_large(
+ first_req->outbuf, talloc_get_size(first_req->outbuf) - 4);
shipit:
- _smb_setlen_large(first_req->outbuf,
- talloc_get_size(first_req->outbuf) - 4);
-
if (!srv_send_smb(first_req->sconn,
(char *)first_req->outbuf,
true, first_req->seqnum+1,
- IS_CONN_ENCRYPTED(conn)||first_req->encrypted,
+ IS_CONN_ENCRYPTED(req->conn)||first_req->encrypted,
&first_req->pcd)) {
exit_server_cleanly("construct_reply_chain: srv_send_smb "
"failed.");
}
- TALLOC_FREE(reqs);
+ TALLOC_FREE(req); /* non-chained case */
+ TALLOC_FREE(reqs); /* chained case */
return;
error:
{
char errbuf[smb_size];
error_packet(errbuf, 0, 0, status, __LINE__, __FILE__);
- if (!srv_send_smb(sconn, errbuf, true, seqnum, encrypted,
+ if (!srv_send_smb(req->sconn, errbuf, true,
+ req->seqnum+1, req->encrypted,
NULL)) {
exit_server_cleanly("construct_reply_chain: "
"srv_send_smb failed.");
}
}
- TALLOC_FREE(reqs);
+ TALLOC_FREE(req); /* non-chained case */
+ TALLOC_FREE(reqs); /* chained case */
}
/****************************************************************************
construct_reply_common(req, (const char *)req->inbuf, outbuf);
}
-/*
- * How many bytes have we already accumulated up to the current wct field
- * offset?
- */
-
-size_t req_wct_ofs(struct smb_request *req)
-{
- size_t buf_size;
-
- if (req->chain_outbuf == NULL) {
- return smb_wct - 4;
- }
- buf_size = talloc_get_size(req->chain_outbuf);
- if ((buf_size % 4) != 0) {
- buf_size += (4 - (buf_size % 4));
- }
- return buf_size - 4;
-}
-
/**
* @brief Find the smb_cmd offset of the last command pushed
* @param[in] buf The buffer we're building up
struct smb_request ***reqs, unsigned *num_reqs)
{
struct smb1_parse_chain_state state;
+ unsigned i;
state.mem_ctx = mem_ctx;
state.buf = buf;
TALLOC_FREE(state.reqs);
return false;
}
+ for (i=0; i<state.num_reqs; i++) {
+ state.reqs[i]->chain = state.reqs;
+ }
*reqs = state.reqs;
*num_reqs = state.num_reqs;
return true;
if (!fd_is_readable(sconn->sock)) {
DEBUG(10,("echo_handler[%d] the parent smbd was faster\n",
- (int)sys_getpid()));
+ (int)getpid()));
ok = smbd_unlock_socket_internal(sconn);
if (!ok) {
if (tevent_req_nterror(req, status)) {
tevent_req_nterror(req, status);
DEBUG(1, ("echo_handler[%d]: receive_smb_raw_talloc failed: %s\n",
- (int)sys_getpid(), nt_errstr(status)));
+ (int)getpid(), nt_errstr(status)));
return;
}
DEBUG(1, ("writev to parent failed: %s\n", strerror(err)));
exit(1);
}
- DEBUG(10,("echo_handler[%d]: forwarded pdu to main\n", (int)sys_getpid()));
+ DEBUG(10,("echo_handler[%d]: forwarded pdu to main\n", (int)getpid()));
smbd_echo_activate_writer(state);
}
iov->iov_len = buflen;
DEBUG(10,("echo_handler[%d]: forward to main\n",
- (int)sys_getpid()));
+ (int)getpid()));
smbd_echo_activate_writer(state);
}
goto fail;
}
- child = sys_fork();
+ child = fork();
if (child == 0) {
NTSTATUS status;
listener_pipe[1] = -1;
sconn->smb1.echo_handler.trusted_fd = listener_pipe[0];
- DEBUG(10,("fork_echo_handler: main[%d] echo_child[%d]\n", (int)sys_getpid(), child));
+ DEBUG(10,("fork_echo_handler: main[%d] echo_child[%d]\n", (int)getpid(), child));
/*
* Without smb signing this is the same as the normal smbd