Changeset 988 for vendor/current/source3/libsmb/clifile.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/libsmb/clifile.c
r746 r988 27 27 #include "trans2.h" 28 28 #include "ntioctl.h" 29 #include "libcli/security/secdesc.h" 30 #include "../libcli/smb/smbXcli_base.h" 29 31 30 32 /*********************************************************** … … 49 51 buflen = talloc_get_size(buf); 50 52 51 if (align_odd && ucs2 && (buflen % 2 == 0)) { 53 if (ucs2 && 54 ((align_odd && (buflen % 2 == 0)) || 55 (!align_odd && (buflen % 2 == 1)))) { 52 56 /* 53 57 * We're pushing into an SMB buffer, align odd 54 58 */ 55 buf = TALLOC_REALLOC_ARRAY(NULL, buf, uint8_t, buflen + 1);59 buf = talloc_realloc(NULL, buf, uint8_t, buflen + 1); 56 60 if (buf == NULL) { 57 61 return NULL; … … 64 68 ucs2 ? CH_UTF16LE : CH_DOS, 65 69 str, str_len, &converted, 66 &converted_size , true)) {70 &converted_size)) { 67 71 return NULL; 68 72 } 69 73 70 buf = TALLOC_REALLOC_ARRAY(NULL, buf, uint8_t,74 buf = talloc_realloc(NULL, buf, uint8_t, 71 75 buflen + converted_size); 72 76 if (buf == NULL) { … … 109 113 buflen = talloc_get_size(buf); 110 114 111 buf = TALLOC_REALLOC_ARRAY(NULL, buf, uint8_t,115 buf = talloc_realloc(NULL, buf, uint8_t, 112 116 buflen + 1 + num_bytes); 113 117 if (buf == NULL) { … … 126 130 ***********************************************************/ 127 131 128 staticuint8_t *trans2_bytes_push_str(uint8_t *buf, bool ucs2,129 const char *str, size_t str_len,130 size_t *pconverted_size)132 uint8_t *trans2_bytes_push_str(uint8_t *buf, bool ucs2, 133 const char *str, size_t str_len, 134 size_t *pconverted_size) 131 135 { 132 136 return internal_bytes_push_str(buf, ucs2, str, str_len, 133 137 false, pconverted_size); 138 } 139 140 uint8_t *trans2_bytes_push_bytes(uint8_t *buf, 141 const uint8_t *bytes, size_t num_bytes) 142 { 143 size_t buflen; 144 145 if (buf == NULL) { 146 return NULL; 147 } 148 buflen = talloc_get_size(buf); 149 150 buf = talloc_realloc(NULL, buf, uint8_t, 151 buflen + num_bytes); 152 if (buf == NULL) { 153 return NULL; 154 } 155 memcpy(&buf[buflen], bytes, num_bytes); 156 return buf; 134 157 } 135 158 … … 162 185 163 186 /* Setup param array. */ 164 state->param = TALLOC_ZERO_ARRAY(state, uint8_t, 6);187 state->param = talloc_zero_array(state, uint8_t, 6); 165 188 if (tevent_req_nomem(state->param, req)) { 166 189 return tevent_req_post(req, ev); … … 169 192 170 193 state->param = trans2_bytes_push_str( 171 state->param, cli_ucs2(cli), path, strlen(path)+1, NULL);194 state->param, smbXcli_conn_use_unicode(cli->conn), path, strlen(path)+1, NULL); 172 195 if (tevent_req_nomem(state->param, req)) { 173 196 return tevent_req_post(req, ev); … … 223 246 NTSTATUS status = NT_STATUS_NO_MEMORY; 224 247 225 if ( cli_has_async_calls(cli)) {248 if (smbXcli_conn_has_async_calls(cli->conn)) { 226 249 /* 227 250 * Can't use sync call while an async call is in flight … … 230 253 goto fail; 231 254 } 232 ev = tevent_context_init(frame);255 ev = samba_tevent_context_init(frame); 233 256 if (ev == NULL) { 234 257 goto fail; … … 259 282 260 283 static struct tevent_req *cli_posix_link_internal_send(TALLOC_CTX *mem_ctx, 261 struct event_context *ev,284 struct tevent_context *ev, 262 285 struct cli_state *cli, 263 286 uint16_t level, … … 280 303 } 281 304 state->data = trans2_bytes_push_str( 282 state->data, cli_ucs2(cli), oldname, strlen(oldname)+1, NULL);305 state->data, smbXcli_conn_use_unicode(cli->conn), oldname, strlen(oldname)+1, NULL); 283 306 284 307 subreq = cli_setpathinfo_send( … … 303 326 304 327 struct tevent_req *cli_posix_symlink_send(TALLOC_CTX *mem_ctx, 305 struct event_context *ev,328 struct tevent_context *ev, 306 329 struct cli_state *cli, 307 330 const char *oldname, … … 322 345 { 323 346 TALLOC_CTX *frame = talloc_stackframe(); 324 struct event_context *ev = NULL;347 struct tevent_context *ev = NULL; 325 348 struct tevent_req *req = NULL; 326 349 NTSTATUS status = NT_STATUS_OK; 327 350 328 if ( cli_has_async_calls(cli)) {351 if (smbXcli_conn_has_async_calls(cli->conn)) { 329 352 /* 330 353 * Can't use sync call while an async call is in flight … … 334 357 } 335 358 336 ev = event_context_init(frame);359 ev = samba_tevent_context_init(frame); 337 360 if (ev == NULL) { 338 361 status = NT_STATUS_NO_MEMORY; … … 350 373 } 351 374 352 if (!tevent_req_poll(req, ev)) { 353 status = map_nt_error_from_unix(errno); 375 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 354 376 goto fail; 355 377 } … … 374 396 375 397 struct tevent_req *cli_posix_readlink_send(TALLOC_CTX *mem_ctx, 376 struct event_context *ev,398 struct tevent_context *ev, 377 399 struct cli_state *cli, 378 400 const char *fname, … … 381 403 struct tevent_req *req = NULL, *subreq = NULL; 382 404 struct readlink_state *state = NULL; 383 uint32_t maxbytelen = (uint32_t)( cli_ucs2(cli) ? len*3 : len);405 uint32_t maxbytelen = (uint32_t)(smbXcli_conn_use_unicode(cli->conn) ? len*3 : len); 384 406 385 407 req = tevent_req_create(mem_ctx, &state, struct readlink_state); … … 442 464 /* The returned data is a pushed string, not raw data. */ 443 465 if (!convert_string_talloc(state, 444 cli_ucs2(cli) ? CH_UTF16LE : CH_DOS,466 smbXcli_conn_use_unicode(cli->conn) ? CH_UTF16LE : CH_DOS, 445 467 CH_UNIX, 446 468 state->data, 447 469 state->num_data, 448 470 &converted, 449 &converted_size, 450 true)) { 471 &converted_size)) { 451 472 return NT_STATUS_NO_MEMORY; 452 473 } … … 464 485 { 465 486 TALLOC_CTX *frame = talloc_stackframe(); 466 struct event_context *ev = NULL;487 struct tevent_context *ev = NULL; 467 488 struct tevent_req *req = NULL; 468 489 NTSTATUS status = NT_STATUS_OK; 469 490 470 if ( cli_has_async_calls(cli)) {491 if (smbXcli_conn_has_async_calls(cli->conn)) { 471 492 /* 472 493 * Can't use sync call while an async call is in flight … … 476 497 } 477 498 478 ev = event_context_init(frame);499 ev = samba_tevent_context_init(frame); 479 500 if (ev == NULL) { 480 501 status = NT_STATUS_NO_MEMORY; … … 492 513 } 493 514 494 if (!tevent_req_poll(req, ev)) { 495 status = map_nt_error_from_unix(errno); 515 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 496 516 goto fail; 497 517 } … … 509 529 510 530 struct tevent_req *cli_posix_hardlink_send(TALLOC_CTX *mem_ctx, 511 struct event_context *ev,531 struct tevent_context *ev, 512 532 struct cli_state *cli, 513 533 const char *oldname, … … 528 548 { 529 549 TALLOC_CTX *frame = talloc_stackframe(); 530 struct event_context *ev = NULL;550 struct tevent_context *ev = NULL; 531 551 struct tevent_req *req = NULL; 532 552 NTSTATUS status = NT_STATUS_OK; 533 553 534 if ( cli_has_async_calls(cli)) {554 if (smbXcli_conn_has_async_calls(cli->conn)) { 535 555 /* 536 556 * Can't use sync call while an async call is in flight … … 540 560 } 541 561 542 ev = event_context_init(frame);562 ev = samba_tevent_context_init(frame); 543 563 if (ev == NULL) { 544 564 status = NT_STATUS_NO_MEMORY; … … 556 576 } 557 577 558 if (!tevent_req_poll(req, ev)) { 559 status = map_nt_error_from_unix(errno); 578 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 560 579 goto fail; 561 580 } … … 569 588 570 589 /**************************************************************************** 571 Map standard UNIX permissions onto wire representations.590 Do a POSIX getacl - pathname based ACL get (UNIX extensions). 572 591 ****************************************************************************/ 573 592 574 uint32_t unix_perms_to_wire(mode_t perms) 575 { 576 unsigned int ret = 0; 577 578 ret |= ((perms & S_IXOTH) ? UNIX_X_OTH : 0); 579 ret |= ((perms & S_IWOTH) ? UNIX_W_OTH : 0); 580 ret |= ((perms & S_IROTH) ? UNIX_R_OTH : 0); 581 ret |= ((perms & S_IXGRP) ? UNIX_X_GRP : 0); 582 ret |= ((perms & S_IWGRP) ? UNIX_W_GRP : 0); 583 ret |= ((perms & S_IRGRP) ? UNIX_R_GRP : 0); 584 ret |= ((perms & S_IXUSR) ? UNIX_X_USR : 0); 585 ret |= ((perms & S_IWUSR) ? UNIX_W_USR : 0); 586 ret |= ((perms & S_IRUSR) ? UNIX_R_USR : 0); 587 #ifdef S_ISVTX 588 ret |= ((perms & S_ISVTX) ? UNIX_STICKY : 0); 589 #endif 590 #ifdef S_ISGID 591 ret |= ((perms & S_ISGID) ? UNIX_SET_GID : 0); 592 #endif 593 #ifdef S_ISUID 594 ret |= ((perms & S_ISUID) ? UNIX_SET_UID : 0); 595 #endif 596 return ret; 597 } 598 599 /**************************************************************************** 600 Map wire permissions to standard UNIX. 601 ****************************************************************************/ 602 603 mode_t wire_perms_to_unix(uint32_t perms) 604 { 605 mode_t ret = (mode_t)0; 606 607 ret |= ((perms & UNIX_X_OTH) ? S_IXOTH : 0); 608 ret |= ((perms & UNIX_W_OTH) ? S_IWOTH : 0); 609 ret |= ((perms & UNIX_R_OTH) ? S_IROTH : 0); 610 ret |= ((perms & UNIX_X_GRP) ? S_IXGRP : 0); 611 ret |= ((perms & UNIX_W_GRP) ? S_IWGRP : 0); 612 ret |= ((perms & UNIX_R_GRP) ? S_IRGRP : 0); 613 ret |= ((perms & UNIX_X_USR) ? S_IXUSR : 0); 614 ret |= ((perms & UNIX_W_USR) ? S_IWUSR : 0); 615 ret |= ((perms & UNIX_R_USR) ? S_IRUSR : 0); 616 #ifdef S_ISVTX 617 ret |= ((perms & UNIX_STICKY) ? S_ISVTX : 0); 618 #endif 619 #ifdef S_ISGID 620 ret |= ((perms & UNIX_SET_GID) ? S_ISGID : 0); 621 #endif 622 #ifdef S_ISUID 623 ret |= ((perms & UNIX_SET_UID) ? S_ISUID : 0); 624 #endif 625 return ret; 626 } 627 628 /**************************************************************************** 629 Return the file type from the wire filetype for UNIX extensions. 630 ****************************************************************************/ 631 632 static mode_t unix_filetype_from_wire(uint32_t wire_type) 633 { 634 switch (wire_type) { 635 case UNIX_TYPE_FILE: 636 return S_IFREG; 637 case UNIX_TYPE_DIR: 638 return S_IFDIR; 639 #ifdef S_IFLNK 640 case UNIX_TYPE_SYMLINK: 641 return S_IFLNK; 642 #endif 643 #ifdef S_IFCHR 644 case UNIX_TYPE_CHARDEV: 645 return S_IFCHR; 646 #endif 647 #ifdef S_IFBLK 648 case UNIX_TYPE_BLKDEV: 649 return S_IFBLK; 650 #endif 651 #ifdef S_IFIFO 652 case UNIX_TYPE_FIFO: 653 return S_IFIFO; 654 #endif 655 #ifdef S_IFSOCK 656 case UNIX_TYPE_SOCKET: 657 return S_IFSOCK; 658 #endif 659 default: 660 return (mode_t)0; 661 } 662 } 663 664 /**************************************************************************** 665 Do a POSIX getfacl (UNIX extensions). 666 ****************************************************************************/ 667 668 struct getfacl_state { 593 struct getacl_state { 669 594 uint32_t num_data; 670 595 uint8_t *data; 671 596 }; 672 597 673 static void cli_posix_get facl_done(struct tevent_req *subreq);674 675 struct tevent_req *cli_posix_get facl_send(TALLOC_CTX *mem_ctx,676 struct event_context *ev,598 static void cli_posix_getacl_done(struct tevent_req *subreq); 599 600 struct tevent_req *cli_posix_getacl_send(TALLOC_CTX *mem_ctx, 601 struct tevent_context *ev, 677 602 struct cli_state *cli, 678 603 const char *fname) 679 604 { 680 605 struct tevent_req *req = NULL, *subreq = NULL; 681 struct get facl_state *state = NULL;682 683 req = tevent_req_create(mem_ctx, &state, struct get facl_state);606 struct getacl_state *state = NULL; 607 608 req = tevent_req_create(mem_ctx, &state, struct getacl_state); 684 609 if (req == NULL) { 685 610 return NULL; 686 611 } 687 612 subreq = cli_qpathinfo_send(state, ev, cli, fname, SMB_QUERY_POSIX_ACL, 688 0, cli->max_xmit);613 0, CLI_BUFFER_SIZE); 689 614 if (tevent_req_nomem(subreq, req)) { 690 615 return tevent_req_post(req, ev); 691 616 } 692 tevent_req_set_callback(subreq, cli_posix_get facl_done, req);617 tevent_req_set_callback(subreq, cli_posix_getacl_done, req); 693 618 return req; 694 619 } 695 620 696 static void cli_posix_get facl_done(struct tevent_req *subreq)621 static void cli_posix_getacl_done(struct tevent_req *subreq) 697 622 { 698 623 struct tevent_req *req = tevent_req_callback_data( 699 624 subreq, struct tevent_req); 700 struct get facl_state *state = tevent_req_data(701 req, struct get facl_state);625 struct getacl_state *state = tevent_req_data( 626 req, struct getacl_state); 702 627 NTSTATUS status; 703 628 … … 711 636 } 712 637 713 NTSTATUS cli_posix_get facl_recv(struct tevent_req *req,638 NTSTATUS cli_posix_getacl_recv(struct tevent_req *req, 714 639 TALLOC_CTX *mem_ctx, 715 640 size_t *prb_size, 716 641 char **retbuf) 717 642 { 718 struct get facl_state *state = tevent_req_data(req, struct getfacl_state);643 struct getacl_state *state = tevent_req_data(req, struct getacl_state); 719 644 NTSTATUS status; 720 645 … … 727 652 } 728 653 729 NTSTATUS cli_posix_get facl(struct cli_state *cli,654 NTSTATUS cli_posix_getacl(struct cli_state *cli, 730 655 const char *fname, 731 656 TALLOC_CTX *mem_ctx, … … 734 659 { 735 660 TALLOC_CTX *frame = talloc_stackframe(); 736 struct event_context *ev = NULL;661 struct tevent_context *ev = NULL; 737 662 struct tevent_req *req = NULL; 738 663 NTSTATUS status = NT_STATUS_OK; 739 664 740 if ( cli_has_async_calls(cli)) {665 if (smbXcli_conn_has_async_calls(cli->conn)) { 741 666 /* 742 667 * Can't use sync call while an async call is in flight … … 746 671 } 747 672 748 ev = event_context_init(frame);673 ev = samba_tevent_context_init(frame); 749 674 if (ev == NULL) { 750 675 status = NT_STATUS_NO_MEMORY; … … 752 677 } 753 678 754 req = cli_posix_get facl_send(frame,679 req = cli_posix_getacl_send(frame, 755 680 ev, 756 681 cli, … … 761 686 } 762 687 763 if (!tevent_req_poll(req, ev)) { 764 status = map_nt_error_from_unix(errno); 765 goto fail; 766 } 767 768 status = cli_posix_getfacl_recv(req, mem_ctx, prb_size, retbuf); 688 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 689 goto fail; 690 } 691 692 status = cli_posix_getacl_recv(req, mem_ctx, prb_size, retbuf); 693 694 fail: 695 TALLOC_FREE(frame); 696 return status; 697 } 698 699 /**************************************************************************** 700 Do a POSIX setacl - pathname based ACL set (UNIX extensions). 701 ****************************************************************************/ 702 703 struct setacl_state { 704 uint8_t *data; 705 }; 706 707 static void cli_posix_setacl_done(struct tevent_req *subreq); 708 709 struct tevent_req *cli_posix_setacl_send(TALLOC_CTX *mem_ctx, 710 struct tevent_context *ev, 711 struct cli_state *cli, 712 const char *fname, 713 const void *data, 714 size_t num_data) 715 { 716 struct tevent_req *req = NULL, *subreq = NULL; 717 struct setacl_state *state = NULL; 718 719 req = tevent_req_create(mem_ctx, &state, struct setacl_state); 720 if (req == NULL) { 721 return NULL; 722 } 723 state->data = talloc_memdup(state, data, num_data); 724 if (tevent_req_nomem(state->data, req)) { 725 return tevent_req_post(req, ev); 726 } 727 728 subreq = cli_setpathinfo_send(state, 729 ev, 730 cli, 731 SMB_SET_POSIX_ACL, 732 fname, 733 state->data, 734 num_data); 735 if (tevent_req_nomem(subreq, req)) { 736 return tevent_req_post(req, ev); 737 } 738 tevent_req_set_callback(subreq, cli_posix_setacl_done, req); 739 return req; 740 } 741 742 static void cli_posix_setacl_done(struct tevent_req *subreq) 743 { 744 NTSTATUS status = cli_setpathinfo_recv(subreq); 745 tevent_req_simple_finish_ntstatus(subreq, status); 746 } 747 748 NTSTATUS cli_posix_setacl_recv(struct tevent_req *req) 749 { 750 return tevent_req_simple_recv_ntstatus(req); 751 } 752 753 NTSTATUS cli_posix_setacl(struct cli_state *cli, 754 const char *fname, 755 const void *acl_buf, 756 size_t acl_buf_size) 757 { 758 TALLOC_CTX *frame = talloc_stackframe(); 759 struct tevent_context *ev = NULL; 760 struct tevent_req *req = NULL; 761 NTSTATUS status = NT_STATUS_OK; 762 763 if (smbXcli_conn_has_async_calls(cli->conn)) { 764 /* 765 * Can't use sync call while an async call is in flight 766 */ 767 status = NT_STATUS_INVALID_PARAMETER; 768 goto fail; 769 } 770 771 ev = samba_tevent_context_init(frame); 772 if (ev == NULL) { 773 status = NT_STATUS_NO_MEMORY; 774 goto fail; 775 } 776 777 req = cli_posix_setacl_send(frame, 778 ev, 779 cli, 780 fname, 781 acl_buf, 782 acl_buf_size); 783 if (req == NULL) { 784 status = NT_STATUS_NO_MEMORY; 785 goto fail; 786 } 787 788 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 789 goto fail; 790 } 791 792 status = cli_posix_setacl_recv(req); 769 793 770 794 fail: … … 785 809 786 810 struct tevent_req *cli_posix_stat_send(TALLOC_CTX *mem_ctx, 787 struct event_context *ev,811 struct tevent_context *ev, 788 812 struct cli_state *cli, 789 813 const char *fname) … … 865 889 { 866 890 TALLOC_CTX *frame = talloc_stackframe(); 867 struct event_context *ev = NULL;891 struct tevent_context *ev = NULL; 868 892 struct tevent_req *req = NULL; 869 893 NTSTATUS status = NT_STATUS_OK; 870 894 871 if ( cli_has_async_calls(cli)) {895 if (smbXcli_conn_has_async_calls(cli->conn)) { 872 896 /* 873 897 * Can't use sync call while an async call is in flight … … 877 901 } 878 902 879 ev = event_context_init(frame);903 ev = samba_tevent_context_init(frame); 880 904 if (ev == NULL) { 881 905 status = NT_STATUS_NO_MEMORY; … … 892 916 } 893 917 894 if (!tevent_req_poll(req, ev)) { 895 status = map_nt_error_from_unix(errno); 918 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 896 919 goto fail; 897 920 } … … 915 938 916 939 static struct tevent_req *cli_posix_chown_chmod_internal_send(TALLOC_CTX *mem_ctx, 917 struct event_context *ev,940 struct tevent_context *ev, 918 941 struct cli_state *cli, 919 942 const char *fname, … … 958 981 959 982 struct tevent_req *cli_posix_chmod_send(TALLOC_CTX *mem_ctx, 960 struct event_context *ev,983 struct tevent_context *ev, 961 984 struct cli_state *cli, 962 985 const char *fname, … … 978 1001 { 979 1002 TALLOC_CTX *frame = talloc_stackframe(); 980 struct event_context *ev = NULL;1003 struct tevent_context *ev = NULL; 981 1004 struct tevent_req *req = NULL; 982 1005 NTSTATUS status = NT_STATUS_OK; 983 1006 984 if ( cli_has_async_calls(cli)) {1007 if (smbXcli_conn_has_async_calls(cli->conn)) { 985 1008 /* 986 1009 * Can't use sync call while an async call is in flight … … 990 1013 } 991 1014 992 ev = event_context_init(frame);1015 ev = samba_tevent_context_init(frame); 993 1016 if (ev == NULL) { 994 1017 status = NT_STATUS_NO_MEMORY; … … 1006 1029 } 1007 1030 1008 if (!tevent_req_poll(req, ev)) { 1009 status = map_nt_error_from_unix(errno); 1031 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 1010 1032 goto fail; 1011 1033 } … … 1023 1045 1024 1046 struct tevent_req *cli_posix_chown_send(TALLOC_CTX *mem_ctx, 1025 struct event_context *ev,1047 struct tevent_context *ev, 1026 1048 struct cli_state *cli, 1027 1049 const char *fname, … … 1047 1069 { 1048 1070 TALLOC_CTX *frame = talloc_stackframe(); 1049 struct event_context *ev = NULL;1071 struct tevent_context *ev = NULL; 1050 1072 struct tevent_req *req = NULL; 1051 1073 NTSTATUS status = NT_STATUS_OK; 1052 1074 1053 if ( cli_has_async_calls(cli)) {1075 if (smbXcli_conn_has_async_calls(cli->conn)) { 1054 1076 /* 1055 1077 * Can't use sync call while an async call is in flight … … 1059 1081 } 1060 1082 1061 ev = event_context_init(frame);1083 ev = samba_tevent_context_init(frame); 1062 1084 if (ev == NULL) { 1063 1085 status = NT_STATUS_NO_MEMORY; … … 1076 1098 } 1077 1099 1078 if (!tevent_req_poll(req, ev)) { 1079 status = map_nt_error_from_unix(errno); 1100 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 1080 1101 goto fail; 1081 1102 } … … 1099 1120 1100 1121 struct tevent_req *cli_rename_send(TALLOC_CTX *mem_ctx, 1101 struct event_context *ev,1122 struct tevent_context *ev, 1102 1123 struct cli_state *cli, 1103 1124 const char *fname_src, … … 1121 1142 } 1122 1143 bytes[0] = 4; 1123 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname_src,1144 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname_src, 1124 1145 strlen(fname_src)+1, NULL); 1125 1146 if (tevent_req_nomem(bytes, req)) { … … 1127 1148 } 1128 1149 1129 bytes = TALLOC_REALLOC_ARRAY(state, bytes, uint8_t,1150 bytes = talloc_realloc(state, bytes, uint8_t, 1130 1151 talloc_get_size(bytes)+1); 1131 1152 if (tevent_req_nomem(bytes, req)) { … … 1134 1155 1135 1156 bytes[talloc_get_size(bytes)-1] = 4; 1136 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname_dst,1157 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname_dst, 1137 1158 strlen(fname_dst)+1, NULL); 1138 1159 if (tevent_req_nomem(bytes, req)) { … … 1170 1191 NTSTATUS cli_rename(struct cli_state *cli, const char *fname_src, const char *fname_dst) 1171 1192 { 1172 TALLOC_CTX *frame = talloc_stackframe();1173 struct event_context *ev;1193 TALLOC_CTX *frame = NULL; 1194 struct tevent_context *ev; 1174 1195 struct tevent_req *req; 1175 1196 NTSTATUS status = NT_STATUS_OK; 1176 1197 1177 if (cli_has_async_calls(cli)) { 1198 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 1199 return cli_smb2_rename(cli, 1200 fname_src, 1201 fname_dst); 1202 } 1203 1204 frame = talloc_stackframe(); 1205 1206 if (smbXcli_conn_has_async_calls(cli->conn)) { 1178 1207 /* 1179 1208 * Can't use sync call while an async call is in flight … … 1183 1212 } 1184 1213 1185 ev = event_context_init(frame);1214 ev = samba_tevent_context_init(frame); 1186 1215 if (ev == NULL) { 1187 1216 status = NT_STATUS_NO_MEMORY; … … 1195 1224 } 1196 1225 1197 if (!tevent_req_poll(req, ev)) { 1198 status = map_nt_error_from_unix(errno); 1226 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 1199 1227 goto fail; 1200 1228 } … … 1218 1246 1219 1247 static struct tevent_req *cli_ntrename_internal_send(TALLOC_CTX *mem_ctx, 1220 struct event_context *ev,1248 struct tevent_context *ev, 1221 1249 struct cli_state *cli, 1222 1250 const char *fname_src, … … 1243 1271 } 1244 1272 bytes[0] = 4; 1245 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname_src,1273 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname_src, 1246 1274 strlen(fname_src)+1, NULL); 1247 1275 if (tevent_req_nomem(bytes, req)) { … … 1249 1277 } 1250 1278 1251 bytes = TALLOC_REALLOC_ARRAY(state, bytes, uint8_t,1279 bytes = talloc_realloc(state, bytes, uint8_t, 1252 1280 talloc_get_size(bytes)+1); 1253 1281 if (tevent_req_nomem(bytes, req)) { … … 1256 1284 1257 1285 bytes[talloc_get_size(bytes)-1] = 4; 1258 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname_dst,1286 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname_dst, 1259 1287 strlen(fname_dst)+1, NULL); 1260 1288 if (tevent_req_nomem(bytes, req)) { … … 1291 1319 1292 1320 struct tevent_req *cli_ntrename_send(TALLOC_CTX *mem_ctx, 1293 struct event_context *ev,1321 struct tevent_context *ev, 1294 1322 struct cli_state *cli, 1295 1323 const char *fname_src, … … 1312 1340 { 1313 1341 TALLOC_CTX *frame = talloc_stackframe(); 1314 struct event_context *ev;1342 struct tevent_context *ev; 1315 1343 struct tevent_req *req; 1316 1344 NTSTATUS status = NT_STATUS_OK; 1317 1345 1318 if ( cli_has_async_calls(cli)) {1346 if (smbXcli_conn_has_async_calls(cli->conn)) { 1319 1347 /* 1320 1348 * Can't use sync call while an async call is in flight … … 1324 1352 } 1325 1353 1326 ev = event_context_init(frame);1354 ev = samba_tevent_context_init(frame); 1327 1355 if (ev == NULL) { 1328 1356 status = NT_STATUS_NO_MEMORY; … … 1336 1364 } 1337 1365 1338 if (!tevent_req_poll(req, ev)) { 1339 status = map_nt_error_from_unix(errno); 1366 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 1340 1367 goto fail; 1341 1368 } … … 1353 1380 1354 1381 struct tevent_req *cli_nt_hardlink_send(TALLOC_CTX *mem_ctx, 1355 struct event_context *ev,1382 struct tevent_context *ev, 1356 1383 struct cli_state *cli, 1357 1384 const char *fname_src, … … 1374 1401 { 1375 1402 TALLOC_CTX *frame = talloc_stackframe(); 1376 struct event_context *ev;1403 struct tevent_context *ev; 1377 1404 struct tevent_req *req; 1378 1405 NTSTATUS status = NT_STATUS_OK; 1379 1406 1380 if ( cli_has_async_calls(cli)) {1407 if (smbXcli_conn_has_async_calls(cli->conn)) { 1381 1408 /* 1382 1409 * Can't use sync call while an async call is in flight … … 1386 1413 } 1387 1414 1388 ev = event_context_init(frame);1415 ev = samba_tevent_context_init(frame); 1389 1416 if (ev == NULL) { 1390 1417 status = NT_STATUS_NO_MEMORY; … … 1398 1425 } 1399 1426 1400 if (!tevent_req_poll(req, ev)) { 1401 status = map_nt_error_from_unix(errno); 1427 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 1402 1428 goto fail; 1403 1429 } … … 1421 1447 1422 1448 struct tevent_req *cli_unlink_send(TALLOC_CTX *mem_ctx, 1423 struct event_context *ev,1449 struct tevent_context *ev, 1424 1450 struct cli_state *cli, 1425 1451 const char *fname, … … 1443 1469 } 1444 1470 bytes[0] = 4; 1445 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,1471 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname, 1446 1472 strlen(fname)+1, NULL); 1447 1473 … … 1480 1506 NTSTATUS cli_unlink(struct cli_state *cli, const char *fname, uint16_t mayhave_attrs) 1481 1507 { 1482 TALLOC_CTX *frame = talloc_stackframe();1483 struct event_context *ev;1508 TALLOC_CTX *frame = NULL; 1509 struct tevent_context *ev; 1484 1510 struct tevent_req *req; 1485 1511 NTSTATUS status = NT_STATUS_OK; 1486 1512 1487 if (cli_has_async_calls(cli)) { 1513 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 1514 return cli_smb2_unlink(cli, fname); 1515 } 1516 1517 frame = talloc_stackframe(); 1518 1519 if (smbXcli_conn_has_async_calls(cli->conn)) { 1488 1520 /* 1489 1521 * Can't use sync call while an async call is in flight … … 1493 1525 } 1494 1526 1495 ev = event_context_init(frame);1527 ev = samba_tevent_context_init(frame); 1496 1528 if (ev == NULL) { 1497 1529 status = NT_STATUS_NO_MEMORY; … … 1505 1537 } 1506 1538 1507 if (!tevent_req_poll(req, ev)) { 1508 status = map_nt_error_from_unix(errno); 1539 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 1509 1540 goto fail; 1510 1541 } … … 1528 1559 1529 1560 struct tevent_req *cli_mkdir_send(TALLOC_CTX *mem_ctx, 1530 struct event_context *ev,1561 struct tevent_context *ev, 1531 1562 struct cli_state *cli, 1532 1563 const char *dname) … … 1547 1578 } 1548 1579 bytes[0] = 4; 1549 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), dname,1580 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), dname, 1550 1581 strlen(dname)+1, NULL); 1551 1582 … … 1584 1615 NTSTATUS cli_mkdir(struct cli_state *cli, const char *dname) 1585 1616 { 1586 TALLOC_CTX *frame = talloc_stackframe();1587 struct event_context *ev;1617 TALLOC_CTX *frame = NULL; 1618 struct tevent_context *ev; 1588 1619 struct tevent_req *req; 1589 1620 NTSTATUS status = NT_STATUS_OK; 1590 1621 1591 if (cli_has_async_calls(cli)) { 1622 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 1623 return cli_smb2_mkdir(cli, dname); 1624 } 1625 1626 frame = talloc_stackframe(); 1627 1628 if (smbXcli_conn_has_async_calls(cli->conn)) { 1592 1629 /* 1593 1630 * Can't use sync call while an async call is in flight … … 1597 1634 } 1598 1635 1599 ev = event_context_init(frame);1636 ev = samba_tevent_context_init(frame); 1600 1637 if (ev == NULL) { 1601 1638 status = NT_STATUS_NO_MEMORY; … … 1609 1646 } 1610 1647 1611 if (!tevent_req_poll(req, ev)) { 1612 status = map_nt_error_from_unix(errno); 1648 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 1613 1649 goto fail; 1614 1650 } … … 1632 1668 1633 1669 struct tevent_req *cli_rmdir_send(TALLOC_CTX *mem_ctx, 1634 struct event_context *ev,1670 struct tevent_context *ev, 1635 1671 struct cli_state *cli, 1636 1672 const char *dname) … … 1651 1687 } 1652 1688 bytes[0] = 4; 1653 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), dname,1689 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), dname, 1654 1690 strlen(dname)+1, NULL); 1655 1691 … … 1688 1724 NTSTATUS cli_rmdir(struct cli_state *cli, const char *dname) 1689 1725 { 1690 TALLOC_CTX *frame = talloc_stackframe();1691 struct event_context *ev;1726 TALLOC_CTX *frame = NULL; 1727 struct tevent_context *ev; 1692 1728 struct tevent_req *req; 1693 1729 NTSTATUS status = NT_STATUS_OK; 1694 1730 1695 if (cli_has_async_calls(cli)) { 1731 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 1732 return cli_smb2_rmdir(cli, dname); 1733 } 1734 1735 frame = talloc_stackframe(); 1736 1737 if (smbXcli_conn_has_async_calls(cli->conn)) { 1696 1738 /* 1697 1739 * Can't use sync call while an async call is in flight … … 1701 1743 } 1702 1744 1703 ev = event_context_init(frame);1745 ev = samba_tevent_context_init(frame); 1704 1746 if (ev == NULL) { 1705 1747 status = NT_STATUS_NO_MEMORY; … … 1713 1755 } 1714 1756 1715 if (!tevent_req_poll(req, ev)) { 1716 status = map_nt_error_from_unix(errno); 1757 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 1717 1758 goto fail; 1718 1759 } … … 1743 1784 1744 1785 struct tevent_req *cli_nt_delete_on_close_send(TALLOC_CTX *mem_ctx, 1745 struct event_context *ev,1786 struct tevent_context *ev, 1746 1787 struct cli_state *cli, 1747 1788 uint16_t fnum, … … 1799 1840 { 1800 1841 TALLOC_CTX *frame = talloc_stackframe(); 1801 struct event_context *ev = NULL;1842 struct tevent_context *ev = NULL; 1802 1843 struct tevent_req *req = NULL; 1803 1844 NTSTATUS status = NT_STATUS_OK; 1804 1845 1805 if ( cli_has_async_calls(cli)) {1846 if (smbXcli_conn_has_async_calls(cli->conn)) { 1806 1847 /* 1807 1848 * Can't use sync call while an async call is in flight … … 1811 1852 } 1812 1853 1813 ev = event_context_init(frame);1854 ev = samba_tevent_context_init(frame); 1814 1855 if (ev == NULL) { 1815 1856 status = NT_STATUS_NO_MEMORY; … … 1827 1868 } 1828 1869 1829 if (!tevent_req_poll(req, ev)) { 1830 status = map_nt_error_from_unix(errno); 1870 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 1831 1871 goto fail; 1832 1872 } … … 1839 1879 } 1840 1880 1841 struct cli_ntcreate _state {1881 struct cli_ntcreate1_state { 1842 1882 uint16_t vwv[24]; 1843 1883 uint16_t fnum; 1884 struct smb_create_returns cr; 1885 struct tevent_req *subreq; 1844 1886 }; 1845 1887 1846 static void cli_ntcreate_done(struct tevent_req *subreq); 1847 1848 struct tevent_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx, 1849 struct event_context *ev, 1850 struct cli_state *cli, 1851 const char *fname, 1852 uint32_t CreatFlags, 1853 uint32_t DesiredAccess, 1854 uint32_t FileAttributes, 1855 uint32_t ShareAccess, 1856 uint32_t CreateDisposition, 1857 uint32_t CreateOptions, 1858 uint8_t SecurityFlags) 1888 static void cli_ntcreate1_done(struct tevent_req *subreq); 1889 static bool cli_ntcreate1_cancel(struct tevent_req *req); 1890 1891 static struct tevent_req *cli_ntcreate1_send(TALLOC_CTX *mem_ctx, 1892 struct tevent_context *ev, 1893 struct cli_state *cli, 1894 const char *fname, 1895 uint32_t CreatFlags, 1896 uint32_t DesiredAccess, 1897 uint32_t FileAttributes, 1898 uint32_t ShareAccess, 1899 uint32_t CreateDisposition, 1900 uint32_t CreateOptions, 1901 uint8_t SecurityFlags) 1859 1902 { 1860 1903 struct tevent_req *req, *subreq; 1861 struct cli_ntcreate _state *state;1904 struct cli_ntcreate1_state *state; 1862 1905 uint16_t *vwv; 1863 1906 uint8_t *bytes; 1864 1907 size_t converted_len; 1865 1908 1866 req = tevent_req_create(mem_ctx, &state, struct cli_ntcreate _state);1909 req = tevent_req_create(mem_ctx, &state, struct cli_ntcreate1_state); 1867 1910 if (req == NULL) { 1868 1911 return NULL; … … 1887 1930 SIVAL(vwv+15, 1, ShareAccess); 1888 1931 SIVAL(vwv+17, 1, CreateDisposition); 1889 SIVAL(vwv+19, 1, CreateOptions); 1932 SIVAL(vwv+19, 1, CreateOptions | 1933 (cli->backup_intent ? FILE_OPEN_FOR_BACKUP_INTENT : 0)); 1890 1934 SIVAL(vwv+21, 1, 0x02); /* ImpersonationLevel */ 1891 1935 SCVAL(vwv+23, 1, SecurityFlags); 1892 1936 1893 1937 bytes = talloc_array(state, uint8_t, 0); 1894 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli),1938 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), 1895 1939 fname, strlen(fname)+1, 1896 1940 &converted_len); 1897 1941 1898 1942 /* sigh. this copes with broken netapp filer behaviour */ 1899 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), "", 1, NULL);1943 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), "", 1, NULL); 1900 1944 1901 1945 if (tevent_req_nomem(bytes, req)) { … … 1910 1954 return tevent_req_post(req, ev); 1911 1955 } 1956 tevent_req_set_callback(subreq, cli_ntcreate1_done, req); 1957 1958 state->subreq = subreq; 1959 tevent_req_set_cancel_fn(req, cli_ntcreate1_cancel); 1960 1961 return req; 1962 } 1963 1964 static void cli_ntcreate1_done(struct tevent_req *subreq) 1965 { 1966 struct tevent_req *req = tevent_req_callback_data( 1967 subreq, struct tevent_req); 1968 struct cli_ntcreate1_state *state = tevent_req_data( 1969 req, struct cli_ntcreate1_state); 1970 uint8_t wct; 1971 uint16_t *vwv; 1972 uint32_t num_bytes; 1973 uint8_t *bytes; 1974 NTSTATUS status; 1975 1976 status = cli_smb_recv(subreq, state, NULL, 34, &wct, &vwv, 1977 &num_bytes, &bytes); 1978 TALLOC_FREE(subreq); 1979 if (tevent_req_nterror(req, status)) { 1980 return; 1981 } 1982 state->cr.oplock_level = CVAL(vwv+2, 0); 1983 state->fnum = SVAL(vwv+2, 1); 1984 state->cr.create_action = IVAL(vwv+3, 1); 1985 state->cr.creation_time = BVAL(vwv+5, 1); 1986 state->cr.last_access_time = BVAL(vwv+9, 1); 1987 state->cr.last_write_time = BVAL(vwv+13, 1); 1988 state->cr.change_time = BVAL(vwv+17, 1); 1989 state->cr.file_attributes = IVAL(vwv+21, 1); 1990 state->cr.allocation_size = BVAL(vwv+23, 1); 1991 state->cr.end_of_file = BVAL(vwv+27, 1); 1992 1993 tevent_req_done(req); 1994 } 1995 1996 static bool cli_ntcreate1_cancel(struct tevent_req *req) 1997 { 1998 struct cli_ntcreate1_state *state = tevent_req_data( 1999 req, struct cli_ntcreate1_state); 2000 return tevent_req_cancel(state->subreq); 2001 } 2002 2003 static NTSTATUS cli_ntcreate1_recv(struct tevent_req *req, 2004 uint16_t *pfnum, 2005 struct smb_create_returns *cr) 2006 { 2007 struct cli_ntcreate1_state *state = tevent_req_data( 2008 req, struct cli_ntcreate1_state); 2009 NTSTATUS status; 2010 2011 if (tevent_req_is_nterror(req, &status)) { 2012 return status; 2013 } 2014 *pfnum = state->fnum; 2015 if (cr != NULL) { 2016 *cr = state->cr; 2017 } 2018 return NT_STATUS_OK; 2019 } 2020 2021 struct cli_ntcreate_state { 2022 NTSTATUS (*recv)(struct tevent_req *req, uint16_t *fnum, 2023 struct smb_create_returns *cr); 2024 struct smb_create_returns cr; 2025 uint16_t fnum; 2026 struct tevent_req *subreq; 2027 }; 2028 2029 static void cli_ntcreate_done(struct tevent_req *subreq); 2030 static bool cli_ntcreate_cancel(struct tevent_req *req); 2031 2032 struct tevent_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx, 2033 struct tevent_context *ev, 2034 struct cli_state *cli, 2035 const char *fname, 2036 uint32_t create_flags, 2037 uint32_t desired_access, 2038 uint32_t file_attributes, 2039 uint32_t share_access, 2040 uint32_t create_disposition, 2041 uint32_t create_options, 2042 uint8_t security_flags) 2043 { 2044 struct tevent_req *req, *subreq; 2045 struct cli_ntcreate_state *state; 2046 2047 req = tevent_req_create(mem_ctx, &state, struct cli_ntcreate_state); 2048 if (req == NULL) { 2049 return NULL; 2050 } 2051 2052 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 2053 state->recv = cli_smb2_create_fnum_recv; 2054 2055 if (cli->use_oplocks) { 2056 create_flags |= REQUEST_OPLOCK|REQUEST_BATCH_OPLOCK; 2057 } 2058 2059 subreq = cli_smb2_create_fnum_send( 2060 state, ev, cli, fname, create_flags, desired_access, 2061 file_attributes, share_access, create_disposition, 2062 create_options); 2063 } else { 2064 state->recv = cli_ntcreate1_recv; 2065 subreq = cli_ntcreate1_send( 2066 state, ev, cli, fname, create_flags, desired_access, 2067 file_attributes, share_access, create_disposition, 2068 create_options, security_flags); 2069 } 2070 if (tevent_req_nomem(subreq, req)) { 2071 return tevent_req_post(req, ev); 2072 } 1912 2073 tevent_req_set_callback(subreq, cli_ntcreate_done, req); 2074 2075 state->subreq = subreq; 2076 tevent_req_set_cancel_fn(req, cli_ntcreate_cancel); 2077 1913 2078 return req; 1914 2079 } … … 1920 2085 struct cli_ntcreate_state *state = tevent_req_data( 1921 2086 req, struct cli_ntcreate_state); 1922 uint8_t wct;1923 uint16_t *vwv;1924 uint32_t num_bytes;1925 uint8_t *bytes;1926 uint8_t *inbuf;1927 2087 NTSTATUS status; 1928 2088 1929 status = cli_smb_recv(subreq, state, &inbuf, 3, &wct, &vwv, 1930 &num_bytes, &bytes); 2089 status = state->recv(subreq, &state->fnum, &state->cr); 1931 2090 TALLOC_FREE(subreq); 1932 2091 if (tevent_req_nterror(req, status)) { 1933 2092 return; 1934 2093 } 1935 state->fnum = SVAL(vwv+2, 1);1936 2094 tevent_req_done(req); 1937 2095 } 1938 2096 1939 NTSTATUS cli_ntcreate_recv(struct tevent_req *req, uint16_t *pfnum) 2097 static bool cli_ntcreate_cancel(struct tevent_req *req) 2098 { 2099 struct cli_ntcreate_state *state = tevent_req_data( 2100 req, struct cli_ntcreate_state); 2101 return tevent_req_cancel(state->subreq); 2102 } 2103 2104 NTSTATUS cli_ntcreate_recv(struct tevent_req *req, uint16_t *fnum, 2105 struct smb_create_returns *cr) 1940 2106 { 1941 2107 struct cli_ntcreate_state *state = tevent_req_data( … … 1946 2112 return status; 1947 2113 } 1948 *pfnum = state->fnum; 2114 if (fnum != NULL) { 2115 *fnum = state->fnum; 2116 } 2117 if (cr != NULL) { 2118 *cr = state->cr; 2119 } 1949 2120 return NT_STATUS_OK; 1950 2121 } … … 1959 2130 uint32_t CreateOptions, 1960 2131 uint8_t SecurityFlags, 1961 uint16_t *pfid) 2132 uint16_t *pfid, 2133 struct smb_create_returns *cr) 1962 2134 { 1963 2135 TALLOC_CTX *frame = talloc_stackframe(); 1964 struct event_context *ev;2136 struct tevent_context *ev; 1965 2137 struct tevent_req *req; 1966 NTSTATUS status = NT_STATUS_ OK;1967 1968 if ( cli_has_async_calls(cli)) {2138 NTSTATUS status = NT_STATUS_NO_MEMORY; 2139 2140 if (smbXcli_conn_has_async_calls(cli->conn)) { 1969 2141 /* 1970 2142 * Can't use sync call while an async call is in flight … … 1974 2146 } 1975 2147 1976 ev = event_context_init(frame);2148 ev = samba_tevent_context_init(frame); 1977 2149 if (ev == NULL) { 1978 status = NT_STATUS_NO_MEMORY;1979 2150 goto fail; 1980 2151 } … … 1985 2156 SecurityFlags); 1986 2157 if (req == NULL) { 1987 status = NT_STATUS_NO_MEMORY; 1988 goto fail; 1989 } 1990 1991 if (!tevent_req_poll(req, ev)) { 1992 status = map_nt_error_from_unix(errno); 1993 goto fail; 1994 } 1995 1996 status = cli_ntcreate_recv(req, pfid); 2158 goto fail; 2159 } 2160 2161 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 2162 goto fail; 2163 } 2164 2165 status = cli_ntcreate_recv(req, pfid, cr); 2166 fail: 2167 TALLOC_FREE(frame); 2168 return status; 2169 } 2170 2171 struct cli_nttrans_create_state { 2172 uint16_t fnum; 2173 struct smb_create_returns cr; 2174 }; 2175 2176 static void cli_nttrans_create_done(struct tevent_req *subreq); 2177 2178 struct tevent_req *cli_nttrans_create_send(TALLOC_CTX *mem_ctx, 2179 struct tevent_context *ev, 2180 struct cli_state *cli, 2181 const char *fname, 2182 uint32_t CreatFlags, 2183 uint32_t DesiredAccess, 2184 uint32_t FileAttributes, 2185 uint32_t ShareAccess, 2186 uint32_t CreateDisposition, 2187 uint32_t CreateOptions, 2188 uint8_t SecurityFlags, 2189 struct security_descriptor *secdesc, 2190 struct ea_struct *eas, 2191 int num_eas) 2192 { 2193 struct tevent_req *req, *subreq; 2194 struct cli_nttrans_create_state *state; 2195 uint8_t *param; 2196 uint8_t *secdesc_buf; 2197 size_t secdesc_len; 2198 NTSTATUS status; 2199 size_t converted_len; 2200 2201 req = tevent_req_create(mem_ctx, 2202 &state, struct cli_nttrans_create_state); 2203 if (req == NULL) { 2204 return NULL; 2205 } 2206 2207 if (secdesc != NULL) { 2208 status = marshall_sec_desc(talloc_tos(), secdesc, 2209 &secdesc_buf, &secdesc_len); 2210 if (tevent_req_nterror(req, status)) { 2211 DEBUG(10, ("marshall_sec_desc failed: %s\n", 2212 nt_errstr(status))); 2213 return tevent_req_post(req, ev); 2214 } 2215 } else { 2216 secdesc_buf = NULL; 2217 secdesc_len = 0; 2218 } 2219 2220 if (num_eas != 0) { 2221 /* 2222 * TODO ;-) 2223 */ 2224 tevent_req_nterror(req, NT_STATUS_NOT_IMPLEMENTED); 2225 return tevent_req_post(req, ev); 2226 } 2227 2228 param = talloc_array(state, uint8_t, 53); 2229 if (tevent_req_nomem(param, req)) { 2230 return tevent_req_post(req, ev); 2231 } 2232 2233 param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn), 2234 fname, strlen(fname), 2235 &converted_len); 2236 if (tevent_req_nomem(param, req)) { 2237 return tevent_req_post(req, ev); 2238 } 2239 2240 SIVAL(param, 0, CreatFlags); 2241 SIVAL(param, 4, 0x0); /* RootDirectoryFid */ 2242 SIVAL(param, 8, DesiredAccess); 2243 SIVAL(param, 12, 0x0); /* AllocationSize */ 2244 SIVAL(param, 16, 0x0); /* AllocationSize */ 2245 SIVAL(param, 20, FileAttributes); 2246 SIVAL(param, 24, ShareAccess); 2247 SIVAL(param, 28, CreateDisposition); 2248 SIVAL(param, 32, CreateOptions | 2249 (cli->backup_intent ? FILE_OPEN_FOR_BACKUP_INTENT : 0)); 2250 SIVAL(param, 36, secdesc_len); 2251 SIVAL(param, 40, 0); /* EA length*/ 2252 SIVAL(param, 44, converted_len); 2253 SIVAL(param, 48, 0x02); /* ImpersonationLevel */ 2254 SCVAL(param, 52, SecurityFlags); 2255 2256 subreq = cli_trans_send(state, ev, cli, SMBnttrans, 2257 NULL, -1, /* name, fid */ 2258 NT_TRANSACT_CREATE, 0, 2259 NULL, 0, 0, /* setup */ 2260 param, talloc_get_size(param), 128, /* param */ 2261 secdesc_buf, secdesc_len, 0); /* data */ 2262 if (tevent_req_nomem(subreq, req)) { 2263 return tevent_req_post(req, ev); 2264 } 2265 tevent_req_set_callback(subreq, cli_nttrans_create_done, req); 2266 return req; 2267 } 2268 2269 static void cli_nttrans_create_done(struct tevent_req *subreq) 2270 { 2271 struct tevent_req *req = tevent_req_callback_data( 2272 subreq, struct tevent_req); 2273 struct cli_nttrans_create_state *state = tevent_req_data( 2274 req, struct cli_nttrans_create_state); 2275 uint8_t *param; 2276 uint32_t num_param; 2277 NTSTATUS status; 2278 2279 status = cli_trans_recv(subreq, talloc_tos(), NULL, 2280 NULL, 0, NULL, /* rsetup */ 2281 ¶m, 69, &num_param, 2282 NULL, 0, NULL); 2283 if (tevent_req_nterror(req, status)) { 2284 return; 2285 } 2286 state->cr.oplock_level = CVAL(param, 0); 2287 state->fnum = SVAL(param, 2); 2288 state->cr.create_action = IVAL(param, 4); 2289 state->cr.creation_time = BVAL(param, 12); 2290 state->cr.last_access_time = BVAL(param, 20); 2291 state->cr.last_write_time = BVAL(param, 28); 2292 state->cr.change_time = BVAL(param, 36); 2293 state->cr.file_attributes = IVAL(param, 44); 2294 state->cr.allocation_size = BVAL(param, 48); 2295 state->cr.end_of_file = BVAL(param, 56); 2296 2297 TALLOC_FREE(param); 2298 tevent_req_done(req); 2299 } 2300 2301 NTSTATUS cli_nttrans_create_recv(struct tevent_req *req, 2302 uint16_t *fnum, 2303 struct smb_create_returns *cr) 2304 { 2305 struct cli_nttrans_create_state *state = tevent_req_data( 2306 req, struct cli_nttrans_create_state); 2307 NTSTATUS status; 2308 2309 if (tevent_req_is_nterror(req, &status)) { 2310 return status; 2311 } 2312 *fnum = state->fnum; 2313 if (cr != NULL) { 2314 *cr = state->cr; 2315 } 2316 return NT_STATUS_OK; 2317 } 2318 2319 NTSTATUS cli_nttrans_create(struct cli_state *cli, 2320 const char *fname, 2321 uint32_t CreatFlags, 2322 uint32_t DesiredAccess, 2323 uint32_t FileAttributes, 2324 uint32_t ShareAccess, 2325 uint32_t CreateDisposition, 2326 uint32_t CreateOptions, 2327 uint8_t SecurityFlags, 2328 struct security_descriptor *secdesc, 2329 struct ea_struct *eas, 2330 int num_eas, 2331 uint16_t *pfid, 2332 struct smb_create_returns *cr) 2333 { 2334 TALLOC_CTX *frame = talloc_stackframe(); 2335 struct tevent_context *ev; 2336 struct tevent_req *req; 2337 NTSTATUS status = NT_STATUS_NO_MEMORY; 2338 2339 if (smbXcli_conn_has_async_calls(cli->conn)) { 2340 /* 2341 * Can't use sync call while an async call is in flight 2342 */ 2343 status = NT_STATUS_INVALID_PARAMETER; 2344 goto fail; 2345 } 2346 ev = samba_tevent_context_init(frame); 2347 if (ev == NULL) { 2348 goto fail; 2349 } 2350 req = cli_nttrans_create_send(frame, ev, cli, fname, CreatFlags, 2351 DesiredAccess, FileAttributes, 2352 ShareAccess, CreateDisposition, 2353 CreateOptions, SecurityFlags, 2354 secdesc, eas, num_eas); 2355 if (req == NULL) { 2356 goto fail; 2357 } 2358 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 2359 goto fail; 2360 } 2361 status = cli_nttrans_create_recv(req, pfid, cr); 1997 2362 fail: 1998 2363 TALLOC_FREE(frame); … … 2005 2370 ****************************************************************************/ 2006 2371 2007 struct cli_open_state { 2008 struct tevent_context *ev; 2009 struct cli_state *cli; 2372 struct cli_openx_state { 2010 2373 const char *fname; 2011 2374 uint16_t vwv[15]; 2012 2375 uint16_t fnum; 2013 unsigned openfn;2014 unsigned dos_deny;2015 uint8_t additional_flags;2016 2376 struct iovec bytes; 2017 2377 }; 2018 2378 2019 static void cli_open_done(struct tevent_req *subreq); 2020 static void cli_open_ntcreate_done(struct tevent_req *subreq); 2021 2022 struct tevent_req *cli_open_create(TALLOC_CTX *mem_ctx, 2023 struct event_context *ev, 2379 static void cli_openx_done(struct tevent_req *subreq); 2380 2381 struct tevent_req *cli_openx_create(TALLOC_CTX *mem_ctx, 2382 struct tevent_context *ev, 2024 2383 struct cli_state *cli, const char *fname, 2025 2384 int flags, int share_mode, … … 2027 2386 { 2028 2387 struct tevent_req *req, *subreq; 2029 struct cli_open_state *state; 2388 struct cli_openx_state *state; 2389 unsigned openfn; 2390 unsigned accessmode; 2391 uint8_t additional_flags; 2030 2392 uint8_t *bytes; 2031 2393 2032 req = tevent_req_create(mem_ctx, &state, struct cli_open _state);2394 req = tevent_req_create(mem_ctx, &state, struct cli_openx_state); 2033 2395 if (req == NULL) { 2034 2396 return NULL; 2035 2397 } 2036 state->ev = ev; 2037 state->cli = cli; 2038 state->fname = fname; 2039 2398 2399 openfn = 0; 2040 2400 if (flags & O_CREAT) { 2041 state->openfn |= (1<<4);2401 openfn |= (1<<4); 2042 2402 } 2043 2403 if (!(flags & O_EXCL)) { 2044 2404 if (flags & O_TRUNC) 2045 state->openfn |= (1<<1);2405 openfn |= (1<<1); 2046 2406 else 2047 state->openfn |= (1<<0);2048 } 2049 2050 state->dos_deny= (share_mode<<4);2407 openfn |= (1<<0); 2408 } 2409 2410 accessmode = (share_mode<<4); 2051 2411 2052 2412 if ((flags & O_ACCMODE) == O_RDWR) { 2053 state->dos_deny|= 2;2413 accessmode |= 2; 2054 2414 } else if ((flags & O_ACCMODE) == O_WRONLY) { 2055 state->dos_deny|= 1;2415 accessmode |= 1; 2056 2416 } 2057 2417 2058 2418 #if defined(O_SYNC) 2059 2419 if ((flags & O_SYNC) == O_SYNC) { 2060 state->dos_deny|= (1<<14);2420 accessmode |= (1<<14); 2061 2421 } 2062 2422 #endif /* O_SYNC */ 2063 2423 2064 2424 if (share_mode == DENY_FCB) { 2065 state->dos_deny= 0xFF;2425 accessmode = 0xFF; 2066 2426 } 2067 2427 … … 2070 2430 SSVAL(state->vwv + 1, 0, 0); 2071 2431 SSVAL(state->vwv + 2, 0, 0); /* no additional info */ 2072 SSVAL(state->vwv + 3, 0, state->dos_deny);2432 SSVAL(state->vwv + 3, 0, accessmode); 2073 2433 SSVAL(state->vwv + 4, 0, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 2074 2434 SSVAL(state->vwv + 5, 0, 0); 2075 2435 SIVAL(state->vwv + 6, 0, 0); 2076 SSVAL(state->vwv + 8, 0, state->openfn);2436 SSVAL(state->vwv + 8, 0, openfn); 2077 2437 SIVAL(state->vwv + 9, 0, 0); 2078 2438 SIVAL(state->vwv + 11, 0, 0); 2079 2439 SIVAL(state->vwv + 13, 0, 0); 2080 2440 2441 additional_flags = 0; 2442 2081 2443 if (cli->use_oplocks) { 2082 2444 /* if using oplocks then ask for a batch oplock via 2083 2445 core and extended methods */ 2084 state->additional_flags =2446 additional_flags = 2085 2447 FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK; 2086 2448 SSVAL(state->vwv+2, 0, SVAL(state->vwv+2, 0) | 6); … … 2088 2450 2089 2451 bytes = talloc_array(state, uint8_t, 0); 2090 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,2452 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname, 2091 2453 strlen(fname)+1, NULL); 2092 2454 … … 2098 2460 state->bytes.iov_len = talloc_get_size(bytes); 2099 2461 2100 subreq = cli_smb_req_create(state, ev, cli, SMBopenX, 2101 state->additional_flags, 2462 subreq = cli_smb_req_create(state, ev, cli, SMBopenX, additional_flags, 2102 2463 15, state->vwv, 1, &state->bytes); 2103 2464 if (subreq == NULL) { … … 2105 2466 return NULL; 2106 2467 } 2107 tevent_req_set_callback(subreq, cli_open _done, req);2468 tevent_req_set_callback(subreq, cli_openx_done, req); 2108 2469 *psmbreq = subreq; 2109 2470 return req; 2110 2471 } 2111 2472 2112 struct tevent_req *cli_open _send(TALLOC_CTX *mem_ctx, structevent_context *ev,2473 struct tevent_req *cli_openx_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, 2113 2474 struct cli_state *cli, const char *fname, 2114 2475 int flags, int share_mode) … … 2117 2478 NTSTATUS status; 2118 2479 2119 req = cli_open _create(mem_ctx, ev, cli, fname, flags, share_mode,2480 req = cli_openx_create(mem_ctx, ev, cli, fname, flags, share_mode, 2120 2481 &subreq); 2121 2482 if (req == NULL) { … … 2123 2484 } 2124 2485 2125 status = cli_smb_req_send(subreq);2486 status = smb1cli_req_chain_submit(&subreq, 1); 2126 2487 if (tevent_req_nterror(req, status)) { 2127 2488 return tevent_req_post(req, ev); … … 2130 2491 } 2131 2492 2132 static void cli_open _done(struct tevent_req *subreq)2493 static void cli_openx_done(struct tevent_req *subreq) 2133 2494 { 2134 2495 struct tevent_req *req = tevent_req_callback_data( 2135 2496 subreq, struct tevent_req); 2136 struct cli_open _state *state = tevent_req_data(2137 req, struct cli_open _state);2497 struct cli_openx_state *state = tevent_req_data( 2498 req, struct cli_openx_state); 2138 2499 uint8_t wct; 2139 2500 uint16_t *vwv; 2140 uint8_t *inbuf;2141 2501 NTSTATUS status; 2142 uint32_t access_mask, share_mode, create_disposition, create_options; 2143 2144 status = cli_smb_recv(subreq, state, &inbuf, 3, &wct, &vwv, NULL, 2502 2503 status = cli_smb_recv(subreq, state, NULL, 3, &wct, &vwv, NULL, 2145 2504 NULL); 2146 TALLOC_FREE(subreq);2147 2148 if (NT_STATUS_IS_OK(status)) {2149 state->fnum = SVAL(vwv+2, 0);2150 tevent_req_done(req);2151 return;2152 }2153 2154 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {2155 tevent_req_nterror(req, status);2156 return;2157 }2158 2159 /*2160 * For the new shiny OS/X Lion SMB server, try a ntcreate2161 * fallback.2162 */2163 2164 if (!map_open_params_to_ntcreate(state->fname, state->dos_deny,2165 state->openfn, &access_mask,2166 &share_mode, &create_disposition,2167 &create_options, NULL)) {2168 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);2169 return;2170 }2171 2172 subreq = cli_ntcreate_send(state, state->ev, state->cli,2173 state->fname, 0, access_mask,2174 0, share_mode, create_disposition,2175 create_options, 0);2176 if (tevent_req_nomem(subreq, req)) {2177 return;2178 }2179 tevent_req_set_callback(subreq, cli_open_ntcreate_done, req);2180 }2181 2182 static void cli_open_ntcreate_done(struct tevent_req *subreq)2183 {2184 struct tevent_req *req = tevent_req_callback_data(2185 subreq, struct tevent_req);2186 struct cli_open_state *state = tevent_req_data(2187 req, struct cli_open_state);2188 NTSTATUS status;2189 2190 status = cli_ntcreate_recv(subreq, &state->fnum);2191 2505 TALLOC_FREE(subreq); 2192 2506 if (tevent_req_nterror(req, status)) { 2193 2507 return; 2194 2508 } 2509 state->fnum = SVAL(vwv+2, 0); 2195 2510 tevent_req_done(req); 2196 2511 } 2197 2512 2198 NTSTATUS cli_open _recv(struct tevent_req *req, uint16_t *pfnum)2199 { 2200 struct cli_open _state *state = tevent_req_data(2201 req, struct cli_open _state);2513 NTSTATUS cli_openx_recv(struct tevent_req *req, uint16_t *pfnum) 2514 { 2515 struct cli_openx_state *state = tevent_req_data( 2516 req, struct cli_openx_state); 2202 2517 NTSTATUS status; 2203 2518 … … 2209 2524 } 2210 2525 2211 NTSTATUS cli_open (struct cli_state *cli, const char *fname, int flags,2526 NTSTATUS cli_openx(struct cli_state *cli, const char *fname, int flags, 2212 2527 int share_mode, uint16_t *pfnum) 2213 2528 { 2214 2529 TALLOC_CTX *frame = talloc_stackframe(); 2215 struct event_context *ev;2530 struct tevent_context *ev; 2216 2531 struct tevent_req *req; 2217 NTSTATUS status = NT_STATUS_ OK;2218 2219 if ( cli_has_async_calls(cli)) {2532 NTSTATUS status = NT_STATUS_NO_MEMORY; 2533 2534 if (smbXcli_conn_has_async_calls(cli->conn)) { 2220 2535 /* 2221 2536 * Can't use sync call while an async call is in flight … … 2225 2540 } 2226 2541 2227 ev = event_context_init(frame);2542 ev = samba_tevent_context_init(frame); 2228 2543 if (ev == NULL) { 2229 status = NT_STATUS_NO_MEMORY; 2230 goto fail; 2231 } 2232 2233 req = cli_open_send(frame, ev, cli, fname, flags, share_mode); 2234 if (req == NULL) { 2235 status = NT_STATUS_NO_MEMORY; 2236 goto fail; 2237 } 2238 2239 if (!tevent_req_poll(req, ev)) { 2240 status = map_nt_error_from_unix(errno); 2241 goto fail; 2242 } 2243 2244 status = cli_open_recv(req, pfnum); 2544 goto fail; 2545 } 2546 2547 req = cli_openx_send(frame, ev, cli, fname, flags, share_mode); 2548 if (req == NULL) { 2549 goto fail; 2550 } 2551 2552 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 2553 goto fail; 2554 } 2555 2556 status = cli_openx_recv(req, pfnum); 2245 2557 fail: 2246 2558 TALLOC_FREE(frame); 2247 2559 return status; 2248 2560 } 2561 /**************************************************************************** 2562 Synchronous wrapper function that does an NtCreateX open by preference 2563 and falls back to openX if this fails. 2564 ****************************************************************************/ 2565 2566 NTSTATUS cli_open(struct cli_state *cli, const char *fname, int flags, 2567 int share_mode_in, uint16_t *pfnum) 2568 { 2569 NTSTATUS status; 2570 unsigned int openfn = 0; 2571 unsigned int dos_deny = 0; 2572 uint32_t access_mask, share_mode, create_disposition, create_options; 2573 struct smb_create_returns cr; 2574 2575 /* Do the initial mapping into OpenX parameters. */ 2576 if (flags & O_CREAT) { 2577 openfn |= (1<<4); 2578 } 2579 if (!(flags & O_EXCL)) { 2580 if (flags & O_TRUNC) 2581 openfn |= (1<<1); 2582 else 2583 openfn |= (1<<0); 2584 } 2585 2586 dos_deny = (share_mode_in<<4); 2587 2588 if ((flags & O_ACCMODE) == O_RDWR) { 2589 dos_deny |= 2; 2590 } else if ((flags & O_ACCMODE) == O_WRONLY) { 2591 dos_deny |= 1; 2592 } 2593 2594 #if defined(O_SYNC) 2595 if ((flags & O_SYNC) == O_SYNC) { 2596 dos_deny |= (1<<14); 2597 } 2598 #endif /* O_SYNC */ 2599 2600 if (share_mode_in == DENY_FCB) { 2601 dos_deny = 0xFF; 2602 } 2603 2604 #if 0 2605 /* Hmmm. This is what I think the above code 2606 should look like if it's using the constants 2607 we #define. JRA. */ 2608 2609 if (flags & O_CREAT) { 2610 openfn |= OPENX_FILE_CREATE_IF_NOT_EXIST; 2611 } 2612 if (!(flags & O_EXCL)) { 2613 if (flags & O_TRUNC) 2614 openfn |= OPENX_FILE_EXISTS_TRUNCATE; 2615 else 2616 openfn |= OPENX_FILE_EXISTS_OPEN; 2617 } 2618 2619 dos_deny = SET_DENY_MODE(share_mode_in); 2620 2621 if ((flags & O_ACCMODE) == O_RDWR) { 2622 dos_deny |= DOS_OPEN_RDWR; 2623 } else if ((flags & O_ACCMODE) == O_WRONLY) { 2624 dos_deny |= DOS_OPEN_WRONLY; 2625 } 2626 2627 #if defined(O_SYNC) 2628 if ((flags & O_SYNC) == O_SYNC) { 2629 dos_deny |= FILE_SYNC_OPENMODE; 2630 } 2631 #endif /* O_SYNC */ 2632 2633 if (share_mode_in == DENY_FCB) { 2634 dos_deny = 0xFF; 2635 } 2636 #endif 2637 2638 if (!map_open_params_to_ntcreate(fname, dos_deny, 2639 openfn, &access_mask, 2640 &share_mode, &create_disposition, 2641 &create_options, NULL)) { 2642 goto try_openx; 2643 } 2644 2645 status = cli_ntcreate(cli, 2646 fname, 2647 0, 2648 access_mask, 2649 0, 2650 share_mode, 2651 create_disposition, 2652 create_options, 2653 0, 2654 pfnum, 2655 &cr); 2656 2657 /* Try and cope will all varients of "we don't do this call" 2658 and fall back to openX. */ 2659 2660 if (NT_STATUS_EQUAL(status,NT_STATUS_NOT_IMPLEMENTED) || 2661 NT_STATUS_EQUAL(status,NT_STATUS_INVALID_INFO_CLASS) || 2662 NT_STATUS_EQUAL(status,NT_STATUS_PROCEDURE_NOT_FOUND) || 2663 NT_STATUS_EQUAL(status,NT_STATUS_INVALID_LEVEL) || 2664 NT_STATUS_EQUAL(status,NT_STATUS_INVALID_PARAMETER) || 2665 NT_STATUS_EQUAL(status,NT_STATUS_INVALID_DEVICE_REQUEST) || 2666 NT_STATUS_EQUAL(status,NT_STATUS_INVALID_DEVICE_STATE) || 2667 NT_STATUS_EQUAL(status,NT_STATUS_CTL_FILE_NOT_SUPPORTED) || 2668 NT_STATUS_EQUAL(status,NT_STATUS_UNSUCCESSFUL)) { 2669 goto try_openx; 2670 } 2671 2672 if (NT_STATUS_IS_OK(status) && 2673 (create_options & FILE_NON_DIRECTORY_FILE) && 2674 (cr.file_attributes & FILE_ATTRIBUTE_DIRECTORY)) 2675 { 2676 /* 2677 * Some (broken) servers return a valid handle 2678 * for directories even if FILE_NON_DIRECTORY_FILE 2679 * is set. Just close the handle and set the 2680 * error explicitly to NT_STATUS_FILE_IS_A_DIRECTORY. 2681 */ 2682 status = cli_close(cli, *pfnum); 2683 if (!NT_STATUS_IS_OK(status)) { 2684 return status; 2685 } 2686 status = NT_STATUS_FILE_IS_A_DIRECTORY; 2687 /* Set this so libsmbclient can retrieve it. */ 2688 cli->raw_status = status; 2689 } 2690 2691 return status; 2692 2693 try_openx: 2694 2695 return cli_openx(cli, fname, flags, share_mode_in, pfnum); 2696 } 2249 2697 2250 2698 /**************************************************************************** … … 2259 2707 2260 2708 struct tevent_req *cli_close_create(TALLOC_CTX *mem_ctx, 2261 struct event_context *ev,2709 struct tevent_context *ev, 2262 2710 struct cli_state *cli, 2263 2711 uint16_t fnum, … … 2287 2735 2288 2736 struct tevent_req *cli_close_send(TALLOC_CTX *mem_ctx, 2289 struct event_context *ev,2737 struct tevent_context *ev, 2290 2738 struct cli_state *cli, 2291 2739 uint16_t fnum) … … 2299 2747 } 2300 2748 2301 status = cli_smb_req_send(subreq);2749 status = smb1cli_req_chain_submit(&subreq, 1); 2302 2750 if (tevent_req_nterror(req, status)) { 2303 2751 return tevent_req_post(req, ev); … … 2327 2775 NTSTATUS cli_close(struct cli_state *cli, uint16_t fnum) 2328 2776 { 2329 TALLOC_CTX *frame = talloc_stackframe();2330 struct event_context *ev;2777 TALLOC_CTX *frame = NULL; 2778 struct tevent_context *ev; 2331 2779 struct tevent_req *req; 2332 2780 NTSTATUS status = NT_STATUS_OK; 2333 2781 2334 if (cli_has_async_calls(cli)) { 2782 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 2783 return cli_smb2_close_fnum(cli, fnum); 2784 } 2785 2786 frame = talloc_stackframe(); 2787 2788 if (smbXcli_conn_has_async_calls(cli->conn)) { 2335 2789 /* 2336 2790 * Can't use sync call while an async call is in flight … … 2340 2794 } 2341 2795 2342 ev = event_context_init(frame);2796 ev = samba_tevent_context_init(frame); 2343 2797 if (ev == NULL) { 2344 2798 status = NT_STATUS_NO_MEMORY; … … 2352 2806 } 2353 2807 2354 if (!tevent_req_poll(req, ev)) { 2355 status = map_nt_error_from_unix(errno); 2808 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 2356 2809 goto fail; 2357 2810 } … … 2381 2834 2382 2835 struct tevent_req *cli_ftruncate_send(TALLOC_CTX *mem_ctx, 2383 struct event_context *ev,2836 struct tevent_context *ev, 2384 2837 struct cli_state *cli, 2385 2838 uint16_t fnum, … … 2438 2891 { 2439 2892 TALLOC_CTX *frame = talloc_stackframe(); 2440 struct event_context *ev = NULL;2893 struct tevent_context *ev = NULL; 2441 2894 struct tevent_req *req = NULL; 2442 2895 NTSTATUS status = NT_STATUS_OK; 2443 2896 2444 if ( cli_has_async_calls(cli)) {2897 if (smbXcli_conn_has_async_calls(cli->conn)) { 2445 2898 /* 2446 2899 * Can't use sync call while an async call is in flight … … 2450 2903 } 2451 2904 2452 ev = event_context_init(frame);2905 ev = samba_tevent_context_init(frame); 2453 2906 if (ev == NULL) { 2454 2907 status = NT_STATUS_NO_MEMORY; … … 2466 2919 } 2467 2920 2468 if (!tevent_req_poll(req, ev)) { 2469 status = map_nt_error_from_unix(errno); 2921 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 2470 2922 goto fail; 2471 2923 } … … 2490 2942 uint8_t bytes[10]; 2491 2943 NTSTATUS status; 2492 int saved_timeout; 2944 unsigned int set_timeout = 0; 2945 unsigned int saved_timeout = 0; 2493 2946 2494 2947 SCVAL(vwv + 0, 0, 0xff); … … 2502 2955 SSVAL(vwv + 7, 0, 1); 2503 2956 2504 SSVAL(bytes, 0, cli ->pid);2957 SSVAL(bytes, 0, cli_getpid(cli)); 2505 2958 SIVAL(bytes, 2, offset); 2506 2959 SIVAL(bytes, 6, len); 2507 2960 2508 saved_timeout = cli->timeout;2509 2510 2961 if (timeout != 0) { 2511 cli->timeout = (timeout == -1) 2512 ? 0x7FFFFFFF : (timeout + 2*1000); 2962 if (timeout == -1) { 2963 set_timeout = 0x7FFFFFFF; 2964 } else { 2965 set_timeout = timeout + 2*1000; 2966 } 2967 saved_timeout = cli_set_timeout(cli, set_timeout); 2513 2968 } 2514 2969 … … 2516 2971 10, bytes, NULL, 0, NULL, NULL, NULL, NULL); 2517 2972 2518 cli->timeout = saved_timeout; 2973 if (saved_timeout != 0) { 2974 cli_set_timeout(cli, saved_timeout); 2975 } 2519 2976 2520 2977 return status; … … 2526 2983 ****************************************************************************/ 2527 2984 2528 bool cli_lock(struct cli_state *cli, uint16_t fnum,2985 NTSTATUS cli_lock32(struct cli_state *cli, uint16_t fnum, 2529 2986 uint32_t offset, uint32_t len, int timeout, 2530 2987 enum brl_type lock_type) … … 2534 2991 status = cli_locktype(cli, fnum, offset, len, timeout, 2535 2992 (lock_type == READ_LOCK? 1 : 0)); 2536 return NT_STATUS_IS_OK(status);2993 return status; 2537 2994 } 2538 2995 … … 2549 3006 2550 3007 struct tevent_req *cli_unlock_send(TALLOC_CTX *mem_ctx, 2551 struct event_context *ev,3008 struct tevent_context *ev, 2552 3009 struct cli_state *cli, 2553 3010 uint16_t fnum, … … 2572 3029 SSVAL(state->vwv+7, 0, 0); 2573 3030 2574 SSVAL(state->data, 0, cli ->pid);3031 SSVAL(state->data, 0, cli_getpid(cli)); 2575 3032 SIVAL(state->data, 2, offset); 2576 3033 SIVAL(state->data, 6, len); … … 2610 3067 { 2611 3068 TALLOC_CTX *frame = talloc_stackframe(); 2612 struct event_context *ev;3069 struct tevent_context *ev; 2613 3070 struct tevent_req *req; 2614 3071 NTSTATUS status = NT_STATUS_OK; 2615 3072 2616 if ( cli_has_async_calls(cli)) {3073 if (smbXcli_conn_has_async_calls(cli->conn)) { 2617 3074 /* 2618 3075 * Can't use sync call while an async call is in flight … … 2622 3079 } 2623 3080 2624 ev = event_context_init(frame);3081 ev = samba_tevent_context_init(frame); 2625 3082 if (ev == NULL) { 2626 3083 status = NT_STATUS_NO_MEMORY; … … 2635 3092 } 2636 3093 2637 if (!tevent_req_poll(req, ev)) { 2638 status = map_nt_error_from_unix(errno); 3094 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 2639 3095 goto fail; 2640 3096 } … … 2651 3107 ****************************************************************************/ 2652 3108 2653 boolcli_lock64(struct cli_state *cli, uint16_t fnum,2654 uint64_t offset, uint64_t len, int timeout,2655 enum brl_type lock_type)3109 NTSTATUS cli_lock64(struct cli_state *cli, uint16_t fnum, 3110 uint64_t offset, uint64_t len, int timeout, 3111 enum brl_type lock_type) 2656 3112 { 2657 3113 uint16_t vwv[8]; 2658 3114 uint8_t bytes[20]; 2659 int saved_timeout = cli->timeout; 3115 unsigned int set_timeout = 0; 3116 unsigned int saved_timeout = 0; 2660 3117 int ltype; 2661 3118 NTSTATUS status; 2662 3119 2663 if (! ( cli->capabilities& CAP_LARGE_FILES)) {2664 return cli_lock (cli, fnum, offset, len, timeout, lock_type);3120 if (! (smb1cli_conn_capabilities(cli->conn) & CAP_LARGE_FILES)) { 3121 return cli_lock32(cli, fnum, offset, len, timeout, lock_type); 2665 3122 } 2666 3123 … … 2678 3135 SSVAL(vwv + 7, 0, 1); 2679 3136 2680 SIVAL(bytes, 0, cli ->pid);3137 SIVAL(bytes, 0, cli_getpid(cli)); 2681 3138 SOFF_T_R(bytes, 4, offset); 2682 3139 SOFF_T_R(bytes, 12, len); 2683 3140 2684 saved_timeout = cli->timeout;2685 2686 3141 if (timeout != 0) { 2687 cli->timeout = (timeout == -1) 2688 ? 0x7FFFFFFF : (timeout + 2*1000); 3142 if (timeout == -1) { 3143 set_timeout = 0x7FFFFFFF; 3144 } else { 3145 set_timeout = timeout + 2*1000; 3146 } 3147 saved_timeout = cli_set_timeout(cli, set_timeout); 2689 3148 } 2690 3149 … … 2692 3151 20, bytes, NULL, 0, NULL, NULL, NULL, NULL); 2693 3152 2694 cli->timeout = saved_timeout; 2695 2696 return NT_STATUS_IS_OK(status); 3153 if (saved_timeout != 0) { 3154 cli_set_timeout(cli, saved_timeout); 3155 } 3156 3157 return status; 2697 3158 } 2698 3159 … … 2709 3170 2710 3171 struct tevent_req *cli_unlock64_send(TALLOC_CTX *mem_ctx, 2711 struct event_context *ev,3172 struct tevent_context *ev, 2712 3173 struct cli_state *cli, 2713 3174 uint16_t fnum, … … 2732 3193 SSVAL(state->vwv+7, 0, 0); 2733 3194 2734 SIVAL(state->data, 0, cli ->pid);3195 SIVAL(state->data, 0, cli_getpid(cli)); 2735 3196 SOFF_T_R(state->data, 4, offset); 2736 3197 SOFF_T_R(state->data, 12, len); … … 2770 3231 { 2771 3232 TALLOC_CTX *frame = talloc_stackframe(); 2772 struct event_context *ev;3233 struct tevent_context *ev; 2773 3234 struct tevent_req *req; 2774 3235 NTSTATUS status = NT_STATUS_OK; 2775 3236 2776 if (! ( cli->capabilities& CAP_LARGE_FILES)) {3237 if (! (smb1cli_conn_capabilities(cli->conn) & CAP_LARGE_FILES)) { 2777 3238 return cli_unlock(cli, fnum, offset, len); 2778 3239 } 2779 3240 2780 if ( cli_has_async_calls(cli)) {3241 if (smbXcli_conn_has_async_calls(cli->conn)) { 2781 3242 /* 2782 3243 * Can't use sync call while an async call is in flight … … 2786 3247 } 2787 3248 2788 ev = event_context_init(frame);3249 ev = samba_tevent_context_init(frame); 2789 3250 if (ev == NULL) { 2790 3251 status = NT_STATUS_NO_MEMORY; … … 2799 3260 } 2800 3261 2801 if (!tevent_req_poll(req, ev)) { 2802 status = map_nt_error_from_unix(errno); 3262 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 2803 3263 goto fail; 2804 3264 } … … 2829 3289 2830 3290 static struct tevent_req *cli_posix_lock_internal_send(TALLOC_CTX *mem_ctx, 2831 struct event_context *ev,3291 struct tevent_context *ev, 2832 3292 struct cli_state *cli, 2833 3293 uint16_t fnum, … … 2878 3338 } 2879 3339 2880 SIVAL(&state->data, POSIX_LOCK_PID_OFFSET, cli ->pid);3340 SIVAL(&state->data, POSIX_LOCK_PID_OFFSET, cli_getpid(cli)); 2881 3341 SOFF_T(&state->data, POSIX_LOCK_START_OFFSET, offset); 2882 3342 SOFF_T(&state->data, POSIX_LOCK_LEN_OFFSET, len); … … 2912 3372 2913 3373 struct tevent_req *cli_posix_lock_send(TALLOC_CTX *mem_ctx, 2914 struct event_context *ev,3374 struct tevent_context *ev, 2915 3375 struct cli_state *cli, 2916 3376 uint16_t fnum, … … 2934 3394 { 2935 3395 TALLOC_CTX *frame = talloc_stackframe(); 2936 struct event_context *ev = NULL;3396 struct tevent_context *ev = NULL; 2937 3397 struct tevent_req *req = NULL; 2938 3398 NTSTATUS status = NT_STATUS_OK; 2939 3399 2940 if ( cli_has_async_calls(cli)) {3400 if (smbXcli_conn_has_async_calls(cli->conn)) { 2941 3401 /* 2942 3402 * Can't use sync call while an async call is in flight … … 2951 3411 } 2952 3412 2953 ev = event_context_init(frame);3413 ev = samba_tevent_context_init(frame); 2954 3414 if (ev == NULL) { 2955 3415 status = NT_STATUS_NO_MEMORY; … … 2970 3430 } 2971 3431 2972 if (!tevent_req_poll(req, ev)) { 2973 status = map_nt_error_from_unix(errno); 3432 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 2974 3433 goto fail; 2975 3434 } … … 2987 3446 2988 3447 struct tevent_req *cli_posix_unlock_send(TALLOC_CTX *mem_ctx, 2989 struct event_context *ev,3448 struct tevent_context *ev, 2990 3449 struct cli_state *cli, 2991 3450 uint16_t fnum, … … 3005 3464 { 3006 3465 TALLOC_CTX *frame = talloc_stackframe(); 3007 struct event_context *ev = NULL;3466 struct tevent_context *ev = NULL; 3008 3467 struct tevent_req *req = NULL; 3009 3468 NTSTATUS status = NT_STATUS_OK; 3010 3469 3011 if ( cli_has_async_calls(cli)) {3470 if (smbXcli_conn_has_async_calls(cli->conn)) { 3012 3471 /* 3013 3472 * Can't use sync call while an async call is in flight … … 3017 3476 } 3018 3477 3019 ev = event_context_init(frame);3478 ev = samba_tevent_context_init(frame); 3020 3479 if (ev == NULL) { 3021 3480 status = NT_STATUS_NO_MEMORY; … … 3034 3493 } 3035 3494 3036 if (!tevent_req_poll(req, ev)) { 3037 status = map_nt_error_from_unix(errno); 3495 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 3038 3496 goto fail; 3039 3497 } … … 3056 3514 int zone_offset; 3057 3515 uint16_t attr; 3058 SMB_OFF_Tsize;3516 off_t size; 3059 3517 time_t change_time; 3060 3518 time_t access_time; … … 3063 3521 3064 3522 struct tevent_req *cli_getattrE_send(TALLOC_CTX *mem_ctx, 3065 struct event_context *ev,3523 struct tevent_context *ev, 3066 3524 struct cli_state *cli, 3067 3525 uint16_t fnum) … … 3076 3534 } 3077 3535 3078 state->zone_offset = cli->serverzone;3536 state->zone_offset = smb1cli_conn_server_time_zone(cli->conn); 3079 3537 SSVAL(state->vwv+0,0,fnum); 3080 3538 … … 3096 3554 uint8_t wct; 3097 3555 uint16_t *vwv = NULL; 3098 uint8_t *inbuf;3099 3556 NTSTATUS status; 3100 3557 3101 status = cli_smb_recv(subreq, state, &inbuf, 11, &wct, &vwv,3558 status = cli_smb_recv(subreq, state, NULL, 11, &wct, &vwv, 3102 3559 NULL, NULL); 3103 3560 TALLOC_FREE(subreq); … … 3106 3563 } 3107 3564 3108 state->size = ( SMB_OFF_T)IVAL(vwv+6,0);3565 state->size = (off_t)IVAL(vwv+6,0); 3109 3566 state->attr = SVAL(vwv+10,0); 3110 3567 state->change_time = make_unix_date2(vwv+0, state->zone_offset); … … 3117 3574 NTSTATUS cli_getattrE_recv(struct tevent_req *req, 3118 3575 uint16_t *attr, 3119 SMB_OFF_T*size,3576 off_t *size, 3120 3577 time_t *change_time, 3121 3578 time_t *access_time, … … 3150 3607 uint16_t fnum, 3151 3608 uint16_t *attr, 3152 SMB_OFF_T*size,3609 off_t *size, 3153 3610 time_t *change_time, 3154 3611 time_t *access_time, 3155 3612 time_t *write_time) 3156 3613 { 3157 TALLOC_CTX *frame = talloc_stackframe();3158 struct event_context *ev = NULL;3614 TALLOC_CTX *frame = NULL; 3615 struct tevent_context *ev = NULL; 3159 3616 struct tevent_req *req = NULL; 3160 3617 NTSTATUS status = NT_STATUS_OK; 3161 3618 3162 if (cli_has_async_calls(cli)) { 3619 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 3620 return cli_smb2_getattrE(cli, 3621 fnum, 3622 attr, 3623 size, 3624 change_time, 3625 access_time, 3626 write_time); 3627 } 3628 3629 frame = talloc_stackframe(); 3630 3631 if (smbXcli_conn_has_async_calls(cli->conn)) { 3163 3632 /* 3164 3633 * Can't use sync call while an async call is in flight … … 3168 3637 } 3169 3638 3170 ev = event_context_init(frame);3639 ev = samba_tevent_context_init(frame); 3171 3640 if (ev == NULL) { 3172 3641 status = NT_STATUS_NO_MEMORY; … … 3180 3649 } 3181 3650 3182 if (!tevent_req_poll(req, ev)) { 3183 status = map_nt_error_from_unix(errno); 3651 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 3184 3652 goto fail; 3185 3653 } … … 3206 3674 int zone_offset; 3207 3675 uint16_t attr; 3208 SMB_OFF_Tsize;3676 off_t size; 3209 3677 time_t write_time; 3210 3678 }; 3211 3679 3212 3680 struct tevent_req *cli_getatr_send(TALLOC_CTX *mem_ctx, 3213 struct event_context *ev,3681 struct tevent_context *ev, 3214 3682 struct cli_state *cli, 3215 3683 const char *fname) … … 3225 3693 } 3226 3694 3227 state->zone_offset = cli->serverzone;3695 state->zone_offset = smb1cli_conn_server_time_zone(cli->conn); 3228 3696 3229 3697 bytes = talloc_array(state, uint8_t, 1); … … 3232 3700 } 3233 3701 bytes[0] = 4; 3234 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,3702 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname, 3235 3703 strlen(fname)+1, NULL); 3236 3704 … … 3256 3724 uint8_t wct; 3257 3725 uint16_t *vwv = NULL; 3258 uint8_t *inbuf;3259 3726 NTSTATUS status; 3260 3727 3261 status = cli_smb_recv(subreq, state, &inbuf, 4, &wct, &vwv, NULL,3728 status = cli_smb_recv(subreq, state, NULL, 4, &wct, &vwv, NULL, 3262 3729 NULL); 3263 3730 TALLOC_FREE(subreq); … … 3267 3734 3268 3735 state->attr = SVAL(vwv+0,0); 3269 state->size = ( SMB_OFF_T)IVAL(vwv+3,0);3736 state->size = (off_t)IVAL(vwv+3,0); 3270 3737 state->write_time = make_unix_date3(vwv+1, state->zone_offset); 3271 3738 … … 3275 3742 NTSTATUS cli_getatr_recv(struct tevent_req *req, 3276 3743 uint16_t *attr, 3277 SMB_OFF_T*size,3744 off_t *size, 3278 3745 time_t *write_time) 3279 3746 { … … 3300 3767 const char *fname, 3301 3768 uint16_t *attr, 3302 SMB_OFF_T*size,3769 off_t *size, 3303 3770 time_t *write_time) 3304 3771 { 3305 TALLOC_CTX *frame = talloc_stackframe();3306 struct event_context *ev = NULL;3772 TALLOC_CTX *frame = NULL; 3773 struct tevent_context *ev = NULL; 3307 3774 struct tevent_req *req = NULL; 3308 3775 NTSTATUS status = NT_STATUS_OK; 3309 3776 3310 if (cli_has_async_calls(cli)) { 3777 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 3778 return cli_smb2_getatr(cli, 3779 fname, 3780 attr, 3781 size, 3782 write_time); 3783 } 3784 3785 frame = talloc_stackframe(); 3786 3787 if (smbXcli_conn_has_async_calls(cli->conn)) { 3311 3788 /* 3312 3789 * Can't use sync call while an async call is in flight … … 3316 3793 } 3317 3794 3318 ev = event_context_init(frame);3795 ev = samba_tevent_context_init(frame); 3319 3796 if (ev == NULL) { 3320 3797 status = NT_STATUS_NO_MEMORY; … … 3328 3805 } 3329 3806 3330 if (!tevent_req_poll(req, ev)) { 3331 status = map_nt_error_from_unix(errno); 3807 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 3332 3808 goto fail; 3333 3809 } … … 3354 3830 3355 3831 struct tevent_req *cli_setattrE_send(TALLOC_CTX *mem_ctx, 3356 struct event_context *ev,3832 struct tevent_context *ev, 3357 3833 struct cli_state *cli, 3358 3834 uint16_t fnum, … … 3372 3848 SSVAL(state->vwv+0, 0, fnum); 3373 3849 push_dos_date2((uint8_t *)&state->vwv[1], 0, change_time, 3374 cli->serverzone);3850 smb1cli_conn_server_time_zone(cli->conn)); 3375 3851 push_dos_date2((uint8_t *)&state->vwv[3], 0, access_time, 3376 cli->serverzone);3852 smb1cli_conn_server_time_zone(cli->conn)); 3377 3853 push_dos_date2((uint8_t *)&state->vwv[5], 0, write_time, 3378 cli->serverzone);3854 smb1cli_conn_server_time_zone(cli->conn)); 3379 3855 3380 3856 subreq = cli_smb_send(state, ev, cli, SMBsetattrE, additional_flags, … … 3412 3888 time_t write_time) 3413 3889 { 3414 TALLOC_CTX *frame = talloc_stackframe();3415 struct event_context *ev = NULL;3890 TALLOC_CTX *frame = NULL; 3891 struct tevent_context *ev = NULL; 3416 3892 struct tevent_req *req = NULL; 3417 3893 NTSTATUS status = NT_STATUS_OK; 3418 3894 3419 if (cli_has_async_calls(cli)) { 3895 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 3896 return cli_smb2_setattrE(cli, 3897 fnum, 3898 change_time, 3899 access_time, 3900 write_time); 3901 } 3902 3903 frame = talloc_stackframe(); 3904 3905 if (smbXcli_conn_has_async_calls(cli->conn)) { 3420 3906 /* 3421 3907 * Can't use sync call while an async call is in flight … … 3425 3911 } 3426 3912 3427 ev = event_context_init(frame);3913 ev = samba_tevent_context_init(frame); 3428 3914 if (ev == NULL) { 3429 3915 status = NT_STATUS_NO_MEMORY; … … 3443 3929 } 3444 3930 3445 if (!tevent_req_poll(req, ev)) { 3446 status = map_nt_error_from_unix(errno); 3931 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 3447 3932 goto fail; 3448 3933 } … … 3466 3951 3467 3952 struct tevent_req *cli_setatr_send(TALLOC_CTX *mem_ctx, 3468 struct event_context *ev,3953 struct tevent_context *ev, 3469 3954 struct cli_state *cli, 3470 3955 const char *fname, … … 3483 3968 3484 3969 SSVAL(state->vwv+0, 0, attr); 3485 push_dos_date3((uint8_t *)&state->vwv[1], 0, mtime, cli->serverzone);3970 push_dos_date3((uint8_t *)&state->vwv[1], 0, mtime, smb1cli_conn_server_time_zone(cli->conn)); 3486 3971 3487 3972 bytes = talloc_array(state, uint8_t, 1); … … 3490 3975 } 3491 3976 bytes[0] = 4; 3492 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,3977 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname, 3493 3978 strlen(fname)+1, NULL); 3494 3979 if (tevent_req_nomem(bytes, req)) { 3495 3980 return tevent_req_post(req, ev); 3496 3981 } 3497 bytes = TALLOC_REALLOC_ARRAY(state, bytes, uint8_t,3982 bytes = talloc_realloc(state, bytes, uint8_t, 3498 3983 talloc_get_size(bytes)+1); 3499 3984 if (tevent_req_nomem(bytes, req)) { … … 3502 3987 3503 3988 bytes[talloc_get_size(bytes)-1] = 4; 3504 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), "",3989 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), "", 3505 3990 1, NULL); 3506 3991 if (tevent_req_nomem(bytes, req)) { … … 3541 4026 time_t mtime) 3542 4027 { 3543 TALLOC_CTX *frame = talloc_stackframe();3544 struct event_context *ev = NULL;4028 TALLOC_CTX *frame = NULL; 4029 struct tevent_context *ev = NULL; 3545 4030 struct tevent_req *req = NULL; 3546 4031 NTSTATUS status = NT_STATUS_OK; 3547 4032 3548 if (cli_has_async_calls(cli)) { 4033 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 4034 return cli_smb2_setatr(cli, 4035 fname, 4036 attr, 4037 mtime); 4038 } 4039 4040 frame = talloc_stackframe(); 4041 4042 if (smbXcli_conn_has_async_calls(cli->conn)) { 3549 4043 /* 3550 4044 * Can't use sync call while an async call is in flight … … 3554 4048 } 3555 4049 3556 ev = event_context_init(frame);4050 ev = samba_tevent_context_init(frame); 3557 4051 if (ev == NULL) { 3558 4052 status = NT_STATUS_NO_MEMORY; … … 3566 4060 } 3567 4061 3568 if (!tevent_req_poll(req, ev)) { 3569 status = map_nt_error_from_unix(errno); 4062 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 3570 4063 goto fail; 3571 4064 } … … 3589 4082 3590 4083 struct tevent_req *cli_chkpath_send(TALLOC_CTX *mem_ctx, 3591 struct event_context *ev,4084 struct tevent_context *ev, 3592 4085 struct cli_state *cli, 3593 4086 const char *fname) … … 3608 4101 } 3609 4102 bytes[0] = 4; 3610 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,4103 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname, 3611 4104 strlen(fname)+1, NULL); 3612 4105 … … 3646 4139 { 3647 4140 TALLOC_CTX *frame = talloc_stackframe(); 3648 struct event_context *ev = NULL;4141 struct tevent_context *ev = NULL; 3649 4142 struct tevent_req *req = NULL; 3650 4143 char *path2 = NULL; 3651 4144 NTSTATUS status = NT_STATUS_OK; 3652 4145 3653 if ( cli_has_async_calls(cli)) {4146 if (smbXcli_conn_has_async_calls(cli->conn)) { 3654 4147 /* 3655 4148 * Can't use sync call while an async call is in flight … … 3673 4166 } 3674 4167 3675 ev = event_context_init(frame);4168 ev = samba_tevent_context_init(frame); 3676 4169 if (ev == NULL) { 3677 4170 status = NT_STATUS_NO_MEMORY; … … 3685 4178 } 3686 4179 3687 if (!tevent_req_poll(req, ev)) { 3688 status = map_nt_error_from_unix(errno); 4180 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 3689 4181 goto fail; 3690 4182 } … … 3710 4202 3711 4203 struct tevent_req *cli_dskattr_send(TALLOC_CTX *mem_ctx, 3712 struct event_context *ev,4204 struct tevent_context *ev, 3713 4205 struct cli_state *cli) 3714 4206 { … … 3739 4231 uint8_t wct; 3740 4232 uint16_t *vwv = NULL; 3741 uint8_t *inbuf;3742 4233 NTSTATUS status; 3743 4234 3744 status = cli_smb_recv(subreq, state, &inbuf, 4, &wct, &vwv, NULL,4235 status = cli_smb_recv(subreq, state, NULL, 4, &wct, &vwv, NULL, 3745 4236 NULL); 3746 4237 TALLOC_FREE(subreq); … … 3771 4262 NTSTATUS cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail) 3772 4263 { 3773 TALLOC_CTX *frame = talloc_stackframe();3774 struct event_context *ev = NULL;4264 TALLOC_CTX *frame = NULL; 4265 struct tevent_context *ev = NULL; 3775 4266 struct tevent_req *req = NULL; 3776 4267 NTSTATUS status = NT_STATUS_OK; 3777 4268 3778 if (cli_has_async_calls(cli)) { 4269 frame = talloc_stackframe(); 4270 4271 if (smbXcli_conn_has_async_calls(cli->conn)) { 3779 4272 /* 3780 4273 * Can't use sync call while an async call is in flight … … 3784 4277 } 3785 4278 3786 ev = event_context_init(frame);4279 ev = samba_tevent_context_init(frame); 3787 4280 if (ev == NULL) { 3788 4281 status = NT_STATUS_NO_MEMORY; … … 3796 4289 } 3797 4290 3798 if (!tevent_req_poll(req, ev)) { 3799 status = map_nt_error_from_unix(errno); 4291 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 3800 4292 goto fail; 3801 4293 } … … 3806 4298 TALLOC_FREE(frame); 3807 4299 return status; 4300 } 4301 4302 NTSTATUS cli_disk_size(struct cli_state *cli, const char *path, uint64_t *bsize, 4303 uint64_t *total, uint64_t *avail) 4304 { 4305 uint64_t sectors_per_block; 4306 uint64_t bytes_per_sector; 4307 int old_bsize, old_total, old_avail; 4308 NTSTATUS status; 4309 4310 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 4311 return cli_smb2_dskattr(cli, path, bsize, total, avail); 4312 } 4313 4314 /* 4315 * Try the trans2 disk full size info call first. 4316 * We already use this in SMBC_fstatvfs_ctx(). 4317 * Ignore 'actual_available_units' as we only 4318 * care about the quota for the caller. 4319 */ 4320 4321 status = cli_get_fs_full_size_info(cli, 4322 total, 4323 avail, 4324 NULL, 4325 §ors_per_block, 4326 &bytes_per_sector); 4327 4328 /* Try and cope will all varients of "we don't do this call" 4329 and fall back to cli_dskattr. */ 4330 4331 if (NT_STATUS_EQUAL(status,NT_STATUS_NOT_IMPLEMENTED) || 4332 NT_STATUS_EQUAL(status,NT_STATUS_NOT_SUPPORTED) || 4333 NT_STATUS_EQUAL(status,NT_STATUS_INVALID_INFO_CLASS) || 4334 NT_STATUS_EQUAL(status,NT_STATUS_PROCEDURE_NOT_FOUND) || 4335 NT_STATUS_EQUAL(status,NT_STATUS_INVALID_LEVEL) || 4336 NT_STATUS_EQUAL(status,NT_STATUS_INVALID_PARAMETER) || 4337 NT_STATUS_EQUAL(status,NT_STATUS_INVALID_DEVICE_REQUEST) || 4338 NT_STATUS_EQUAL(status,NT_STATUS_INVALID_DEVICE_STATE) || 4339 NT_STATUS_EQUAL(status,NT_STATUS_CTL_FILE_NOT_SUPPORTED) || 4340 NT_STATUS_EQUAL(status,NT_STATUS_UNSUCCESSFUL)) { 4341 goto try_dskattr; 4342 } 4343 4344 if (!NT_STATUS_IS_OK(status)) { 4345 return status; 4346 } 4347 4348 if (bsize) { 4349 *bsize = sectors_per_block * 4350 bytes_per_sector; 4351 } 4352 4353 return NT_STATUS_OK; 4354 4355 try_dskattr: 4356 4357 /* Old SMB1 core protocol fallback. */ 4358 status = cli_dskattr(cli, &old_bsize, &old_total, &old_avail); 4359 if (!NT_STATUS_IS_OK(status)) { 4360 return status; 4361 } 4362 if (bsize) { 4363 *bsize = (uint64_t)old_bsize; 4364 } 4365 if (total) { 4366 *total = (uint64_t)old_total; 4367 } 4368 if (avail) { 4369 *avail = (uint64_t)old_avail; 4370 } 4371 return NT_STATUS_OK; 3808 4372 } 3809 4373 … … 3821 4385 3822 4386 struct tevent_req *cli_ctemp_send(TALLOC_CTX *mem_ctx, 3823 struct event_context *ev,4387 struct tevent_context *ev, 3824 4388 struct cli_state *cli, 3825 4389 const char *path) … … 3843 4407 } 3844 4408 bytes[0] = 4; 3845 bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), path,4409 bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), path, 3846 4410 strlen(path)+1, NULL); 3847 4411 if (tevent_req_nomem(bytes, req)) { … … 3869 4433 uint32_t num_bytes = 0; 3870 4434 uint8_t *bytes = NULL; 3871 uint8_t *inbuf; 3872 3873 status = cli_smb_recv(subreq, state, &inbuf, 1, &wcnt, &vwv, 4435 4436 status = cli_smb_recv(subreq, state, NULL, 1, &wcnt, &vwv, 3874 4437 &num_bytes, &bytes); 3875 4438 TALLOC_FREE(subreq); … … 3926 4489 { 3927 4490 TALLOC_CTX *frame = talloc_stackframe(); 3928 struct event_context *ev;4491 struct tevent_context *ev; 3929 4492 struct tevent_req *req; 3930 4493 NTSTATUS status = NT_STATUS_OK; 3931 4494 3932 if ( cli_has_async_calls(cli)) {4495 if (smbXcli_conn_has_async_calls(cli->conn)) { 3933 4496 /* 3934 4497 * Can't use sync call while an async call is in flight … … 3938 4501 } 3939 4502 3940 ev = event_context_init(frame);4503 ev = samba_tevent_context_init(frame); 3941 4504 if (ev == NULL) { 3942 4505 status = NT_STATUS_NO_MEMORY; … … 3950 4513 } 3951 4514 3952 if (!tevent_req_poll(req, ev)) { 3953 status = map_nt_error_from_unix(errno); 4515 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 3954 4516 goto fail; 3955 4517 } … … 4003 4565 if (ea_namelen == 0 && ea_len == 0) { 4004 4566 data_len = 4; 4005 data = (uint8_t *)SMB_MALLOC(data_len); 4567 data = talloc_array(talloc_tos(), 4568 uint8_t, 4569 data_len); 4006 4570 if (!data) { 4007 4571 return NT_STATUS_NO_MEMORY; … … 4011 4575 } else { 4012 4576 data_len = 4 + 4 + ea_namelen + 1 + ea_len; 4013 data = (uint8_t *)SMB_MALLOC(data_len); 4577 data = talloc_array(talloc_tos(), 4578 uint8_t, 4579 data_len); 4014 4580 if (!data) { 4015 4581 return NT_STATUS_NO_MEMORY; … … 4028 4594 setup, 1, 0, 4029 4595 param, param_len, 2, 4030 data, data_len, cli->max_xmit,4596 data, data_len, CLI_BUFFER_SIZE, 4031 4597 NULL, 4032 4598 NULL, 0, NULL, /* rsetup */ 4033 4599 NULL, 0, NULL, /* rparam */ 4034 4600 NULL, 0, NULL); /* rdata */ 4035 SAFE_FREE(data);4601 talloc_free(data); 4036 4602 return status; 4037 4603 } … … 4047 4613 unsigned int param_len = 0; 4048 4614 uint8_t *param; 4049 size_t srclen = 2*(strlen(path)+1);4050 char *p;4051 4615 NTSTATUS status; 4052 4053 param = SMB_MALLOC_ARRAY(uint8_t, 6+srclen+2); 4616 TALLOC_CTX *frame = NULL; 4617 4618 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 4619 return cli_smb2_set_ea_path(cli, 4620 path, 4621 ea_name, 4622 ea_val, 4623 ea_len); 4624 } 4625 4626 frame = talloc_stackframe(); 4627 4628 param = talloc_array(frame, uint8_t, 6); 4054 4629 if (!param) { 4055 returnNT_STATUS_NO_MEMORY;4056 }4057 memset(param, '\0', 6);4630 status = NT_STATUS_NO_MEMORY; 4631 goto fail; 4632 } 4058 4633 SSVAL(param,0,SMB_INFO_SET_EA); 4059 p = (char *)(¶m[6]); 4060 4061 p += clistr_push(cli, p, path, srclen, STR_TERMINATE); 4062 param_len = PTR_DIFF(p, param); 4634 SSVAL(param,2,0); 4635 SSVAL(param,4,0); 4636 4637 param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn), 4638 path, strlen(path)+1, 4639 NULL); 4640 param_len = talloc_get_size(param); 4063 4641 4064 4642 status = cli_set_ea(cli, TRANSACT2_SETPATHINFO, param, param_len, 4065 4643 ea_name, ea_val, ea_len); 4066 SAFE_FREE(param); 4644 4645 fail: 4646 4647 TALLOC_FREE(frame); 4067 4648 return status; 4068 4649 } … … 4077 4658 { 4078 4659 uint8_t param[6]; 4660 4661 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 4662 return cli_smb2_set_ea_fnum(cli, 4663 fnum, 4664 ea_name, 4665 ea_val, 4666 ea_len); 4667 } 4079 4668 4080 4669 memset(param, 0, 6); … … 4144 4733 } 4145 4734 4146 ea_list = TALLOC_ARRAY(ctx, struct ea_struct, num_eas);4735 ea_list = talloc_array(ctx, struct ea_struct, num_eas); 4147 4736 if (!ea_list) { 4148 4737 return false; … … 4160 4749 ea->flags = CVAL(p,0); 4161 4750 unix_ea_name[0] = '\0'; 4162 pull_ascii _fstring(unix_ea_name, p + 4);4751 pull_ascii(unix_ea_name, p + 4, sizeof(unix_ea_name), rdata_len - PTR_DIFF(p+4, rdata), STR_TERMINATE); 4163 4752 ea->name = talloc_strdup(ea_list, unix_ea_name); 4164 4753 if (!ea->name) { … … 4212 4801 subreq = cli_qpathinfo_send(state, ev, cli, fname, 4213 4802 SMB_INFO_QUERY_ALL_EAS, 4, 4214 cli->max_xmit);4803 CLI_BUFFER_SIZE); 4215 4804 if (tevent_req_nomem(subreq, req)) { 4216 4805 return tevent_req_post(req, ev); … … 4259 4848 struct ea_struct **pea_list) 4260 4849 { 4261 TALLOC_CTX *frame = talloc_stackframe();4262 struct event_context *ev = NULL;4850 TALLOC_CTX *frame = NULL; 4851 struct tevent_context *ev = NULL; 4263 4852 struct tevent_req *req = NULL; 4264 4853 NTSTATUS status = NT_STATUS_NO_MEMORY; 4265 4854 4266 if (cli_has_async_calls(cli)) { 4855 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { 4856 return cli_smb2_get_ea_list_path(cli, 4857 path, 4858 ctx, 4859 pnum_eas, 4860 pea_list); 4861 } 4862 4863 frame = talloc_stackframe(); 4864 4865 if (smbXcli_conn_has_async_calls(cli->conn)) { 4267 4866 /* 4268 4867 * Can't use sync call while an async call is in flight … … 4271 4870 goto fail; 4272 4871 } 4273 ev = event_context_init(frame);4872 ev = samba_tevent_context_init(frame); 4274 4873 if (ev == NULL) { 4275 4874 goto fail; … … 4371 4970 4372 4971 static struct tevent_req *cli_posix_open_internal_send(TALLOC_CTX *mem_ctx, 4373 struct event_context *ev,4972 struct tevent_context *ev, 4374 4973 struct cli_state *cli, 4375 4974 const char *fname, … … 4398 4997 SSVAL(state->param, 0, SMB_POSIX_PATH_OPEN); 4399 4998 4400 state->param = trans2_bytes_push_str(state->param, cli_ucs2(cli), fname,4999 state->param = trans2_bytes_push_str(state->param, smbXcli_conn_use_unicode(cli->conn), fname, 4401 5000 strlen(fname)+1, NULL); 4402 5001 … … 4442 5041 4443 5042 struct tevent_req *cli_posix_open_send(TALLOC_CTX *mem_ctx, 4444 struct event_context *ev,5043 struct tevent_context *ev, 4445 5044 struct cli_state *cli, 4446 5045 const char *fname, … … 4473 5072 4474 5073 TALLOC_CTX *frame = talloc_stackframe(); 4475 struct event_context *ev = NULL;5074 struct tevent_context *ev = NULL; 4476 5075 struct tevent_req *req = NULL; 4477 5076 NTSTATUS status = NT_STATUS_OK; 4478 5077 4479 if ( cli_has_async_calls(cli)) {5078 if (smbXcli_conn_has_async_calls(cli->conn)) { 4480 5079 /* 4481 5080 * Can't use sync call while an async call is in flight … … 4485 5084 } 4486 5085 4487 ev = event_context_init(frame);5086 ev = samba_tevent_context_init(frame); 4488 5087 if (ev == NULL) { 4489 5088 status = NT_STATUS_NO_MEMORY; … … 4502 5101 } 4503 5102 4504 if (!tevent_req_poll(req, ev)) { 4505 status = map_nt_error_from_unix(errno); 5103 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 4506 5104 goto fail; 4507 5105 } … … 4515 5113 4516 5114 struct tevent_req *cli_posix_mkdir_send(TALLOC_CTX *mem_ctx, 4517 struct event_context *ev,5115 struct tevent_context *ev, 4518 5116 struct cli_state *cli, 4519 5117 const char *fname, … … 4532 5130 { 4533 5131 TALLOC_CTX *frame = talloc_stackframe(); 4534 struct event_context *ev = NULL;5132 struct tevent_context *ev = NULL; 4535 5133 struct tevent_req *req = NULL; 4536 5134 NTSTATUS status = NT_STATUS_OK; 4537 5135 4538 if ( cli_has_async_calls(cli)) {5136 if (smbXcli_conn_has_async_calls(cli->conn)) { 4539 5137 /* 4540 5138 * Can't use sync call while an async call is in flight … … 4544 5142 } 4545 5143 4546 ev = event_context_init(frame);5144 ev = samba_tevent_context_init(frame); 4547 5145 if (ev == NULL) { 4548 5146 status = NT_STATUS_NO_MEMORY; … … 4560 5158 } 4561 5159 4562 if (!tevent_req_poll(req, ev)) { 4563 status = map_nt_error_from_unix(errno); 5160 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 4564 5161 goto fail; 4565 5162 } … … 4583 5180 4584 5181 static struct tevent_req *cli_posix_unlink_internal_send(TALLOC_CTX *mem_ctx, 4585 struct event_context *ev,5182 struct tevent_context *ev, 4586 5183 struct cli_state *cli, 4587 5184 const char *fname, … … 4618 5215 4619 5216 struct tevent_req *cli_posix_unlink_send(TALLOC_CTX *mem_ctx, 4620 struct event_context *ev,5217 struct tevent_context *ev, 4621 5218 struct cli_state *cli, 4622 5219 const char *fname) … … 4638 5235 { 4639 5236 TALLOC_CTX *frame = talloc_stackframe(); 4640 struct event_context *ev = NULL;5237 struct tevent_context *ev = NULL; 4641 5238 struct tevent_req *req = NULL; 4642 5239 NTSTATUS status = NT_STATUS_OK; 4643 5240 4644 if ( cli_has_async_calls(cli)) {5241 if (smbXcli_conn_has_async_calls(cli->conn)) { 4645 5242 /* 4646 5243 * Can't use sync call while an async call is in flight … … 4650 5247 } 4651 5248 4652 ev = event_context_init(frame);5249 ev = samba_tevent_context_init(frame); 4653 5250 if (ev == NULL) { 4654 5251 status = NT_STATUS_NO_MEMORY; … … 4665 5262 } 4666 5263 4667 if (!tevent_req_poll(req, ev)) { 4668 status = map_nt_error_from_unix(errno); 5264 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 4669 5265 goto fail; 4670 5266 } … … 4682 5278 4683 5279 struct tevent_req *cli_posix_rmdir_send(TALLOC_CTX *mem_ctx, 4684 struct event_context *ev,5280 struct tevent_context *ev, 4685 5281 struct cli_state *cli, 4686 5282 const char *fname) … … 4699 5295 { 4700 5296 TALLOC_CTX *frame = talloc_stackframe(); 4701 struct event_context *ev = NULL;5297 struct tevent_context *ev = NULL; 4702 5298 struct tevent_req *req = NULL; 4703 5299 NTSTATUS status = NT_STATUS_OK; 4704 5300 4705 if ( cli_has_async_calls(cli)) {5301 if (smbXcli_conn_has_async_calls(cli->conn)) { 4706 5302 /* 4707 5303 * Can't use sync call while an async call is in flight … … 4711 5307 } 4712 5308 4713 ev = event_context_init(frame);5309 ev = samba_tevent_context_init(frame); 4714 5310 if (ev == NULL) { 4715 5311 status = NT_STATUS_NO_MEMORY; … … 4726 5322 } 4727 5323 4728 if (!tevent_req_poll(req, ev)) { 4729 status = map_nt_error_from_unix(errno); 5324 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 4730 5325 goto fail; 4731 5326 } … … 4758 5353 struct tevent_req *req, *subreq; 4759 5354 struct cli_notify_state *state; 5355 unsigned old_timeout; 4760 5356 4761 5357 req = tevent_req_create(mem_ctx, &state, struct cli_notify_state); … … 4767 5363 SSVAL(state->setup, 4, fnum); 4768 5364 SSVAL(state->setup, 6, recursive); 5365 5366 /* 5367 * Notifies should not time out 5368 */ 5369 old_timeout = cli_set_timeout(cli, 0); 4769 5370 4770 5371 subreq = cli_trans_send( … … 4787 5388 0); /* max returned data. */ 4788 5389 5390 cli_set_timeout(cli, old_timeout); 5391 4789 5392 if (tevent_req_nomem(subreq, req)) { 4790 5393 return tevent_req_post(req, ev); … … 4817 5420 4818 5421 while (num_params - ofs > 12) { 4819 uint32_t len= IVAL(params, ofs);5422 uint32_t next = IVAL(params, ofs); 4820 5423 state->num_changes += 1; 4821 5424 4822 if (( len == 0) || (ofs+len>= num_params)) {5425 if ((next == 0) || (ofs+next >= num_params)) { 4823 5426 break; 4824 5427 } 4825 ofs += len;5428 ofs += next; 4826 5429 } 4827 5430 … … 4841 5444 char *name; 4842 5445 4843 if ( (next != 0) && (len+12 != next)) {5446 if (trans_oob(num_params, ofs + 12, len)) { 4844 5447 TALLOC_FREE(params); 4845 5448 tevent_req_nterror( … … 4849 5452 4850 5453 state->changes[i].action = IVAL(params, ofs+4); 4851 ret = clistr_pull_talloc( params, (char *)params, flags2,5454 ret = clistr_pull_talloc(state->changes, (char *)params, flags2, 4852 5455 &name, params+ofs+12, len, 4853 5456 STR_TERMINATE|STR_UNICODE); … … 4882 5485 } 4883 5486 5487 NTSTATUS cli_notify(struct cli_state *cli, uint16_t fnum, uint32_t buffer_size, 5488 uint32_t completion_filter, bool recursive, 5489 TALLOC_CTX *mem_ctx, uint32_t *pnum_changes, 5490 struct notify_change **pchanges) 5491 { 5492 TALLOC_CTX *frame = talloc_stackframe(); 5493 struct tevent_context *ev; 5494 struct tevent_req *req; 5495 NTSTATUS status = NT_STATUS_NO_MEMORY; 5496 5497 if (smbXcli_conn_has_async_calls(cli->conn)) { 5498 /* 5499 * Can't use sync call while an async call is in flight 5500 */ 5501 status = NT_STATUS_INVALID_PARAMETER; 5502 goto fail; 5503 } 5504 ev = samba_tevent_context_init(frame); 5505 if (ev == NULL) { 5506 goto fail; 5507 } 5508 req = cli_notify_send(ev, ev, cli, fnum, buffer_size, 5509 completion_filter, recursive); 5510 if (req == NULL) { 5511 goto fail; 5512 } 5513 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 5514 goto fail; 5515 } 5516 status = cli_notify_recv(req, mem_ctx, pnum_changes, pchanges); 5517 fail: 5518 TALLOC_FREE(frame); 5519 return status; 5520 } 5521 4884 5522 struct cli_qpathinfo_state { 4885 5523 uint8_t *param; … … 4915 5553 SSVAL(state->param, 0, level); 4916 5554 state->param = trans2_bytes_push_str( 4917 state->param, cli_ucs2(cli), fname, strlen(fname)+1, NULL);5555 state->param, smbXcli_conn_use_unicode(cli->conn), fname, strlen(fname)+1, NULL); 4918 5556 if (tevent_req_nomem(state->param, req)) { 4919 5557 return tevent_req_post(req, ev); … … 4991 5629 { 4992 5630 TALLOC_CTX *frame = talloc_stackframe(); 4993 struct event_context *ev;5631 struct tevent_context *ev; 4994 5632 struct tevent_req *req; 4995 5633 NTSTATUS status = NT_STATUS_NO_MEMORY; 4996 5634 4997 if ( cli_has_async_calls(cli)) {5635 if (smbXcli_conn_has_async_calls(cli->conn)) { 4998 5636 /* 4999 5637 * Can't use sync call while an async call is in flight … … 5002 5640 goto fail; 5003 5641 } 5004 ev = event_context_init(frame);5642 ev = samba_tevent_context_init(frame); 5005 5643 if (ev == NULL) { 5006 5644 goto fail; … … 5024 5662 uint8_t param[4]; 5025 5663 uint8_t *data; 5664 uint16_t recv_flags2; 5026 5665 uint32_t min_rdata; 5027 5666 uint8_t *rdata; … … 5083 5722 NTSTATUS status; 5084 5723 5085 status = cli_trans_recv(subreq, state, NULL, NULL, 0, NULL, 5724 status = cli_trans_recv(subreq, state, 5725 &state->recv_flags2, 5726 NULL, 0, NULL, 5086 5727 NULL, 0, NULL, 5087 5728 &state->rdata, state->min_rdata, … … 5094 5735 5095 5736 NTSTATUS cli_qfileinfo_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, 5737 uint16_t *recv_flags2, 5096 5738 uint8_t **rdata, uint32_t *num_rdata) 5097 5739 { … … 5102 5744 if (tevent_req_is_nterror(req, &status)) { 5103 5745 return status; 5746 } 5747 5748 if (recv_flags2 != NULL) { 5749 *recv_flags2 = state->recv_flags2; 5104 5750 } 5105 5751 if (rdata != NULL) { … … 5116 5762 NTSTATUS cli_qfileinfo(TALLOC_CTX *mem_ctx, struct cli_state *cli, 5117 5763 uint16_t fnum, uint16_t level, uint32_t min_rdata, 5118 uint32_t max_rdata, 5764 uint32_t max_rdata, uint16_t *recv_flags2, 5119 5765 uint8_t **rdata, uint32_t *num_rdata) 5120 5766 { 5121 5767 TALLOC_CTX *frame = talloc_stackframe(); 5122 struct event_context *ev;5768 struct tevent_context *ev; 5123 5769 struct tevent_req *req; 5124 5770 NTSTATUS status = NT_STATUS_NO_MEMORY; 5125 5771 5126 if ( cli_has_async_calls(cli)) {5772 if (smbXcli_conn_has_async_calls(cli->conn)) { 5127 5773 /* 5128 5774 * Can't use sync call while an async call is in flight … … 5131 5777 goto fail; 5132 5778 } 5133 ev = event_context_init(frame);5779 ev = samba_tevent_context_init(frame); 5134 5780 if (ev == NULL) { 5135 5781 goto fail; … … 5143 5789 goto fail; 5144 5790 } 5145 status = cli_qfileinfo_recv(req, mem_ctx, r data, num_rdata);5791 status = cli_qfileinfo_recv(req, mem_ctx, recv_flags2, rdata, num_rdata); 5146 5792 fail: 5147 5793 TALLOC_FREE(frame); … … 5156 5802 5157 5803 struct tevent_req *cli_flush_send(TALLOC_CTX *mem_ctx, 5158 struct event_context *ev,5804 struct tevent_context *ev, 5159 5805 struct cli_state *cli, 5160 5806 uint16_t fnum) … … 5200 5846 { 5201 5847 TALLOC_CTX *frame = talloc_stackframe(); 5202 struct event_context *ev;5848 struct tevent_context *ev; 5203 5849 struct tevent_req *req; 5204 5850 NTSTATUS status = NT_STATUS_NO_MEMORY; 5205 5851 5206 if ( cli_has_async_calls(cli)) {5852 if (smbXcli_conn_has_async_calls(cli->conn)) { 5207 5853 /* 5208 5854 * Can't use sync call while an async call is in flight … … 5211 5857 goto fail; 5212 5858 } 5213 ev = event_context_init(frame);5859 ev = samba_tevent_context_init(frame); 5214 5860 if (ev == NULL) { 5215 5861 goto fail; … … 5253 5899 } 5254 5900 state->get_names = get_names; 5255 ret_size = get_names ? cli->max_xmit: 16;5901 ret_size = get_names ? CLI_BUFFER_SIZE : 16; 5256 5902 5257 5903 SIVAL(state->setup + 0, 0, FSCTL_GET_SHADOW_COPY_DATA); … … 5329 5975 names, CH_UTF16LE, CH_UNIX, 5330 5976 src, 2 * sizeof(SHADOW_COPY_LABEL), 5331 &names[i], &converted_size , True);5977 &names[i], &converted_size); 5332 5978 if (!ret) { 5333 5979 TALLOC_FREE(names); … … 5345 5991 { 5346 5992 TALLOC_CTX *frame = talloc_stackframe(); 5347 struct event_context *ev;5993 struct tevent_context *ev; 5348 5994 struct tevent_req *req; 5349 5995 NTSTATUS status = NT_STATUS_NO_MEMORY; 5350 5996 5351 if ( cli_has_async_calls(cli)) {5997 if (smbXcli_conn_has_async_calls(cli->conn)) { 5352 5998 /* 5353 5999 * Can't use sync call while an async call is in flight … … 5356 6002 goto fail; 5357 6003 } 5358 ev = event_context_init(frame);6004 ev = samba_tevent_context_init(frame); 5359 6005 if (ev == NULL) { 5360 6006 goto fail;
Note:
See TracChangeset
for help on using the changeset viewer.