Line data Source code
1 : #include "includes.h" 2 : #include "librpc/gen_ndr/ndr_claims.h" 3 : #include "librpc/ndr/ndr_claims.h" 4 : 5 : #include "librpc/ndr/ndr_compression.h" 6 : #include "lib/compression/lzxpress_huffman.h" 7 : 8 1977 : enum ndr_compression_alg ndr_claims_compression_alg(enum CLAIMS_COMPRESSION_FORMAT wire_alg) 9 : { 10 1977 : switch (wire_alg) { 11 1313 : case CLAIMS_COMPRESSION_FORMAT_NONE: 12 1313 : return NDR_COMPRESSION_NONE; 13 : 14 0 : case CLAIMS_COMPRESSION_FORMAT_LZNT1: 15 0 : return NDR_COMPRESSION_INVALID; 16 : 17 0 : case CLAIMS_COMPRESSION_FORMAT_XPRESS: 18 0 : return NDR_COMPRESSION_INVALID; 19 : 20 617 : case CLAIMS_COMPRESSION_FORMAT_XPRESS_HUFF: 21 617 : return NDR_COMPRESSION_XPRESS_HUFF_RAW; 22 : } 23 0 : return NDR_COMPRESSION_INVALID; 24 : } 25 : 26 : 27 2151 : enum CLAIMS_COMPRESSION_FORMAT ndr_claims_actual_wire_compression_alg(enum CLAIMS_COMPRESSION_FORMAT specified_compression, 28 : size_t uncompressed_claims_size) { 29 2151 : if (uncompressed_claims_size < CLAIM_UPPER_COMPRESSION_THRESHOLD) { 30 1776 : return CLAIMS_COMPRESSION_FORMAT_NONE; 31 : } 32 : 33 357 : return specified_compression; 34 : } 35 : 36 717 : size_t ndr_claims_compressed_size(struct CLAIMS_SET_NDR *claims_set, 37 : enum CLAIMS_COMPRESSION_FORMAT wire_alg, 38 : int flags) 39 : { 40 717 : TALLOC_CTX *frame = NULL; 41 13 : DATA_BLOB tmp_blob; 42 13 : uint8_t * tmp_compressed; 43 13 : ssize_t compressed_size; 44 13 : enum ndr_err_code ndr_err; 45 13 : enum CLAIMS_COMPRESSION_FORMAT actual_wire_alg; 46 : 47 717 : if (claims_set == NULL) { 48 0 : return 0; 49 : } 50 : 51 717 : frame = talloc_stackframe(); 52 : 53 717 : ndr_err = ndr_push_struct_blob(&tmp_blob, 54 : frame, 55 : claims_set, 56 : (ndr_push_flags_fn_t)ndr_push_CLAIMS_SET_NDR); 57 717 : if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { 58 0 : DBG_ERR("Failed to push claims while determining compressed size\n"); 59 0 : TALLOC_FREE(frame); 60 0 : return 0; 61 : } 62 : 63 717 : actual_wire_alg = ndr_claims_actual_wire_compression_alg(wire_alg, 64 : tmp_blob.length); 65 : 66 717 : switch (actual_wire_alg) { 67 594 : case CLAIMS_COMPRESSION_FORMAT_NONE: 68 594 : TALLOC_FREE(frame); 69 594 : return tmp_blob.length; 70 : 71 123 : case CLAIMS_COMPRESSION_FORMAT_XPRESS_HUFF: 72 127 : compressed_size = lzxpress_huffman_compress_talloc(frame, 73 123 : tmp_blob.data, 74 : tmp_blob.length, 75 : &tmp_compressed); 76 : 77 123 : TALLOC_FREE(frame); 78 : 79 123 : if (compressed_size < 0) { 80 0 : DBG_ERR("Failed to compress claims (for determining compressed size)\n"); 81 0 : return 0; 82 : } 83 123 : return compressed_size; 84 : 85 0 : default: 86 0 : TALLOC_FREE(frame); 87 0 : DBG_ERR("Invalid chosen compression algorithm while determining compressed claim size\n"); 88 0 : return 0; 89 : } 90 : }