Changeset 740 for vendor/current/librpc/ndr/ndr.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/librpc/ndr/ndr.c
r594 r740 47 47 }; 48 48 49 const struct ndr_syntax_id null_ndr_syntax_id = { 50 { 0, 0, 0, { 0, 0 }, { 0, 0, 0, 0, 0, 0 } }, 51 0 52 }; 53 49 54 /* 50 55 work out the number of bytes needed to align on a n byte boundary … … 59 64 initialise a ndr parse structure from a data blob 60 65 */ 61 _PUBLIC_ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx , struct smb_iconv_convenience *iconv_convenience)66 _PUBLIC_ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx) 62 67 { 63 68 struct ndr_pull *ndr; … … 69 74 ndr->data = blob->data; 70 75 ndr->data_size = blob->length; 71 ndr->iconv_convenience = talloc_reference(ndr, iconv_convenience);72 76 73 77 return ndr; … … 103 107 104 108 /* create a ndr_push structure, ready for some marshalling */ 105 _PUBLIC_ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx , struct smb_iconv_convenience *iconv_convenience)109 _PUBLIC_ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx) 106 110 { 107 111 struct ndr_push *ndr; … … 118 122 return NULL; 119 123 } 120 ndr->iconv_convenience = talloc_reference(ndr, iconv_convenience);121 124 122 125 return ndr; … … 169 172 va_list ap; 170 173 char *s = NULL; 171 int i, ret; 174 uint32_t i; 175 int ret; 172 176 173 177 va_start(ap, format); … … 179 183 } 180 184 185 if (ndr->no_newline) { 186 DEBUGADD(1,("%s", s)); 187 free(s); 188 return; 189 } 190 181 191 for (i=0;i<ndr->depth;i++) { 182 192 DEBUGADD(1,(" ")); … … 187 197 } 188 198 199 _PUBLIC_ void ndr_print_printf_helper(struct ndr_print *ndr, const char *format, ...) 200 { 201 va_list ap; 202 uint32_t i; 203 204 if (!ndr->no_newline) { 205 for (i=0;i<ndr->depth;i++) { 206 printf(" "); 207 } 208 } 209 210 va_start(ap, format); 211 vprintf(format, ap); 212 va_end(ap); 213 if (!ndr->no_newline) { 214 printf("\n"); 215 } 216 } 217 189 218 _PUBLIC_ void ndr_print_string_helper(struct ndr_print *ndr, const char *format, ...) 190 219 { 191 220 va_list ap; 192 int i; 193 194 for (i=0;i<ndr->depth;i++) { 195 ndr->private_data = talloc_asprintf_append_buffer( 196 (char *)ndr->private_data, " "); 221 uint32_t i; 222 223 if (!ndr->no_newline) { 224 for (i=0;i<ndr->depth;i++) { 225 ndr->private_data = talloc_asprintf_append_buffer( 226 (char *)ndr->private_data, " "); 227 } 197 228 } 198 229 … … 201 232 format, ap); 202 233 va_end(ap); 203 ndr->private_data = talloc_asprintf_append_buffer((char *)ndr->private_data, 204 "\n"); 234 if (!ndr->no_newline) { 235 ndr->private_data = talloc_asprintf_append_buffer((char *)ndr->private_data, 236 "\n"); 237 } 205 238 } 206 239 … … 257 290 ndr->flags = 0; 258 291 259 /* this is a s4 hack until we build up the courage to pass260 * this all the way down261 */262 #if _SAMBA_BUILD_ == 4263 ndr->iconv_convenience = smb_iconv_convenience_init(talloc_autofree_context(), "ASCII", "UTF-8", true);264 #endif265 266 292 fn(ndr, name, flags, ptr); 267 293 talloc_free(ndr); … … 285 311 ndr->depth = 1; 286 312 ndr->flags = 0; 287 288 /* this is a s4 hack until we build up the courage to pass289 * this all the way down290 */291 #if _SAMBA_BUILD_ == 4292 ndr->iconv_convenience = smb_iconv_convenience_init(talloc_autofree_context(), "ASCII", "UTF-8", true);293 #endif294 313 295 314 fn(ndr, name, ptr); … … 554 573 subndr->offset = 0; 555 574 subndr->data_size = r_content_size; 556 subndr->iconv_convenience = talloc_reference(subndr, ndr->iconv_convenience);557 575 558 576 if (force_le) { … … 590 608 struct ndr_push *subndr; 591 609 592 subndr = ndr_push_init_ctx(ndr , ndr->iconv_convenience);610 subndr = ndr_push_init_ctx(ndr); 593 611 NDR_ERR_HAVE_NO_MEMORY(subndr); 594 612 subndr->flags = ndr->flags & ~LIBNDR_FLAG_NDR64; … … 812 830 } 813 831 832 _PUBLIC_ enum ndr_err_code ndr_push_pipe_chunk_trailer(struct ndr_push *ndr, int ndr_flags, uint32_t count) 833 { 834 if (ndr->flags & LIBNDR_FLAG_NDR64) { 835 int64_t tmp = 0 - (int64_t)count; 836 uint64_t ncount = tmp; 837 838 NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, ncount)); 839 } 840 841 return NDR_ERR_SUCCESS; 842 } 843 844 _PUBLIC_ enum ndr_err_code ndr_check_pipe_chunk_trailer(struct ndr_pull *ndr, int ndr_flags, uint32_t count) 845 { 846 if (ndr->flags & LIBNDR_FLAG_NDR64) { 847 int64_t tmp = 0 - (int64_t)count; 848 uint64_t ncount1 = tmp; 849 uint64_t ncount2; 850 851 NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &ncount2)); 852 if (ncount1 == ncount2) { 853 return NDR_ERR_SUCCESS; 854 } 855 856 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE, 857 "Bad pipe trailer[%lld should be %lld] size was %lu\"", 858 (unsigned long long)ncount2, 859 (unsigned long long)ncount1, 860 (unsigned long)count); 861 } 862 863 return NDR_ERR_SUCCESS; 864 } 865 814 866 /* 815 867 store a switch value … … 851 903 pull a struct from a blob using NDR 852 904 */ 853 _PUBLIC_ enum ndr_err_code ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience,void *p,905 _PUBLIC_ enum ndr_err_code ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p, 854 906 ndr_pull_flags_fn_t fn) 855 907 { 856 908 struct ndr_pull *ndr; 857 ndr = ndr_pull_init_blob(blob, mem_ctx , iconv_convenience);909 ndr = ndr_pull_init_blob(blob, mem_ctx); 858 910 NDR_ERR_HAVE_NO_MEMORY(ndr); 859 911 NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p)); … … 866 918 */ 867 919 _PUBLIC_ enum ndr_err_code ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, 868 struct smb_iconv_convenience *iconv_convenience,869 920 void *p, ndr_pull_flags_fn_t fn) 870 921 { 871 922 struct ndr_pull *ndr; 872 ndr = ndr_pull_init_blob(blob, mem_ctx, iconv_convenience); 923 uint32_t highest_ofs; 924 ndr = ndr_pull_init_blob(blob, mem_ctx); 873 925 NDR_ERR_HAVE_NO_MEMORY(ndr); 874 926 NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p)); 875 if (ndr->offset < ndr->data_size) { 876 return ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES, 877 "not all bytes consumed ofs[%u] size[%u]", 878 ndr->offset, ndr->data_size); 927 if (ndr->offset > ndr->relative_highest_offset) { 928 highest_ofs = ndr->offset; 929 } else { 930 highest_ofs = ndr->relative_highest_offset; 931 } 932 if (highest_ofs < ndr->data_size) { 933 enum ndr_err_code ret; 934 ret = ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES, 935 "not all bytes consumed ofs[%u] size[%u]", 936 highest_ofs, ndr->data_size); 937 talloc_free(ndr); 938 return ret; 879 939 } 880 940 talloc_free(ndr); … … 886 946 */ 887 947 _PUBLIC_ enum ndr_err_code ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, 888 struct smb_iconv_convenience *iconv_convenience,void *p,948 void *p, 889 949 uint32_t level, ndr_pull_flags_fn_t fn) 890 950 { 891 951 struct ndr_pull *ndr; 892 ndr = ndr_pull_init_blob(blob, mem_ctx , iconv_convenience);952 ndr = ndr_pull_init_blob(blob, mem_ctx); 893 953 NDR_ERR_HAVE_NO_MEMORY(ndr); 894 954 NDR_CHECK_FREE(ndr_pull_set_switch_value(ndr, p, level)); … … 903 963 */ 904 964 _PUBLIC_ enum ndr_err_code ndr_pull_union_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, 905 struct smb_iconv_convenience *iconv_convenience,void *p,965 void *p, 906 966 uint32_t level, ndr_pull_flags_fn_t fn) 907 967 { 908 968 struct ndr_pull *ndr; 909 ndr = ndr_pull_init_blob(blob, mem_ctx, iconv_convenience); 969 uint32_t highest_ofs; 970 ndr = ndr_pull_init_blob(blob, mem_ctx); 910 971 NDR_ERR_HAVE_NO_MEMORY(ndr); 911 972 NDR_CHECK_FREE(ndr_pull_set_switch_value(ndr, p, level)); 912 973 NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p)); 913 if (ndr->offset < ndr->data_size) { 974 if (ndr->offset > ndr->relative_highest_offset) { 975 highest_ofs = ndr->offset; 976 } else { 977 highest_ofs = ndr->relative_highest_offset; 978 } 979 if (highest_ofs < ndr->data_size) { 914 980 enum ndr_err_code ret; 915 981 ret = ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES, 916 982 "not all bytes consumed ofs[%u] size[%u]", 917 ndr->offset, ndr->data_size);983 highest_ofs, ndr->data_size); 918 984 talloc_free(ndr); 919 985 return ret; … … 926 992 push a struct to a blob using NDR 927 993 */ 928 _PUBLIC_ enum ndr_err_code ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience,const void *p, ndr_push_flags_fn_t fn)994 _PUBLIC_ enum ndr_err_code ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *p, ndr_push_flags_fn_t fn) 929 995 { 930 996 struct ndr_push *ndr; 931 ndr = ndr_push_init_ctx(mem_ctx , iconv_convenience);997 ndr = ndr_push_init_ctx(mem_ctx); 932 998 NDR_ERR_HAVE_NO_MEMORY(ndr); 933 999 … … 944 1010 push a union to a blob using NDR 945 1011 */ 946 _PUBLIC_ enum ndr_err_code ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience,void *p,1012 _PUBLIC_ enum ndr_err_code ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p, 947 1013 uint32_t level, ndr_push_flags_fn_t fn) 948 1014 { 949 1015 struct ndr_push *ndr; 950 ndr = ndr_push_init_ctx(mem_ctx , iconv_convenience);1016 ndr = ndr_push_init_ctx(mem_ctx); 951 1017 NDR_ERR_HAVE_NO_MEMORY(ndr); 952 1018 … … 964 1030 generic ndr_size_*() handler for structures 965 1031 */ 966 _PUBLIC_ size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push , struct smb_iconv_convenience *iconv_convenience)1032 _PUBLIC_ size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push) 967 1033 { 968 1034 struct ndr_push *ndr; … … 973 1039 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0; 974 1040 975 ndr = ndr_push_init_ctx(NULL , iconv_convenience);1041 ndr = ndr_push_init_ctx(NULL); 976 1042 if (!ndr) return 0; 977 1043 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE; … … 989 1055 generic ndr_size_*() handler for unions 990 1056 */ 991 _PUBLIC_ size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_fn_t push , struct smb_iconv_convenience *iconv_convenience)1057 _PUBLIC_ size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_fn_t push) 992 1058 { 993 1059 struct ndr_push *ndr; … … 998 1064 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0; 999 1065 1000 ndr = ndr_push_init_ctx(NULL , iconv_convenience);1066 ndr = ndr_push_init_ctx(NULL); 1001 1067 if (!ndr) return 0; 1002 1068 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE; … … 1067 1133 } 1068 1134 1135 /* 1136 push a short relative object - stage1 1137 this is called during SCALARS processing 1138 */ 1139 _PUBLIC_ enum ndr_err_code ndr_push_short_relative_ptr1(struct ndr_push *ndr, const void *p) 1140 { 1141 if (p == NULL) { 1142 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, 0)); 1143 return NDR_ERR_SUCCESS; 1144 } 1145 NDR_CHECK(ndr_push_align(ndr, 2)); 1146 NDR_CHECK(ndr_token_store(ndr, &ndr->relative_list, p, ndr->offset)); 1147 return ndr_push_uint16(ndr, NDR_SCALARS, 0xFFFF); 1148 } 1069 1149 /* 1070 1150 push a relative object - stage2 … … 1092 1172 } 1093 1173 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, save_offset - ndr->relative_base_offset)); 1174 ndr->offset = save_offset; 1175 return NDR_ERR_SUCCESS; 1176 } 1177 /* 1178 push a short relative object - stage2 1179 this is called during buffers processing 1180 */ 1181 _PUBLIC_ enum ndr_err_code ndr_push_short_relative_ptr2(struct ndr_push *ndr, const void *p) 1182 { 1183 uint32_t save_offset; 1184 uint32_t ptr_offset = 0xFFFF; 1185 if (p == NULL) { 1186 return NDR_ERR_SUCCESS; 1187 } 1188 save_offset = ndr->offset; 1189 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &ptr_offset)); 1190 if (ptr_offset > ndr->offset) { 1191 return ndr_push_error(ndr, NDR_ERR_BUFSIZE, 1192 "ndr_push_short_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)", 1193 ptr_offset, ndr->offset); 1194 } 1195 ndr->offset = ptr_offset; 1196 if (save_offset < ndr->relative_base_offset) { 1197 return ndr_push_error(ndr, NDR_ERR_BUFSIZE, 1198 "ndr_push_relative_ptr2 save_offset(%u) < ndr->relative_base_offset(%u)", 1199 save_offset, ndr->relative_base_offset); 1200 } 1201 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, save_offset - ndr->relative_base_offset)); 1094 1202 ndr->offset = save_offset; 1095 1203 return NDR_ERR_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.