From 58aa97c0d9db06588d1aba4f06a3c98ed2098d8f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 1 Aug 2008 23:14:51 +0200 Subject: Refactoring: Add the routine cli_request_send() cli_request_send() is supposed to bundle all generic SMB-header handling. This makes cli_request_new static to async_smb.c. (This used to be commit 7e73dd4e7622db64d30d48ba106892e0895fc188) --- source3/include/async_smb.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/include/async_smb.h') diff --git a/source3/include/async_smb.h b/source3/include/async_smb.h index 19408be74b..5ec6b12050 100644 --- a/source3/include/async_smb.h +++ b/source3/include/async_smb.h @@ -20,14 +20,14 @@ #include "includes.h" /* - * Create a fresh async smb request + * Ship a new smb request to the server */ -struct async_req *cli_request_new(TALLOC_CTX *mem_ctx, - struct event_context *ev, - struct cli_state *cli, - uint8_t num_words, size_t num_bytes, - struct cli_request **preq); +struct async_req *cli_request_send(TALLOC_CTX *mem_ctx, struct cli_state *cli, + uint8_t smb_command, + uint8_t additional_flags, + uint8_t wct, const uint16_t *vwv, + uint16_t num_bytes, const uint8_t *bytes); /* * Convenience function to get the SMB part out of an async_req -- cgit From 2650207d4adbfd68974fc2b342dd2af079a2552c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 24 Aug 2008 14:17:43 +0200 Subject: Remove cli->event_ctx, pass it explicitly Storing the event_context as permanent state in struct cli_state creates more complex code than necessary IMO. (This used to be commit debb37f703075008e5ea7d34d214cfa4d0f8f916) --- source3/include/async_smb.h | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'source3/include/async_smb.h') diff --git a/source3/include/async_smb.h b/source3/include/async_smb.h index 5ec6b12050..40a8d3476e 100644 --- a/source3/include/async_smb.h +++ b/source3/include/async_smb.h @@ -23,7 +23,9 @@ * Ship a new smb request to the server */ -struct async_req *cli_request_send(TALLOC_CTX *mem_ctx, struct cli_state *cli, +struct async_req *cli_request_send(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct cli_state *cli, uint8_t smb_command, uint8_t additional_flags, uint8_t wct, const uint16_t *vwv, @@ -46,17 +48,3 @@ NTSTATUS cli_pull_error(char *buf); */ void cli_set_error(struct cli_state *cli, NTSTATUS status); - -/* - * Create a temporary event context for use in the sync helper functions - */ - -struct cli_tmp_event *cli_tmp_event_ctx(TALLOC_CTX *mem_ctx, - struct cli_state *cli); - -/* - * Attach an event context permanently to a cli_struct - */ - -NTSTATUS cli_add_event_ctx(struct cli_state *cli, - struct event_context *event_ctx); -- cgit From 128524930d490fb5ea637d99bffb36157c80869b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 25 Aug 2008 13:33:41 +0200 Subject: Add cli_pull_reply Along the lines of cli_request_send this abstracts away the smb-level buffer handling when parsing replies we got from the server. (This used to be commit 253134d3aaa359fdfb665709dd5686f69af7f8fd) --- source3/include/async_smb.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/include/async_smb.h') diff --git a/source3/include/async_smb.h b/source3/include/async_smb.h index 40a8d3476e..93d2273239 100644 --- a/source3/include/async_smb.h +++ b/source3/include/async_smb.h @@ -37,6 +37,10 @@ struct async_req *cli_request_send(TALLOC_CTX *mem_ctx, struct cli_request *cli_request_get(struct async_req *req); +NTSTATUS cli_pull_reply(struct async_req *req, + uint8_t *pwct, uint16_t **pvwv, + uint16_t *pnum_bytes, uint8_t **pbytes); + /* * Fetch an error out of a NBT packet */ -- cgit From 77d1b29e25512982a1f912adac46bb954ee3d19f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 25 Aug 2008 14:40:15 +0200 Subject: Move "struct cli_request" from client.h to async_smb.h Also add some comments (This used to be commit 2ecc311f785317caf5b60051147dcd085c80d64f) --- source3/include/async_smb.h | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'source3/include/async_smb.h') diff --git a/source3/include/async_smb.h b/source3/include/async_smb.h index 93d2273239..031ab233dd 100644 --- a/source3/include/async_smb.h +++ b/source3/include/async_smb.h @@ -17,8 +17,69 @@ along with this program. If not, see . */ +#ifndef __ASYNC_SMB_H__ +#define __ASYNC_SMB_H__ + #include "includes.h" +struct cli_request { + /** + * "prev" and "next" form the doubly linked list in + * cli_state->outstanding_requests + */ + struct cli_request *prev, *next; + + /** + * "our" struct async_req; + */ + struct async_req *async; + + /** + * The client connection for this request + */ + struct cli_state *cli; + + /** + * The enc_state to decrypt the reply + */ + struct smb_trans_enc_state *enc_state; + + /** + * The mid we used for this request. Mainly used to demultiplex on + * receiving replies. + */ + uint16_t mid; + + /** + * The bytes we have to ship to the server + */ + char *outbuf; + + /** + * How much from "outbuf" did we already send + */ + size_t sent; + + /** + * The reply comes in here. Its intended size is implicit by + * smb_len(), its current size can be read via talloc_get_size() + */ + char *inbuf; + + /** + * Specific requests might add stuff here. Maybe convert this to a + * private_pointer at some point. + */ + union { + struct { + off_t ofs; + size_t size; + ssize_t received; + uint8_t *rcvbuf; + } read; + } data; +}; + /* * Ship a new smb request to the server */ @@ -52,3 +113,5 @@ NTSTATUS cli_pull_error(char *buf); */ void cli_set_error(struct cli_state *cli, NTSTATUS status); + +#endif -- cgit From b054f14111337c826548d7728dc2b0a66ab5beae Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 25 Aug 2008 15:59:36 +0200 Subject: Activate code to enable chained requests Add the CHAIN1 torture test (This used to be commit 82992d74a99b056bbfe90e1b79190e0b7c0bf2bd) --- source3/include/async_smb.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'source3/include/async_smb.h') diff --git a/source3/include/async_smb.h b/source3/include/async_smb.h index 031ab233dd..1053de2942 100644 --- a/source3/include/async_smb.h +++ b/source3/include/async_smb.h @@ -22,6 +22,13 @@ #include "includes.h" +/** + * struct cli_request is the state holder for an async client request we sent + * to the server. It can consist of more than one struct async_req that we + * have to server if the application did a cli_chain_cork() and + * cli_chain_uncork() + */ + struct cli_request { /** * "prev" and "next" form the doubly linked list in @@ -30,9 +37,15 @@ struct cli_request { struct cli_request *prev, *next; /** - * "our" struct async_req; + * num_async: How many chained requests do we serve? + */ + int num_async; + + /** + * async: This is the list of chained requests that were queued up by + * cli_request_chain before we sent out this request */ - struct async_req *async; + struct async_req **async; /** * The client connection for this request @@ -92,6 +105,10 @@ struct async_req *cli_request_send(TALLOC_CTX *mem_ctx, uint8_t wct, const uint16_t *vwv, uint16_t num_bytes, const uint8_t *bytes); +bool cli_chain_cork(struct cli_state *cli, struct event_context *ev, + size_t size_hint); +void cli_chain_uncork(struct cli_state *cli); + /* * Convenience function to get the SMB part out of an async_req */ -- cgit From bb0fc9cfceab7e961eaa9049d111121609ff8174 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 27 Aug 2008 19:26:40 +0200 Subject: Add cli_request->recv_helper Necessary for requests with multiple replies (This used to be commit cb2e338eb33dfb4627f9b43456af0c86d7d268c6) --- source3/include/async_smb.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source3/include/async_smb.h') diff --git a/source3/include/async_smb.h b/source3/include/async_smb.h index 1053de2942..6a09bb6001 100644 --- a/source3/include/async_smb.h +++ b/source3/include/async_smb.h @@ -91,6 +91,18 @@ struct cli_request { uint8_t *rcvbuf; } read; } data; + + /** + * For requests that don't follow the strict request/reply pattern + * such as the transaction request family and echo requests it is + * necessary to break the standard procedure in + * handle_incoming_pdu(). For a simple example look at + * cli_echo_recv_helper(). + */ + struct { + void (*fn)(struct async_req *req); + void *priv; + } recv_helper; }; /* -- cgit From 228a12681bc7e6eb5bddb75b3b97a74c5eef1c3a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 27 Aug 2008 19:30:57 +0200 Subject: Add async smbecho client support (This used to be commit c1d645fbe39433541d8bfe6b818c855cee318dc5) --- source3/include/async_smb.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/include/async_smb.h') diff --git a/source3/include/async_smb.h b/source3/include/async_smb.h index 6a09bb6001..ed42baef0d 100644 --- a/source3/include/async_smb.h +++ b/source3/include/async_smb.h @@ -90,6 +90,10 @@ struct cli_request { ssize_t received; uint8_t *rcvbuf; } read; + struct { + DATA_BLOB data; + uint16_t num_echos; + } echo; } data; /** -- cgit From f294f51bf0d136208fee1be343684ea890a499d0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 28 Aug 2008 15:44:14 +0200 Subject: Remove cli_request_get() req->private_data==NULL at this point is definitely a bug. (This used to be commit ce3dc9f616cafc1289a94ac7cae0beca967d836e) --- source3/include/async_smb.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'source3/include/async_smb.h') diff --git a/source3/include/async_smb.h b/source3/include/async_smb.h index ed42baef0d..e9e10023e3 100644 --- a/source3/include/async_smb.h +++ b/source3/include/async_smb.h @@ -125,12 +125,6 @@ bool cli_chain_cork(struct cli_state *cli, struct event_context *ev, size_t size_hint); void cli_chain_uncork(struct cli_state *cli); -/* - * Convenience function to get the SMB part out of an async_req - */ - -struct cli_request *cli_request_get(struct async_req *req); - NTSTATUS cli_pull_reply(struct async_req *req, uint8_t *pwct, uint16_t **pvwv, uint16_t *pnum_bytes, uint8_t **pbytes); -- cgit