The branch, master has been updated via 592c669 s3: Convert cli_raw_tcon to cli_smb via 13c1c8e s3: Fix a memleak via c83ce65 s3: Replace a use of cli_errstr via ffef3aa s3: Replace cli_negprot_sendsync() by cli_negprot_send() via a60ba54 s3: Remove a pointless static via 5d9075c s3: Remove a use of cli_send_smb from b47b4c9 s3: Remove two calls to cli_errstr
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 592c669d9ddeb3a39ed8472c633c7deace33a269 Author: Volker Lendecke <v...@samba.org> Date: Sun Mar 27 18:03:24 2011 +0200 s3: Convert cli_raw_tcon to cli_smb Autobuild-User: Volker Lendecke <vlen...@samba.org> Autobuild-Date: Sun Mar 27 19:50:21 CEST 2011 on sn-devel-104 commit 13c1c8ef3da5385cb8d0130bdf9c9abe0e43b49f Author: Volker Lendecke <v...@samba.org> Date: Sun Mar 27 17:43:11 2011 +0200 s3: Fix a memleak commit c83ce65ad099270c1edd119bb3d313a4638a0488 Author: Volker Lendecke <v...@samba.org> Date: Sun Mar 27 17:37:24 2011 +0200 s3: Replace a use of cli_errstr commit ffef3aa809eac020efd316c1922c50538d271a4f Author: Volker Lendecke <v...@samba.org> Date: Sun Mar 27 17:34:36 2011 +0200 s3: Replace cli_negprot_sendsync() by cli_negprot_send() commit a60ba5461855825c71e290f03fa1182210f87cae Author: Volker Lendecke <v...@samba.org> Date: Sun Mar 27 17:20:28 2011 +0200 s3: Remove a pointless static commit 5d9075c0498853010fb8036d4aa71bd6e1b284af Author: Volker Lendecke <v...@samba.org> Date: Sun Mar 27 17:04:56 2011 +0200 s3: Remove a use of cli_send_smb ----------------------------------------------------------------------- Summary of changes: source3/include/proto.h | 5 +- source3/libsmb/cliconnect.c | 81 +++++++++++----------------------------- source3/libsmb/clireadwrite.c | 83 +++++++++++++++++++++++------------------ source3/torture/torture.c | 36 ++++++++++++++--- 4 files changed, 100 insertions(+), 105 deletions(-) Changeset truncated at 500 lines: diff --git a/source3/include/proto.h b/source3/include/proto.h index a24b7d0..14ec2d6 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -1546,7 +1546,6 @@ struct tevent_req *cli_tdis_send(TALLOC_CTX *mem_ctx, struct cli_state *cli); NTSTATUS cli_tdis_recv(struct tevent_req *req); NTSTATUS cli_tdis(struct cli_state *cli); -void cli_negprot_sendsync(struct cli_state *cli); NTSTATUS cli_negprot(struct cli_state *cli); struct tevent_req *cli_negprot_send(TALLOC_CTX *mem_ctx, struct event_context *ev, @@ -2205,8 +2204,8 @@ ssize_t cli_read(struct cli_state *cli, uint16_t fnum, char *buf, ssize_t cli_write(struct cli_state *cli, uint16_t fnum, uint16 write_mode, const char *buf, off_t offset, size_t size); -ssize_t cli_smbwrite(struct cli_state *cli, - uint16_t fnum, char *buf, off_t offset, size_t size1); +NTSTATUS cli_smbwrite(struct cli_state *cli, uint16_t fnum, char *buf, + off_t offset, size_t size1, size_t *ptotal); struct tevent_req *cli_write_andx_create(TALLOC_CTX *mem_ctx, struct event_context *ev, struct cli_state *cli, uint16_t fnum, diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index 819d835..2fa9e8a 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -1913,41 +1913,6 @@ fail: Send a negprot command. ****************************************************************************/ -void cli_negprot_sendsync(struct cli_state *cli) -{ - char *p; - int numprots; - - if (cli->protocol < PROTOCOL_NT1) - cli->use_spnego = False; - - memset(cli->outbuf,'\0',smb_size); - - /* setup the protocol strings */ - cli_set_message(cli->outbuf,0,0,True); - - p = smb_buf(cli->outbuf); - for (numprots=0; numprots < ARRAY_SIZE(prots); numprots++) { - if (prots[numprots].prot > cli->protocol) { - break; - } - *p++ = 2; - p += clistr_push(cli, p, prots[numprots].name, -1, STR_TERMINATE); - } - - SCVAL(cli->outbuf,smb_com,SMBnegprot); - cli_setup_bcc(cli, p); - cli_setup_packet(cli); - - SCVAL(smb_buf(cli->outbuf),0,2); - - cli_send_smb(cli); -} - -/**************************************************************************** - Send a negprot command. -****************************************************************************/ - struct cli_negprot_state { struct cli_state *cli; }; @@ -2743,7 +2708,10 @@ NTSTATUS cli_raw_tcon(struct cli_state *cli, const char *service, const char *pass, const char *dev, uint16 *max_xmit, uint16 *tid) { - char *p; + struct tevent_req *req; + uint16_t *ret_vwv; + uint8_t *bytes; + NTSTATUS status; if (!lp_client_plaintext_auth() && (*pass)) { DEBUG(1, ("Server requested plaintext password but 'client " @@ -2751,31 +2719,26 @@ NTSTATUS cli_raw_tcon(struct cli_state *cli, return NT_STATUS_ACCESS_DENIED; } - memset(cli->outbuf,'\0',smb_size); - memset(cli->inbuf,'\0',smb_size); - - cli_set_message(cli->outbuf, 0, 0, True); - SCVAL(cli->outbuf,smb_com,SMBtcon); - cli_setup_packet(cli); - - p = smb_buf(cli->outbuf); - *p++ = 4; p += clistr_push(cli, p, service, -1, STR_TERMINATE | STR_NOALIGN); - *p++ = 4; p += clistr_push(cli, p, pass, -1, STR_TERMINATE | STR_NOALIGN); - *p++ = 4; p += clistr_push(cli, p, dev, -1, STR_TERMINATE | STR_NOALIGN); - - cli_setup_bcc(cli, p); - - cli_send_smb(cli); - if (!cli_receive_smb(cli)) { - return NT_STATUS_UNEXPECTED_NETWORK_ERROR; - } - - if (cli_is_error(cli)) { - return cli_nt_error(cli); + bytes = talloc_array(talloc_tos(), uint8_t, 0); + bytes = smb_bytes_push_bytes(bytes, 4, NULL, 0); + bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), + service, strlen(service)+1, NULL); + bytes = smb_bytes_push_bytes(bytes, 4, NULL, 0); + bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), + pass, strlen(pass)+1, NULL); + bytes = smb_bytes_push_bytes(bytes, 4, NULL, 0); + bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), + dev, strlen(dev)+1, NULL); + + status = cli_smb(talloc_tos(), cli, SMBtcon, 0, 0, NULL, + talloc_get_size(bytes), bytes, &req, + 2, NULL, &ret_vwv, NULL, NULL); + if (!NT_STATUS_IS_OK(status)) { + return status; } - *max_xmit = SVAL(cli->inbuf, smb_vwv0); - *tid = SVAL(cli->inbuf, smb_vwv1); + *max_xmit = SVAL(ret_vwv + 0, 0); + *tid = SVAL(ret_vwv + 1, 0); return NT_STATUS_OK; } diff --git a/source3/libsmb/clireadwrite.c b/source3/libsmb/clireadwrite.c index cd95b17..a6620d9 100644 --- a/source3/libsmb/clireadwrite.c +++ b/source3/libsmb/clireadwrite.c @@ -856,56 +856,67 @@ ssize_t cli_write(struct cli_state *cli, write to a file using a SMBwrite and not bypassing 0 byte writes ****************************************************************************/ -ssize_t cli_smbwrite(struct cli_state *cli, - uint16_t fnum, char *buf, off_t offset, size_t size1) +NTSTATUS cli_smbwrite(struct cli_state *cli, uint16_t fnum, char *buf, + off_t offset, size_t size1, size_t *ptotal) { - char *p; + uint8_t *bytes; ssize_t total = 0; - do { - size_t size = MIN(size1, cli->max_xmit - 48); - - memset(cli->outbuf,'\0',smb_size); - memset(cli->inbuf,'\0',smb_size); - - cli_set_message(cli->outbuf,5, 0,True); - - SCVAL(cli->outbuf,smb_com,SMBwrite); - SSVAL(cli->outbuf,smb_tid,cli->cnum); - cli_setup_packet(cli); - - SSVAL(cli->outbuf,smb_vwv0,fnum); - SSVAL(cli->outbuf,smb_vwv1,size); - SIVAL(cli->outbuf,smb_vwv2,offset); - SSVAL(cli->outbuf,smb_vwv4,0); - - p = smb_buf(cli->outbuf); - *p++ = 1; - SSVAL(p, 0, size); p += 2; - memcpy(p, buf + total, size); p += size; - - cli_setup_bcc(cli, p); + /* + * 3 bytes prefix + */ - if (!cli_send_smb(cli)) - return -1; + bytes = TALLOC_ARRAY(talloc_tos(), uint8_t, 3); + if (bytes == NULL) { + return NT_STATUS_NO_MEMORY; + } + bytes[0] = 1; - if (!cli_receive_smb(cli)) - return -1; + do { + size_t size = MIN(size1, cli->max_xmit - 48); + struct tevent_req *req; + uint16_t vwv[5]; + uint16_t *ret_vwv; + NTSTATUS status; + + SSVAL(vwv+0, 0, fnum); + SSVAL(vwv+1, 0, size); + SIVAL(vwv+2, 0, offset); + SSVAL(vwv+4, 0, 0); + + bytes = TALLOC_REALLOC_ARRAY(talloc_tos(), bytes, uint8_t, + size+3); + if (bytes == NULL) { + return NT_STATUS_NO_MEMORY; + } + SSVAL(bytes, 1, size); + memcpy(bytes + 3, buf + total, size); - if (cli_is_error(cli)) - return -1; + status = cli_smb(talloc_tos(), cli, SMBwrite, 0, 5, vwv, + size+3, bytes, &req, 1, NULL, &ret_vwv, + NULL, NULL); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(bytes); + return status; + } - size = SVAL(cli->inbuf,smb_vwv0); - if (size == 0) + size = SVAL(ret_vwv+0, 0); + TALLOC_FREE(req); + if (size == 0) { break; - + } size1 -= size; total += size; offset += size; } while (size1); - return total; + TALLOC_FREE(bytes); + + if (ptotal != NULL) { + *ptotal = total; + } + return NT_STATUS_OK; } /* diff --git a/source3/torture/torture.c b/source3/torture/torture.c index 61cfb9e..66433ec 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -961,7 +961,7 @@ static bool run_readwritelarge_internal(int max_xmit_k) cli1->max_xmit = 4*1024; - cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf)); + cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf), NULL); if (!NT_STATUS_IS_OK(cli_qfileinfo_basic( cli1, fnum1, NULL, &fsize, NULL, NULL, @@ -1389,11 +1389,13 @@ static bool run_tcon2_test(int dummy) status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum); + SAFE_FREE(service); + if (!NT_STATUS_IS_OK(status)) { - printf("tcon2 failed : %s\n", cli_errstr(cli)); + printf("tcon2 failed : %s\n", nt_errstr(status)); } else { - printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n", - (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid)); + printf("tcon OK : max_xmit=%d cnum=%d\n", + (int)max_xmit, (int)cnum); } if (!torture_close_connection(cli)) { @@ -2776,21 +2778,41 @@ static void rand_buf(char *buf, int len) /* send smb negprot commands, not reading the response */ static bool run_negprot_nowait(int dummy) { + struct tevent_context *ev; int i; - static struct cli_state *cli; + struct cli_state *cli; bool correct = True; printf("starting negprot nowait test\n"); + ev = tevent_context_init(talloc_tos()); + if (ev == NULL) { + return false; + } + if (!(cli = open_nbt_connection())) { + TALLOC_FREE(ev); return False; } for (i=0;i<50000;i++) { - cli_negprot_sendsync(cli); + struct tevent_req *req; + + req = cli_negprot_send(ev, ev, cli); + if (req == NULL) { + TALLOC_FREE(ev); + return false; + } + if (!tevent_req_poll(req, ev)) { + d_fprintf(stderr, "tevent_req_poll failed: %s\n", + strerror(errno)); + TALLOC_FREE(ev); + return false; + } + TALLOC_FREE(req); } - if (!torture_close_connection(cli)) { + if (torture_close_connection(cli)) { correct = False; } -- Samba Shared Repository