Changeset 740 for vendor/current/source3/libsmb/clidfs.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/libsmb/clidfs.c
r597 r740 21 21 22 22 #include "includes.h" 23 #include "libsmb/libsmb.h" 24 #include "libsmb/clirap.h" 25 #include "msdfs.h" 26 #include "trans2.h" 27 #include "libsmb/nmblib.h" 23 28 24 29 /******************************************************************** … … 128 133 129 134 /* have to open a new connection */ 130 if (!(c=cli_initialise_ex(get_cmdline_auth_info_signing_state(auth_info)))) { 135 c = cli_initialise_ex(get_cmdline_auth_info_signing_state(auth_info)); 136 if (c == NULL) { 131 137 d_printf("Connection to %s failed\n", server_n); 132 if (c) {133 cli_shutdown(c);134 }135 138 return NULL; 136 139 } … … 321 324 } 322 325 323 if (referring_cli && referring_cli-> posix_capabilities) {326 if (referring_cli && referring_cli->requested_posix_capabilities) { 324 327 uint16 major, minor; 325 328 uint32 caplow, caphigh; … … 352 355 353 356 /* Search to the start of the list. */ 354 for (p = cli; p; p = p->prev) {357 for (p = cli; p; p = DLIST_PREV(p)) { 355 358 if (strequal(server, p->desthost) && 356 359 strequal(share,p->share)) { … … 453 456 **********************************************************************/ 454 457 455 static voidsplit_dfs_path(TALLOC_CTX *ctx,458 static bool split_dfs_path(TALLOC_CTX *ctx, 456 459 const char *nodepath, 457 460 char **pp_server, … … 468 471 path = talloc_strdup(ctx, nodepath); 469 472 if (!path) { 470 return;473 goto fail; 471 474 } 472 475 473 476 if ( path[0] != '\\' ) { 474 return;477 goto fail; 475 478 } 476 479 477 480 p = strchr_m( path + 1, '\\' ); 478 481 if ( !p ) { 479 return;482 goto fail; 480 483 } 481 484 … … 492 495 *pp_extrapath = talloc_strdup(ctx, ""); 493 496 } 497 if (*pp_extrapath == NULL) { 498 goto fail; 499 } 494 500 495 501 *pp_share = talloc_strdup(ctx, p); 502 if (*pp_share == NULL) { 503 goto fail; 504 } 505 496 506 *pp_server = talloc_strdup(ctx, &path[1]); 507 if (*pp_server == NULL) { 508 goto fail; 509 } 510 511 TALLOC_FREE(path); 512 return true; 513 514 fail: 515 TALLOC_FREE(*pp_share); 516 TALLOC_FREE(*pp_extrapath); 517 TALLOC_FREE(path); 518 return false; 497 519 } 498 520 … … 565 587 } 566 588 567 if (cli-> posix_capabilities & CIFS_UNIX_POSIX_PATHNAMES_CAP) {589 if (cli->requested_posix_capabilities & CIFS_UNIX_POSIX_PATHNAMES_CAP) { 568 590 path_sep = '/'; 569 591 } … … 581 603 ********************************************************************/ 582 604 583 static bool cli_dfs_check_error( struct cli_state *cli, NTSTATUS status ) 584 { 585 uint32 flgs2 = SVAL(cli->inbuf,smb_flg2); 586 605 static bool cli_dfs_check_error(struct cli_state *cli, NTSTATUS expected, 606 NTSTATUS status) 607 { 587 608 /* only deal with DS when we negotiated NT_STATUS codes and UNICODE */ 588 609 589 if (!((flgs2&FLAGS2_32_BIT_ERROR_CODES) && 590 (flgs2&FLAGS2_UNICODE_STRINGS))) 591 return false; 592 593 if (NT_STATUS_EQUAL(status, NT_STATUS(IVAL(cli->inbuf,smb_rcls)))) 610 if (!(cli->capabilities & CAP_UNICODE)) { 611 return false; 612 } 613 if (!(cli->capabilities & CAP_STATUS32)) { 614 return false; 615 } 616 if (NT_STATUS_EQUAL(status, expected)) { 594 617 return true; 595 618 } 596 619 return false; 597 620 } … … 601 624 ********************************************************************/ 602 625 603 boolcli_dfs_get_referral(TALLOC_CTX *ctx,626 NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx, 604 627 struct cli_state *cli, 605 628 const char *path, 606 CLIENT_DFS_REFERRAL**refs,629 struct client_dfs_referral **refs, 607 630 size_t *num_refs, 608 631 size_t *consumed) … … 610 633 unsigned int data_len = 0; 611 634 unsigned int param_len = 0; 612 uint16 setup = TRANSACT2_GET_DFS_REFERRAL;613 char*param = NULL;614 char *rparam=NULL, *rdata=NULL;635 uint16 setup[1]; 636 uint8_t *param = NULL; 637 uint8_t *rdata = NULL; 615 638 char *p; 616 639 char *endp; … … 620 643 uint16_t consumed_ucs; 621 644 uint16 num_referrals; 622 CLIENT_DFS_REFERRAL*referrals = NULL;623 bool ret = false;645 struct client_dfs_referral *referrals = NULL; 646 NTSTATUS status; 624 647 625 648 *num_refs = 0; 626 649 *refs = NULL; 627 650 628 param = SMB_MALLOC_ARRAY(char, 2+pathlen+2); 651 SSVAL(setup, 0, TRANSACT2_GET_DFS_REFERRAL); 652 653 param = SMB_MALLOC_ARRAY(uint8_t, 2+pathlen+2); 629 654 if (!param) { 655 status = NT_STATUS_NO_MEMORY; 630 656 goto out; 631 657 } 632 658 SSVAL(param, 0, 0x03); /* max referral level */ 633 p = ¶m[2];659 p = (char *)(¶m[2]); 634 660 635 661 path_ucs = (smb_ucs2_t *)p; … … 637 663 param_len = PTR_DIFF(p, param); 638 664 639 if (!cli_send_trans(cli, SMBtrans2, 640 NULL, /* name */ 641 -1, 0, /* fid, flags */ 642 &setup, 1, 0, /* setup, length, max */ 643 param, param_len, 2, /* param, length, max */ 644 NULL, 0, cli->max_xmit /* data, length, max */ 645 )) { 665 status = cli_trans(talloc_tos(), cli, SMBtrans2, 666 NULL, 0xffff, 0, 0, 667 setup, 1, 0, 668 param, param_len, 2, 669 NULL, 0, cli->max_xmit, 670 NULL, 671 NULL, 0, NULL, /* rsetup */ 672 NULL, 0, NULL, 673 &rdata, 4, &data_len); 674 if (!NT_STATUS_IS_OK(status)) { 646 675 goto out; 647 676 } 648 649 if (!cli_receive_trans(cli, SMBtrans2,650 &rparam, ¶m_len,651 &rdata, &data_len)) {652 goto out;653 }654 655 677 if (data_len < 4) { 656 678 goto out; 657 679 } 658 680 659 endp = rdata + data_len;681 endp = (char *)rdata + data_len; 660 682 661 683 consumed_ucs = SVAL(rdata, 0); … … 689 711 uint16 node_offset; 690 712 691 referrals = TALLOC_ARRAY(ctx, CLIENT_DFS_REFERRAL,692 num_referrals);713 referrals = talloc_array(ctx, struct client_dfs_referral, 714 num_referrals); 693 715 694 716 if (!referrals) { … … 697 719 /* start at the referrals array */ 698 720 699 p = rdata+8;721 p = (char *)rdata+8; 700 722 for (i=0; i<num_referrals && p < endp; i++) { 701 723 if (p + 18 > endp) { … … 718 740 } 719 741 clistr_pull_talloc(ctx, cli->inbuf, 742 SVAL(cli->inbuf, smb_flg2), 720 743 &referrals[i].dfspath, 721 744 p+node_offset, -1, … … 732 755 } 733 756 734 ret = true;735 736 757 *num_refs = num_referrals; 737 758 *refs = referrals; … … 741 762 TALLOC_FREE(consumed_path); 742 763 SAFE_FREE(param); 743 SAFE_FREE(rdata); 744 SAFE_FREE(rparam); 745 return ret; 764 TALLOC_FREE(rdata); 765 return status; 746 766 } 747 767 … … 757 777 char **pp_targetpath) 758 778 { 759 CLIENT_DFS_REFERRAL*refs = NULL;779 struct client_dfs_referral *refs = NULL; 760 780 size_t num_refs = 0; 761 781 size_t consumed = 0; … … 773 793 SMB_STRUCT_STAT sbuf; 774 794 uint32 attributes; 795 NTSTATUS status; 775 796 776 797 if ( !rootcli || !path || !targetcli ) { … … 803 824 } 804 825 805 if (cli_qpathinfo_basic( rootcli, dfs_path, &sbuf, &attributes)) { 826 status = cli_qpathinfo_basic( rootcli, dfs_path, &sbuf, &attributes); 827 if (NT_STATUS_IS_OK(status)) { 806 828 /* This is an ordinary path, just return it. */ 807 829 *targetcli = rootcli; … … 815 837 /* Special case where client asked for a path that does not exist */ 816 838 817 if (cli_dfs_check_error(rootcli, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { 839 if (cli_dfs_check_error(rootcli, NT_STATUS_OBJECT_NAME_NOT_FOUND, 840 status)) { 818 841 *targetcli = rootcli; 819 842 *pp_targetpath = talloc_strdup(ctx, path); … … 826 849 /* We got an error, check for DFS referral. */ 827 850 828 if (!cli_dfs_check_error(rootcli, NT_STATUS_PATH_NOT_COVERED)) { 851 if (!cli_dfs_check_error(rootcli, NT_STATUS_PATH_NOT_COVERED, 852 status)) { 829 853 return false; 830 854 } … … 845 869 } 846 870 847 if (!cli_dfs_get_referral(ctx, cli_ipc, dfs_path, &refs, 848 &num_refs, &consumed) || !num_refs) { 871 status = cli_dfs_get_referral(ctx, cli_ipc, dfs_path, &refs, 872 &num_refs, &consumed); 873 if (!NT_STATUS_IS_OK(status) || !num_refs) { 849 874 return false; 850 875 } … … 855 880 return false; 856 881 } 857 split_dfs_path(ctx, refs[0].dfspath, &server, &share, &extrapath ); 858 859 if (!server || !share) { 882 if (!split_dfs_path(ctx, refs[0].dfspath, &server, &share, 883 &extrapath)) { 860 884 return false; 861 885 } … … 997 1021 const char *domain) 998 1022 { 999 CLIENT_DFS_REFERRAL*refs = NULL;1023 struct client_dfs_referral *refs = NULL; 1000 1024 size_t num_refs = 0; 1001 1025 size_t consumed = 0; … … 1004 1028 uint16 cnum; 1005 1029 char *newextrapath = NULL; 1030 NTSTATUS status; 1006 1031 1007 1032 if (!cli || !sharename) { … … 1031 1056 1032 1057 if (force_encrypt) { 1033 NTSTATUSstatus = cli_cm_force_encryption(cli,1058 status = cli_cm_force_encryption(cli, 1034 1059 username, 1035 1060 password, … … 1041 1066 } 1042 1067 1043 res = cli_dfs_get_referral(ctx, cli, fullpath, &refs, &num_refs, &consumed); 1044 1045 if (!cli_tdis(cli)) { 1068 status = cli_dfs_get_referral(ctx, cli, fullpath, &refs, 1069 &num_refs, &consumed); 1070 res = NT_STATUS_IS_OK(status); 1071 1072 status = cli_tdis(cli); 1073 if (!NT_STATUS_IS_OK(status)) { 1046 1074 return false; 1047 1075 } … … 1057 1085 } 1058 1086 1059 split_dfs_path(ctx, refs[0].dfspath, pp_newserver, 1060 pp_newshare, &newextrapath ); 1061 1062 if ((*pp_newserver == NULL) || (*pp_newshare == NULL)) { 1087 if (!split_dfs_path(ctx, refs[0].dfspath, pp_newserver, 1088 pp_newshare, &newextrapath)) { 1063 1089 return false; 1064 1090 }
Note:
See TracChangeset
for help on using the changeset viewer.