| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 | DATA BLOB
|
|---|
| 4 |
|
|---|
| 5 | Copyright (C) Andrew Tridgell 2001
|
|---|
| 6 | Copyright (C) Andrew Bartlett 2001
|
|---|
| 7 |
|
|---|
| 8 | This program is free software; you can redistribute it and/or modify
|
|---|
| 9 | it under the terms of the GNU General Public License as published by
|
|---|
| 10 | the Free Software Foundation; either version 3 of the License, or
|
|---|
| 11 | (at your option) any later version.
|
|---|
| 12 |
|
|---|
| 13 | This program is distributed in the hope that it will be useful,
|
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 16 | GNU General Public License for more details.
|
|---|
| 17 |
|
|---|
| 18 | You should have received a copy of the GNU General Public License
|
|---|
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | /* This is a public header file that is installed as part of Samba.
|
|---|
| 23 | * If you remove any functions or change their signature, update
|
|---|
| 24 | * the so version number. */
|
|---|
| 25 |
|
|---|
| 26 | #ifndef _SAMBA_DATABLOB_H_
|
|---|
| 27 | #define _SAMBA_DATABLOB_H_
|
|---|
| 28 |
|
|---|
| 29 | #ifndef _PUBLIC_
|
|---|
| 30 | #define _PUBLIC_
|
|---|
| 31 | #endif
|
|---|
| 32 |
|
|---|
| 33 | #include <talloc.h>
|
|---|
| 34 | #include <stdint.h>
|
|---|
| 35 |
|
|---|
| 36 | /* used to hold an arbitrary blob of data */
|
|---|
| 37 | typedef struct datablob {
|
|---|
| 38 | uint8_t *data;
|
|---|
| 39 | size_t length;
|
|---|
| 40 | } DATA_BLOB;
|
|---|
| 41 |
|
|---|
| 42 | struct data_blob_list_item {
|
|---|
| 43 | struct data_blob_list_item *prev,*next;
|
|---|
| 44 | DATA_BLOB blob;
|
|---|
| 45 | };
|
|---|
| 46 |
|
|---|
| 47 | /* by making struct ldb_val and DATA_BLOB the same, we can simplify
|
|---|
| 48 | a fair bit of code */
|
|---|
| 49 | #define ldb_val datablob
|
|---|
| 50 |
|
|---|
| 51 | #define data_blob(ptr, size) data_blob_named(ptr, size, "DATA_BLOB: "__location__)
|
|---|
| 52 | #define data_blob_talloc(ctx, ptr, size) data_blob_talloc_named(ctx, ptr, size, "DATA_BLOB: "__location__)
|
|---|
| 53 | #define data_blob_dup_talloc(ctx, blob) data_blob_talloc_named(ctx, (blob)->data, (blob)->length, "DATA_BLOB: "__location__)
|
|---|
| 54 |
|
|---|
| 55 | /**
|
|---|
| 56 | construct a data blob, must be freed with data_blob_free()
|
|---|
| 57 | you can pass NULL for p and get a blank data blob
|
|---|
| 58 | **/
|
|---|
| 59 | _PUBLIC_ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name);
|
|---|
| 60 |
|
|---|
| 61 | /**
|
|---|
| 62 | construct a data blob, using supplied TALLOC_CTX
|
|---|
| 63 | **/
|
|---|
| 64 | _PUBLIC_ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name);
|
|---|
| 65 |
|
|---|
| 66 | /**
|
|---|
| 67 | construct a zero data blob, using supplied TALLOC_CTX.
|
|---|
| 68 | use this sparingly as it initialises data - better to initialise
|
|---|
| 69 | yourself if you want specific data in the blob
|
|---|
| 70 | **/
|
|---|
| 71 | _PUBLIC_ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length);
|
|---|
| 72 |
|
|---|
| 73 | /**
|
|---|
| 74 | free a data blob
|
|---|
| 75 | **/
|
|---|
| 76 | _PUBLIC_ void data_blob_free(DATA_BLOB *d);
|
|---|
| 77 |
|
|---|
| 78 | /**
|
|---|
| 79 | clear a DATA_BLOB's contents
|
|---|
| 80 | **/
|
|---|
| 81 | _PUBLIC_ void data_blob_clear(DATA_BLOB *d);
|
|---|
| 82 |
|
|---|
| 83 | /**
|
|---|
| 84 | free a data blob and clear its contents
|
|---|
| 85 | **/
|
|---|
| 86 | _PUBLIC_ void data_blob_clear_free(DATA_BLOB *d);
|
|---|
| 87 |
|
|---|
| 88 | /**
|
|---|
| 89 | check if two data blobs are equal
|
|---|
| 90 | **/
|
|---|
| 91 | _PUBLIC_ int data_blob_cmp(const DATA_BLOB *d1, const DATA_BLOB *d2);
|
|---|
| 92 |
|
|---|
| 93 | /**
|
|---|
| 94 | print the data_blob as hex string
|
|---|
| 95 | **/
|
|---|
| 96 | _PUBLIC_ char *data_blob_hex_string_upper(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob);
|
|---|
| 97 |
|
|---|
| 98 | /**
|
|---|
| 99 | print the data_blob as hex string
|
|---|
| 100 | **/
|
|---|
| 101 | _PUBLIC_ char *data_blob_hex_string_lower(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob);
|
|---|
| 102 |
|
|---|
| 103 | /**
|
|---|
| 104 | useful for constructing data blobs in test suites, while
|
|---|
| 105 | avoiding const warnings
|
|---|
| 106 | **/
|
|---|
| 107 | _PUBLIC_ DATA_BLOB data_blob_string_const(const char *str);
|
|---|
| 108 |
|
|---|
| 109 | /**
|
|---|
| 110 | useful for constructing data blobs in test suites, while
|
|---|
| 111 | avoiding const warnings
|
|---|
| 112 |
|
|---|
| 113 | includes the terminating null character (as opposed to data_blo_string_const)
|
|---|
| 114 | **/
|
|---|
| 115 | _PUBLIC_ DATA_BLOB data_blob_string_const_null(const char *str);
|
|---|
| 116 |
|
|---|
| 117 | /**
|
|---|
| 118 | * Create a new data blob from const data
|
|---|
| 119 | */
|
|---|
| 120 | _PUBLIC_ DATA_BLOB data_blob_const(const void *p, size_t length);
|
|---|
| 121 |
|
|---|
| 122 | /**
|
|---|
| 123 | realloc a data_blob
|
|---|
| 124 | **/
|
|---|
| 125 | _PUBLIC_ bool data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length);
|
|---|
| 126 |
|
|---|
| 127 | /**
|
|---|
| 128 | append some data to a data blob
|
|---|
| 129 | **/
|
|---|
| 130 | _PUBLIC_ bool data_blob_append(TALLOC_CTX *mem_ctx, DATA_BLOB *blob,
|
|---|
| 131 | const void *p, size_t length);
|
|---|
| 132 |
|
|---|
| 133 | extern const DATA_BLOB data_blob_null;
|
|---|
| 134 |
|
|---|
| 135 | #endif /* _SAMBA_DATABLOB_H_ */
|
|---|