Changeset 740 for vendor/current/source3/libsmb/clientgen.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/libsmb/clientgen.c
r427 r740 20 20 21 21 #include "includes.h" 22 #include "libsmb/libsmb.h" 23 #include "../lib/util/tevent_ntstatus.h" 24 #include "smb_signing.h" 25 #include "async_smb.h" 22 26 23 27 /******************************************************************* … … 247 251 /* If the server is not responding, note that now */ 248 252 if (len < 0) { 249 DEBUG(0, ("Receiving SMB: Server stopped responding\n")); 250 close(cli->fd); 251 cli->fd = -1; 253 /* 254 * only log if the connection should still be open and not when 255 * the connection was closed due to a dropped ip message 256 */ 257 if (cli->fd != -1) { 258 char addr[INET6_ADDRSTRLEN]; 259 print_sockaddr(addr, sizeof(addr), &cli->dest_ss); 260 DEBUG(0, ("Receiving SMB: Server %s stopped responding\n", 261 addr)); 262 close(cli->fd); 263 cli->fd = -1; 264 } 252 265 return false; 253 266 } … … 286 299 } 287 300 288 /****************************************************************************289 Read the data portion of a readX smb.290 The timeout is in milliseconds291 ****************************************************************************/292 293 ssize_t cli_receive_smb_data(struct cli_state *cli, char *buffer, size_t len)294 {295 NTSTATUS status;296 297 set_smb_read_error(&cli->smb_rw_error, SMB_READ_OK);298 299 status = read_fd_with_timeout(300 cli->fd, buffer, len, len, cli->timeout, NULL);301 if (NT_STATUS_IS_OK(status)) {302 return len;303 }304 305 if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {306 set_smb_read_error(&cli->smb_rw_error, SMB_READ_EOF);307 return -1;308 }309 310 if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {311 set_smb_read_error(&cli->smb_rw_error, SMB_READ_TIMEOUT);312 return -1;313 }314 315 set_smb_read_error(&cli->smb_rw_error, SMB_READ_ERROR);316 return -1;317 }318 319 301 static ssize_t write_socket(int fd, const char *buf, size_t len) 320 302 { … … 391 373 if (enc_on) { 392 374 cli_free_enc_buffer(cli, buf_out); 393 }394 395 /* Increment the mid so we can tell between responses. */396 cli->mid++;397 if (!cli->mid)398 cli->mid++;399 return true;400 }401 402 /****************************************************************************403 Send a "direct" writeX smb to a fd.404 ****************************************************************************/405 406 bool cli_send_smb_direct_writeX(struct cli_state *cli,407 const char *p,408 size_t extradata)409 {410 /* First length to send is the offset to the data. */411 size_t len = SVAL(cli->outbuf,smb_vwv11) + 4;412 size_t nwritten=0;413 struct iovec iov[2];414 415 /* fd == -1 causes segfaults -- Tom (tom@ninja.nl) */416 if (cli->fd == -1) {417 return false;418 }419 420 if (client_is_signing_on(cli)) {421 DEBUG(0,("cli_send_smb_large: cannot send signed packet.\n"));422 return false;423 }424 425 iov[0].iov_base = (void *)cli->outbuf;426 iov[0].iov_len = len;427 iov[1].iov_base = CONST_DISCARD(void *, p);428 iov[1].iov_len = extradata;429 430 nwritten = write_data_iov(cli->fd, iov, 2);431 if (nwritten < (len + extradata)) {432 close(cli->fd);433 cli->fd = -1;434 cli->smb_rw_error = SMB_WRITE_ERROR;435 DEBUG(0,("Error writing %d bytes to client. (%s)\n",436 (int)(len+extradata), strerror(errno)));437 return false;438 375 } 439 376 … … 639 576 #if defined(DEVELOPER) 640 577 /* just because we over-allocate, doesn't mean it's right to use it */ 641 clobber_region( FUNCTION_MACRO, __LINE__, cli->outbuf+cli->bufsize, SAFETY_MARGIN);642 clobber_region( FUNCTION_MACRO, __LINE__, cli->inbuf+cli->bufsize, SAFETY_MARGIN);578 clobber_region(__FUNCTION__, __LINE__, cli->outbuf+cli->bufsize, SAFETY_MARGIN); 579 clobber_region(__FUNCTION__, __LINE__, cli->inbuf+cli->bufsize, SAFETY_MARGIN); 643 580 #endif 644 581 … … 694 631 ****************************************************************************/ 695 632 696 void cli_shutdown(struct cli_state *cli) 697 { 698 if (cli == NULL) { 699 return; 700 } 701 702 if (cli->prev == NULL) { 703 /* 704 * Possible head of a DFS list, 705 * shutdown all subsidiary DFS 706 * connections. 707 */ 708 struct cli_state *p, *next; 709 710 for (p = cli->next; p; p = next) { 711 next = p->next; 712 cli_shutdown(p); 713 } 714 } else { 715 /* 716 * We're a subsidiary connection. 717 * Just remove ourselves from the 718 * DFS list. 719 */ 720 DLIST_REMOVE(cli->prev, cli); 721 } 722 633 static void _cli_shutdown(struct cli_state *cli) 634 { 723 635 cli_nt_pipes_close(cli); 724 636 … … 760 672 } 761 673 674 void cli_shutdown(struct cli_state *cli) 675 { 676 struct cli_state *cli_head; 677 if (cli == NULL) { 678 return; 679 } 680 DLIST_HEAD(cli, cli_head); 681 if (cli_head == cli) { 682 /* 683 * head of a DFS list, shutdown all subsidiary DFS 684 * connections. 685 */ 686 struct cli_state *p, *next; 687 688 for (p = cli_head->next; p; p = next) { 689 next = p->next; 690 DLIST_REMOVE(cli_head, p); 691 _cli_shutdown(p); 692 } 693 } else { 694 DLIST_REMOVE(cli_head, cli); 695 } 696 697 _cli_shutdown(cli); 698 } 699 762 700 /**************************************************************************** 763 701 Set socket options on a open connection. … … 789 727 cli->case_sensitive = case_sensitive; 790 728 return ret; 791 }792 793 /****************************************************************************794 Send a keepalive packet to the server795 ****************************************************************************/796 797 bool cli_send_keepalive(struct cli_state *cli)798 {799 if (cli->fd == -1) {800 DEBUG(3, ("cli_send_keepalive: fd == -1\n"));801 return false;802 }803 if (!send_keepalive(cli->fd)) {804 close(cli->fd);805 cli->fd = -1;806 DEBUG(0,("Error sending keepalive packet to client.\n"));807 return false;808 }809 return true;810 729 } 811 730 … … 854 773 uint32_t num_bytes; 855 774 uint8_t *bytes; 856 857 status = cli_smb_recv(subreq, 0, NULL, NULL, &num_bytes, &bytes); 775 uint8_t *inbuf; 776 777 status = cli_smb_recv(subreq, state, &inbuf, 0, NULL, NULL, 778 &num_bytes, &bytes); 858 779 if (!NT_STATUS_IS_OK(status)) { 859 780 tevent_req_nterror(req, status); … … 964 885 return false; 965 886 } 887 888 NTSTATUS cli_smb(TALLOC_CTX *mem_ctx, struct cli_state *cli, 889 uint8_t smb_command, uint8_t additional_flags, 890 uint8_t wct, uint16_t *vwv, 891 uint32_t num_bytes, const uint8_t *bytes, 892 struct tevent_req **result_parent, 893 uint8_t min_wct, uint8_t *pwct, uint16_t **pvwv, 894 uint32_t *pnum_bytes, uint8_t **pbytes) 895 { 896 struct tevent_context *ev; 897 struct tevent_req *req = NULL; 898 NTSTATUS status = NT_STATUS_NO_MEMORY; 899 900 if (cli_has_async_calls(cli)) { 901 return NT_STATUS_INVALID_PARAMETER; 902 } 903 ev = tevent_context_init(mem_ctx); 904 if (ev == NULL) { 905 goto fail; 906 } 907 req = cli_smb_send(mem_ctx, ev, cli, smb_command, additional_flags, 908 wct, vwv, num_bytes, bytes); 909 if (req == NULL) { 910 goto fail; 911 } 912 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 913 goto fail; 914 } 915 status = cli_smb_recv(req, NULL, NULL, min_wct, pwct, pvwv, 916 pnum_bytes, pbytes); 917 fail: 918 TALLOC_FREE(ev); 919 if (NT_STATUS_IS_OK(status) && (result_parent != NULL)) { 920 *result_parent = req; 921 } 922 return status; 923 }
Note:
See TracChangeset
for help on using the changeset viewer.