Changeset 740 for vendor/current/librpc/rpc/binding.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/librpc/rpc/binding.c
r414 r740 24 24 25 25 #include "includes.h" 26 #include "../../lib/util/util_net.h" 26 27 #include "librpc/gen_ndr/ndr_epmapper.h" 27 28 #include "librpc/gen_ndr/ndr_misc.h" 28 29 #include "librpc/rpc/dcerpc.h" 30 #include "rpc_common.h" 31 29 32 #undef strcasecmp 33 #undef strncasecmp 30 34 31 35 #define MAX_PROTSEQ 10 … … 86 90 {"smb2", DCERPC_SMB2}, 87 91 {"hdrsign", DCERPC_HEADER_SIGNING}, 88 {"ndr64", DCERPC_NDR64} 92 {"ndr64", DCERPC_NDR64}, 93 {"localaddress", DCERPC_LOCALADDRESS} 89 94 }; 90 95 … … 114 119 } else { /* IPX */ 115 120 return talloc_asprintf(mem_ctx, "IPX:%s", 116 data_blob_hex_string (mem_ctx, &epm_floor->rhs.uuid.unknown));121 data_blob_hex_string_upper(mem_ctx, &epm_floor->rhs.uuid.unknown)); 117 122 } 118 123 … … 220 225 for (i=0;i<ARRAY_SIZE(ncacn_options);i++) { 221 226 if (b->flags & ncacn_options[i].flag) { 222 s = talloc_asprintf_append_buffer(s, ",%s", ncacn_options[i].name); 227 if (ncacn_options[i].flag == DCERPC_LOCALADDRESS && b->localaddress) { 228 s = talloc_asprintf_append_buffer(s, ",%s=%s", ncacn_options[i].name, 229 b->localaddress); 230 } else { 231 s = talloc_asprintf_append_buffer(s, ",%s", ncacn_options[i].name); 232 } 223 233 if (!s) return NULL; 224 234 } … … 240 250 int i, j, comma_count; 241 251 242 b = talloc (mem_ctx, struct dcerpc_binding);252 b = talloc_zero(mem_ctx, struct dcerpc_binding); 243 253 if (!b) { 244 254 return NT_STATUS_NO_MEMORY; … … 313 323 b->assoc_group_id = 0; 314 324 b->endpoint = NULL; 325 b->localaddress = NULL; 315 326 316 327 if (!options) { … … 339 350 for (i=0;b->options[i];i++) { 340 351 for (j=0;j<ARRAY_SIZE(ncacn_options);j++) { 341 if (strcasecmp(ncacn_options[j].name, b->options[i]) == 0) { 352 size_t opt_len = strlen(ncacn_options[j].name); 353 if (strncasecmp(ncacn_options[j].name, b->options[i], opt_len) == 0) { 342 354 int k; 355 char c = b->options[i][opt_len]; 356 357 if (ncacn_options[j].flag == DCERPC_LOCALADDRESS && c == '=') { 358 b->localaddress = talloc_strdup(b, &b->options[i][opt_len+1]); 359 } else if (c != 0) { 360 continue; 361 } 362 343 363 b->flags |= ncacn_options[j].flag; 344 364 for (k=i;b->options[k];k++) { … … 376 396 uint16_t if_version=0; 377 397 378 ndr = ndr_pull_init_blob(&epm_floor->lhs.lhs_data, mem_ctx , NULL);398 ndr = ndr_pull_init_blob(&epm_floor->lhs.lhs_data, mem_ctx); 379 399 if (ndr == NULL) { 380 400 talloc_free(mem_ctx); … … 404 424 static DATA_BLOB dcerpc_floor_pack_lhs_data(TALLOC_CTX *mem_ctx, const struct ndr_syntax_id *syntax) 405 425 { 406 struct ndr_push *ndr = ndr_push_init_ctx(mem_ctx, NULL); 426 DATA_BLOB blob; 427 struct ndr_push *ndr = ndr_push_init_ctx(mem_ctx); 407 428 408 429 ndr->flags |= LIBNDR_FLAG_NOALIGN; … … 411 432 ndr_push_uint16(ndr, NDR_SCALARS, syntax->if_version); 412 433 413 return ndr_push_blob(ndr); 434 blob = ndr_push_blob(ndr); 435 talloc_steal(mem_ctx, blob.data); 436 talloc_free(ndr); 437 return blob; 438 } 439 440 static bool dcerpc_floor_pack_rhs_if_version_data( 441 TALLOC_CTX *mem_ctx, const struct ndr_syntax_id *syntax, 442 DATA_BLOB *pblob) 443 { 444 DATA_BLOB blob; 445 struct ndr_push *ndr = ndr_push_init_ctx(mem_ctx); 446 enum ndr_err_code ndr_err; 447 448 if (ndr == NULL) { 449 return false; 450 } 451 452 ndr->flags |= LIBNDR_FLAG_NOALIGN; 453 454 ndr_err = ndr_push_uint16(ndr, NDR_SCALARS, syntax->if_version >> 16); 455 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { 456 return false; 457 } 458 459 blob = ndr_push_blob(ndr); 460 talloc_steal(mem_ctx, blob.data); 461 talloc_free(ndr); 462 *pblob = blob; 463 return true; 414 464 } 415 465 … … 608 658 } 609 659 610 _PUBLIC_ NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx, 611 struct epm_tower *tower,612 struct dcerpc_binding **b_out)660 _PUBLIC_ NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx, 661 struct epm_tower *tower, 662 struct dcerpc_binding **b_out) 613 663 { 614 664 NTSTATUS status; 615 665 struct dcerpc_binding *binding; 616 666 617 binding = talloc(mem_ctx, struct dcerpc_binding); 667 /* 668 * A tower needs to have at least 4 floors to carry useful 669 * information. Floor 3 is the transport identifier which defines 670 * how many floors are required at least. 671 */ 672 if (tower->num_floors < 4) { 673 return NT_STATUS_INVALID_PARAMETER; 674 } 675 676 binding = talloc_zero(mem_ctx, struct dcerpc_binding); 618 677 NT_STATUS_HAVE_NO_MEMORY(binding); 619 678 … … 631 690 } 632 691 633 if (tower->num_floors < 1) {634 return NT_STATUS_OK;635 }636 637 692 /* Set object uuid */ 638 693 status = dcerpc_floor_get_lhs_data(&tower->floors[0], &binding->object); 639 694 640 695 if (!NT_STATUS_IS_OK(status)) { 641 DEBUG(1, ("Error pulling object uuid and version: %s", nt_errstr(status))); 696 DEBUG(1, ("Error pulling object uuid and version: %s", nt_errstr(status))); 642 697 return status; 643 698 } … … 649 704 /* Set endpoint */ 650 705 if (tower->num_floors >= 4) { 651 binding->endpoint = dcerpc_floor_get_rhs_data( mem_ctx, &tower->floors[3]);706 binding->endpoint = dcerpc_floor_get_rhs_data(binding, &tower->floors[3]); 652 707 } else { 653 708 binding->endpoint = NULL; … … 656 711 /* Set network address */ 657 712 if (tower->num_floors >= 5) { 658 binding->host = dcerpc_floor_get_rhs_data( mem_ctx, &tower->floors[4]);713 binding->host = dcerpc_floor_get_rhs_data(binding, &tower->floors[4]); 659 714 NT_STATUS_HAVE_NO_MEMORY(binding->host); 660 715 binding->target_hostname = binding->host; … … 662 717 *b_out = binding; 663 718 return NT_STATUS_OK; 719 } 720 721 _PUBLIC_ struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx, 722 const struct dcerpc_binding *b) 723 { 724 struct dcerpc_binding *n; 725 uint32_t count; 726 727 n = talloc_zero(mem_ctx, struct dcerpc_binding); 728 if (n == NULL) { 729 return NULL; 730 } 731 732 n->transport = b->transport; 733 n->object = b->object; 734 n->flags = b->flags; 735 n->assoc_group_id = b->assoc_group_id; 736 737 if (b->host != NULL) { 738 n->host = talloc_strdup(n, b->host); 739 if (n->host == NULL) { 740 talloc_free(n); 741 return NULL; 742 } 743 } 744 745 if (b->target_hostname != NULL) { 746 n->target_hostname = talloc_strdup(n, b->target_hostname); 747 if (n->target_hostname == NULL) { 748 talloc_free(n); 749 return NULL; 750 } 751 } 752 753 if (b->target_principal != NULL) { 754 n->target_principal = talloc_strdup(n, b->target_principal); 755 if (n->target_principal == NULL) { 756 talloc_free(n); 757 return NULL; 758 } 759 } 760 761 if (b->localaddress != NULL) { 762 n->localaddress = talloc_strdup(n, b->localaddress); 763 if (n->localaddress == NULL) { 764 talloc_free(n); 765 return NULL; 766 } 767 } 768 769 if (b->endpoint != NULL) { 770 n->endpoint = talloc_strdup(n, b->endpoint); 771 if (n->endpoint == NULL) { 772 talloc_free(n); 773 return NULL; 774 } 775 } 776 777 for (count = 0; b->options && b->options[count]; count++); 778 779 if (count > 0) { 780 uint32_t i; 781 782 n->options = talloc_array(n, const char *, count + 1); 783 if (n->options == NULL) { 784 talloc_free(n); 785 return NULL; 786 } 787 788 for (i = 0; i < count; i++) { 789 n->options[i] = talloc_strdup(n->options, b->options[i]); 790 if (n->options[i] == NULL) { 791 talloc_free(n); 792 return NULL; 793 } 794 } 795 n->options[count] = NULL; 796 } 797 798 return n; 664 799 } 665 800 … … 692 827 tower->floors[0].lhs.protocol = EPM_PROTOCOL_UUID; 693 828 694 tower->floors[0].lhs.lhs_data = dcerpc_floor_pack_lhs_data(mem_ctx, &binding->object); 695 696 tower->floors[0].rhs.uuid.unknown = data_blob_talloc_zero(mem_ctx, 2); 829 tower->floors[0].lhs.lhs_data = dcerpc_floor_pack_lhs_data(tower->floors, &binding->object); 830 831 if (!dcerpc_floor_pack_rhs_if_version_data( 832 tower->floors, &binding->object, 833 &tower->floors[0].rhs.uuid.unknown)) { 834 return NT_STATUS_NO_MEMORY; 835 } 697 836 698 837 /* Floor 1 */ 699 838 tower->floors[1].lhs.protocol = EPM_PROTOCOL_UUID; 700 839 701 tower->floors[1].lhs.lhs_data = dcerpc_floor_pack_lhs_data( mem_ctx,840 tower->floors[1].lhs.lhs_data = dcerpc_floor_pack_lhs_data(tower->floors, 702 841 &ndr_transfer_syntax); 703 842 704 tower->floors[1].rhs.uuid.unknown = data_blob_talloc_zero( mem_ctx, 2);843 tower->floors[1].rhs.uuid.unknown = data_blob_talloc_zero(tower->floors, 2); 705 844 706 845 /* Floor 2 to num_protocols */ 707 846 for (i = 0; i < num_protocols; i++) { 708 847 tower->floors[2 + i].lhs.protocol = protseq[i]; 709 tower->floors[2 + i].lhs.lhs_data = data_blob_talloc( mem_ctx, NULL, 0);848 tower->floors[2 + i].lhs.lhs_data = data_blob_talloc(tower->floors, NULL, 0); 710 849 ZERO_STRUCT(tower->floors[2 + i].rhs); 711 dcerpc_floor_set_rhs_data( mem_ctx, &tower->floors[2 + i], "");850 dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[2 + i], ""); 712 851 } 713 852 714 853 /* The 4th floor contains the endpoint */ 715 854 if (num_protocols >= 2 && binding->endpoint) { 716 status = dcerpc_floor_set_rhs_data( mem_ctx, &tower->floors[3], binding->endpoint);855 status = dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[3], binding->endpoint); 717 856 if (NT_STATUS_IS_ERR(status)) { 718 857 return status; … … 722 861 /* The 5th contains the network address */ 723 862 if (num_protocols >= 3 && binding->host) { 724 if (is_ipaddress(binding->host)) { 725 status = dcerpc_floor_set_rhs_data(mem_ctx, &tower->floors[4], 863 if (is_ipaddress(binding->host) || 864 (binding->host[0] == '\\' && binding->host[1] == '\\')) { 865 status = dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[4], 726 866 binding->host); 727 867 } else { … … 731 871 a wildcard all-zeros IP for the server to 732 872 fill in */ 733 status = dcerpc_floor_set_rhs_data( mem_ctx, &tower->floors[4],873 status = dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[4], 734 874 "0.0.0.0"); 735 875 }
Note:
See TracChangeset
for help on using the changeset viewer.