Changeset 745 for trunk/server/source3/libsmb/clientgen.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/libsmb/clientgen.c
r656 r745 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 … … 641 578 #if defined(DEVELOPER) 642 579 /* just because we over-allocate, doesn't mean it's right to use it */ 643 clobber_region( FUNCTION_MACRO, __LINE__, cli->outbuf+cli->bufsize, SAFETY_MARGIN);644 clobber_region( FUNCTION_MACRO, __LINE__, cli->inbuf+cli->bufsize, SAFETY_MARGIN);580 clobber_region(__FUNCTION__, __LINE__, cli->outbuf+cli->bufsize, SAFETY_MARGIN); 581 clobber_region(__FUNCTION__, __LINE__, cli->inbuf+cli->bufsize, SAFETY_MARGIN); 645 582 #endif 646 583 … … 696 633 ****************************************************************************/ 697 634 698 void cli_shutdown(struct cli_state *cli) 699 { 700 if (cli == NULL) { 701 return; 702 } 703 704 if (cli->prev == NULL) { 705 /* 706 * Possible head of a DFS list, 707 * shutdown all subsidiary DFS 708 * connections. 709 */ 710 struct cli_state *p, *next; 711 712 for (p = cli->next; p; p = next) { 713 next = p->next; 714 cli_shutdown(p); 715 } 716 } else { 717 /* 718 * We're a subsidiary connection. 719 * Just remove ourselves from the 720 * DFS list. 721 */ 722 DLIST_REMOVE(cli->prev, cli); 723 } 724 635 static void _cli_shutdown(struct cli_state *cli) 636 { 725 637 cli_nt_pipes_close(cli); 726 638 … … 762 674 } 763 675 676 void cli_shutdown(struct cli_state *cli) 677 { 678 struct cli_state *cli_head; 679 if (cli == NULL) { 680 return; 681 } 682 DLIST_HEAD(cli, cli_head); 683 if (cli_head == cli) { 684 /* 685 * head of a DFS list, shutdown all subsidiary DFS 686 * connections. 687 */ 688 struct cli_state *p, *next; 689 690 for (p = cli_head->next; p; p = next) { 691 next = p->next; 692 DLIST_REMOVE(cli_head, p); 693 _cli_shutdown(p); 694 } 695 } else { 696 DLIST_REMOVE(cli_head, cli); 697 } 698 699 _cli_shutdown(cli); 700 } 701 764 702 /**************************************************************************** 765 703 Set socket options on a open connection. … … 791 729 cli->case_sensitive = case_sensitive; 792 730 return ret; 793 }794 795 /****************************************************************************796 Send a keepalive packet to the server797 ****************************************************************************/798 799 bool cli_send_keepalive(struct cli_state *cli)800 {801 if (cli->fd == -1) {802 DEBUG(3, ("cli_send_keepalive: fd == -1\n"));803 return false;804 }805 if (!send_keepalive(cli->fd)) {806 close(cli->fd);807 cli->fd = -1;808 DEBUG(0,("Error sending keepalive packet to client.\n"));809 return false;810 }811 return true;812 731 } 813 732 … … 856 775 uint32_t num_bytes; 857 776 uint8_t *bytes; 858 859 status = cli_smb_recv(subreq, 0, NULL, NULL, &num_bytes, &bytes); 777 uint8_t *inbuf; 778 779 status = cli_smb_recv(subreq, state, &inbuf, 0, NULL, NULL, 780 &num_bytes, &bytes); 860 781 if (!NT_STATUS_IS_OK(status)) { 861 782 tevent_req_nterror(req, status); … … 966 887 return false; 967 888 } 889 890 NTSTATUS cli_smb(TALLOC_CTX *mem_ctx, struct cli_state *cli, 891 uint8_t smb_command, uint8_t additional_flags, 892 uint8_t wct, uint16_t *vwv, 893 uint32_t num_bytes, const uint8_t *bytes, 894 struct tevent_req **result_parent, 895 uint8_t min_wct, uint8_t *pwct, uint16_t **pvwv, 896 uint32_t *pnum_bytes, uint8_t **pbytes) 897 { 898 struct tevent_context *ev; 899 struct tevent_req *req = NULL; 900 NTSTATUS status = NT_STATUS_NO_MEMORY; 901 902 if (cli_has_async_calls(cli)) { 903 return NT_STATUS_INVALID_PARAMETER; 904 } 905 ev = tevent_context_init(mem_ctx); 906 if (ev == NULL) { 907 goto fail; 908 } 909 req = cli_smb_send(mem_ctx, ev, cli, smb_command, additional_flags, 910 wct, vwv, num_bytes, bytes); 911 if (req == NULL) { 912 goto fail; 913 } 914 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 915 goto fail; 916 } 917 status = cli_smb_recv(req, NULL, NULL, min_wct, pwct, pvwv, 918 pnum_bytes, pbytes); 919 fail: 920 TALLOC_FREE(ev); 921 if (NT_STATUS_IS_OK(status) && (result_parent != NULL)) { 922 *result_parent = req; 923 } 924 return status; 925 }
Note:
See TracChangeset
for help on using the changeset viewer.