diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/talloc/configure.ac | 2 | ||||
-rwxr-xr-x | lib/talloc/script/abi_checks.sh | 27 | ||||
-rw-r--r-- | lib/talloc/script/mksyms.awk | 19 | ||||
-rwxr-xr-x | lib/talloc/script/mksyms.sh | 19 | ||||
-rwxr-xr-x | lib/talloc/script/release-script.sh (renamed from lib/talloc/release-script.sh) | 10 | ||||
-rw-r--r-- | lib/talloc/talloc.exports | 24 | ||||
-rw-r--r-- | lib/talloc/talloc.signatures | 51 | ||||
-rw-r--r-- | lib/tdr/tdr.c | 10 | ||||
-rw-r--r-- | lib/tdr/tdr.h | 2 | ||||
-rw-r--r-- | lib/tevent/tevent_signal.c | 2 | ||||
-rw-r--r-- | lib/util/asn1.c | 102 | ||||
-rw-r--r-- | lib/util/asn1.h | 4 | ||||
-rw-r--r-- | lib/util/talloc_stack.h | 2 | ||||
-rw-r--r-- | lib/util/tests/asn1_tests.c | 260 | ||||
-rw-r--r-- | lib/util/tests/data_blob.c | 2 | ||||
-rw-r--r-- | lib/util/util.c | 18 | ||||
-rw-r--r-- | lib/util/util_tdb.c | 2 |
17 files changed, 459 insertions, 97 deletions
diff --git a/lib/talloc/configure.ac b/lib/talloc/configure.ac index a169f79724..c1b1d2e4a1 100644 --- a/lib/talloc/configure.ac +++ b/lib/talloc/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ(2.50) -AC_INIT(talloc, 2.0.0) +AC_INIT(talloc, 2.0.1) AC_CONFIG_SRCDIR([talloc.c]) AC_SUBST(datarootdir) AC_CONFIG_HEADER(config.h) diff --git a/lib/talloc/script/abi_checks.sh b/lib/talloc/script/abi_checks.sh index ba60ed003a..66c4e60e45 100755 --- a/lib/talloc/script/abi_checks.sh +++ b/lib/talloc/script/abi_checks.sh @@ -33,6 +33,7 @@ LANG=C; export LANG LC_ALL=C; export LC_ALL LC_COLLATE=C; export LC_COLLATE +exit_status=0 script=$0 dir_name=$(dirname ${script}) @@ -58,34 +59,22 @@ signatures_file_check=${signatures_file}.check ${dir_name}/mksyms.sh awk ${exports_file_check} ${headers} 2>&1 > /dev/null +cat ${headers} | ${dir_name}/mksigs.pl | sort| uniq > ${signatures_file_check} 2> /dev/null -cat ${headers} | ${dir_name}/mksigs.pl > ${signatures_file_check} 2> /dev/null - -normalize_exports_file() { - filename=$1 - cat ${filename} \ - | sed -e 's/^[ \t]*//g' \ - | sed -e 's/^$//g' \ - | sed -e 's/^#.*$//g' \ - | sort | uniq > ${filename}.sort -} - -normalize_exports_file ${exports_file} -normalize_exports_file ${exports_file_check} - -normalize_exports_file ${signatures_file} -normalize_exports_file ${signatures_file_check} - -diff -u ${exports_file}.sort ${exports_file_check}.sort +diff -u ${exports_file} ${exports_file_check} if test "x$?" != "x0" ; then echo "WARNING: possible ABI change detected in exports!" + let exit_status++ else echo "exports check: OK" fi -diff -u ${signatures_file}.sort ${signatures_file_check}.sort +diff -u ${signatures_file} ${signatures_file_check} if test "x$?" != "x0" ; then echo "WARNING: possible ABI change detected in signatures!" + let exit_status++ else echo "signatures check: OK" fi + +exit $exit_status diff --git a/lib/talloc/script/mksyms.awk b/lib/talloc/script/mksyms.awk index ca14da0f21..8775faff3f 100644 --- a/lib/talloc/script/mksyms.awk +++ b/lib/talloc/script/mksyms.awk @@ -8,25 +8,12 @@ # BEGIN { inheader=0; - current_file=""; - print "#" - print "# This file is automatically generated with \"make symbols\". DO NOT EDIT " - print "#" - print "{" - print "\tglobal:" } END { - print"" - print "\tlocal: *;" - print "};" } { - if (FILENAME!=current_file) { - print "\t\t# The following definitions come from",FILENAME - current_file=FILENAME - } if (inheader) { if (match($0,"[)][^()]*[;][ \t]*$")) { inheader = 0; @@ -42,7 +29,7 @@ END { /^extern[ \t]+[^()]+[;][ \t]*$/ { gsub(/[^ \t]+[ \t]+/, ""); sub(/[;][ \t]*$/, ""); - printf "\t\t%s;\n", $0; + printf " %s;\n", $0; next; } @@ -61,7 +48,7 @@ END { sub(/[(].*$/, ""); gsub(/[^ \t]+[ \t]+/, ""); gsub(/^[*]+/, ""); - printf "\t\t%s;\n",$0; + printf " %s;\n",$0; next; } @@ -70,7 +57,7 @@ END { sub(/[(].*$/, ""); gsub(/[^ \t]+[ \t]+/, ""); gsub(/^[*]/, ""); - printf "\t\t%s;\n",$0; + printf " %s;\n",$0; next; } diff --git a/lib/talloc/script/mksyms.sh b/lib/talloc/script/mksyms.sh index 714d55abae..089344f8f0 100755 --- a/lib/talloc/script/mksyms.sh +++ b/lib/talloc/script/mksyms.sh @@ -34,7 +34,24 @@ echo creating $symsfile mkdir -p `dirname $symsfile` -${awk} -f `dirname $0`/mksyms.awk $proto_src > $symsfile_tmp +#Write header +cat > $symsfile_tmp << EOF +# This file is autogenerated, please DO NOT EDIT +{ + global: +EOF + +#loop on each header +for i in $proto_src; do +${awk} -f `dirname $0`/mksyms.awk $i | sort >> $symsfile_tmp +done; + +#Write tail +cat >> $symsfile_tmp << EOF + + local: *; +}; +EOF if cmp -s $symsfile $symsfile_tmp 2>/dev/null then diff --git a/lib/talloc/release-script.sh b/lib/talloc/script/release-script.sh index 6b6c0e7aad..4804f6ff58 100755 --- a/lib/talloc/release-script.sh +++ b/lib/talloc/script/release-script.sh @@ -10,6 +10,16 @@ if [ ! -d "lib/talloc" ]; then exit 1 fi +# Check exports and signatures are up to date +pushd lib/talloc +./script/abi_checks.sh talloc talloc.h +abicheck=$? +popd +if [ ! "$abicheck" = "0" ]; then + echo "ERROR: ABI Checks produced warnings!" + exit 1 +fi + git clean -f -x -d lib/talloc git clean -f -x -d lib/replace diff --git a/lib/talloc/talloc.exports b/lib/talloc/talloc.exports index 75134c0802..1b8062f4a0 100644 --- a/lib/talloc/talloc.exports +++ b/lib/talloc/talloc.exports @@ -1,7 +1,19 @@ +# This file is autogenerated, please DO NOT EDIT { global: _talloc; _talloc_array; + _talloc_free; + _talloc_get_type_abort; + _talloc_memdup; + _talloc_move; + _talloc_realloc; + _talloc_realloc_array; + _talloc_reference_loc; + _talloc_set_destructor; + _talloc_steal_loc; + _talloc_zero; + _talloc_zero_array; talloc_asprintf; talloc_asprintf_append; talloc_asprintf_append_buffer; @@ -11,40 +23,32 @@ talloc_enable_leak_report; talloc_enable_leak_report_full; talloc_enable_null_tracking; + talloc_enable_null_tracking_no_autofree; talloc_find_parent_byname; - _talloc_free; talloc_free_children; talloc_get_name; talloc_get_size; - _talloc_get_type_abort; talloc_increase_ref_count; talloc_init; talloc_is_parent; - _talloc_memdup; - _talloc_move; talloc_named; talloc_named_const; talloc_parent; talloc_parent_name; talloc_pool; - _talloc_realloc; - _talloc_realloc_array; talloc_realloc_fn; talloc_reference_count; - _talloc_reference_loc; talloc_reparent; talloc_report; talloc_report_depth_cb; talloc_report_depth_file; talloc_report_full; talloc_set_abort_fn; - _talloc_set_destructor; talloc_set_log_fn; talloc_set_log_stderr; talloc_set_name; talloc_set_name_const; talloc_show_parents; - _talloc_steal_loc; talloc_strdup; talloc_strdup_append; talloc_strdup_append_buffer; @@ -59,8 +63,6 @@ talloc_vasprintf_append_buffer; talloc_version_major; talloc_version_minor; - _talloc_zero; - _talloc_zero_array; local: *; }; diff --git a/lib/talloc/talloc.signatures b/lib/talloc/talloc.signatures index 00fb4a3296..f2868e8269 100644 --- a/lib/talloc/talloc.signatures +++ b/lib/talloc/talloc.signatures @@ -1,15 +1,15 @@ -char *talloc_asprintf_append_buffer (char *, const char *, ...); -char *talloc_asprintf_append (char *, const char *, ...); char *talloc_asprintf (const void *, const char *, ...); -char *talloc_strdup_append_buffer (char *, const char *); -char *talloc_strdup_append (char *, const char *); +char *talloc_asprintf_append (char *, const char *, ...); +char *talloc_asprintf_append_buffer (char *, const char *, ...); char *talloc_strdup (const void *, const char *); -char *talloc_strndup_append_buffer (char *, const char *, size_t); -char *talloc_strndup_append (char *, const char *, size_t); +char *talloc_strdup_append (char *, const char *); +char *talloc_strdup_append_buffer (char *, const char *); char *talloc_strndup (const void *, const char *, size_t); -char *talloc_vasprintf_append_buffer (char *, const char *, va_list); -char *talloc_vasprintf_append (char *, const char *, va_list); +char *talloc_strndup_append (char *, const char *, size_t); +char *talloc_strndup_append_buffer (char *, const char *, size_t); char *talloc_vasprintf (const void *, const char *, va_list); +char *talloc_vasprintf_append (char *, const char *, va_list); +char *talloc_vasprintf_append_buffer (char *, const char *, va_list); const char *talloc_get_name (const void *); const char *talloc_parent_name (const void *); const char *talloc_set_name (const void *, const char *, ...); @@ -23,39 +23,40 @@ size_t talloc_get_size (const void *); size_t talloc_reference_count (const void *); size_t talloc_total_blocks (const void *); size_t talloc_total_size (const void *); +void *_talloc (const void *, size_t); void *_talloc_array (const void *, size_t, unsigned int, const char *); +void *_talloc_get_type_abort (const void *, const char *, const char *); +void *_talloc_memdup (const void *, const void *, size_t, const char *); +void *_talloc_move (const void *, const void *); +void *_talloc_realloc (const void *, void *, size_t, const char *); +void *_talloc_realloc_array (const void *, void *, size_t, unsigned int, const char *); +void *_talloc_reference_loc (const void *, const void *, const char *); +void *_talloc_steal_loc (const void *, const void *, const char *); +void *_talloc_zero (const void *, size_t, const char *); +void *_talloc_zero_array (const void *, size_t, unsigned int, const char *); void *talloc_autofree_context (void); void *talloc_check_name (const void *, const char *); -void *_talloc (const void *, size_t); -void talloc_disable_null_tracking (void); -void talloc_enable_leak_report_full (void); -void talloc_enable_leak_report (void); -void talloc_enable_null_tracking (void); void *talloc_find_parent_byname (const void *, const char *); -void talloc_free_children (void *); -void *_talloc_get_type_abort (const void *, const char *, const char *); void *talloc_init (const char *, ...); -void *_talloc_memdup (const void *, const void *, size_t, const char *); -void *_talloc_move (const void *, const void *); -void *talloc_named_const (const void *, size_t, const char *); void *talloc_named (const void *, size_t, const char *, ...); +void *talloc_named_const (const void *, size_t, const char *); void *talloc_parent (const void *); void *talloc_pool (const void *, size_t); -void *_talloc_realloc_array (const void *, void *, size_t, unsigned int, const char *); -void *_talloc_realloc (const void *, void *, size_t, const char *); void *talloc_realloc_fn (const void *, void *, size_t); -void *_talloc_reference_loc (const void *, const void *, const char *); void *talloc_reparent (const void *, const void *, const void *); +void _talloc_set_destructor (const void *, int (*) (void *)); +void talloc_disable_null_tracking (void); +void talloc_enable_leak_report (void); +void talloc_enable_leak_report_full (void); +void talloc_enable_null_tracking (void); +void talloc_enable_null_tracking_no_autofree (void); +void talloc_free_children (void *); void talloc_report (const void *, FILE *); void talloc_report_depth_cb (const void *, int, int, void (*) (const void *, int, int, int, void *), void *); void talloc_report_depth_file (const void *, int, int, FILE *); void talloc_report_full (const void *, FILE *); void talloc_set_abort_fn (void (*) (const char *)); -void _talloc_set_destructor (const void *, int (*) (void *)); void talloc_set_log_fn (void (*) (const char *)); void talloc_set_log_stderr (void); void talloc_set_name_const (const void *, const char *); void talloc_show_parents (const void *, FILE *); -void *_talloc_steal_loc (const void *, const void *, const char *); -void *_talloc_zero_array (const void *, size_t, unsigned int, const char *); -void *_talloc_zero (const void *, size_t, const char *); diff --git a/lib/tdr/tdr.c b/lib/tdr/tdr.c index 293436ed5e..ce67003f8b 100644 --- a/lib/tdr/tdr.c +++ b/lib/tdr/tdr.c @@ -92,6 +92,11 @@ NTSTATUS tdr_pull_uint16(struct tdr_pull *tdr, TALLOC_CTX *ctx, uint16_t *v) return NT_STATUS_OK; } +NTSTATUS tdr_pull_uint1632(struct tdr_pull *tdr, TALLOC_CTX *ctx, uint16_t *v) +{ + return tdr_pull_uint16(tdr, ctx, v); +} + NTSTATUS tdr_push_uint16(struct tdr_push *tdr, const uint16_t *v) { TDR_PUSH_NEED_BYTES(tdr, 2); @@ -100,6 +105,11 @@ NTSTATUS tdr_push_uint16(struct tdr_push *tdr, const uint16_t *v) return NT_STATUS_OK; } +NTSTATUS tdr_push_uint1632(struct tdr_push *tdr, const uint16_t *v) +{ + return tdr_push_uint16(tdr, v); +} + NTSTATUS tdr_print_uint16(struct tdr_print *tdr, const char *name, uint16_t *v) { tdr->print(tdr, "%-25s: 0x%02x (%u)", name, *v, *v); diff --git a/lib/tdr/tdr.h b/lib/tdr/tdr.h index 1eedc580d5..84f3e50c2b 100644 --- a/lib/tdr/tdr.h +++ b/lib/tdr/tdr.h @@ -55,7 +55,7 @@ struct tdr_print { } while (0) #define TDR_ALLOC(ctx, s, n) do { \ - (s) = talloc_array_size(ctx, sizeof(*(s)), n); \ + (s) = talloc_array_ptrtype(ctx, (s), n); \ if ((n) && !(s)) return NT_STATUS_NO_MEMORY; \ } while (0) diff --git a/lib/tevent/tevent_signal.c b/lib/tevent/tevent_signal.c index d3325b67ac..ab170a66cf 100644 --- a/lib/tevent/tevent_signal.c +++ b/lib/tevent/tevent_signal.c @@ -92,7 +92,7 @@ static void tevent_common_signal_handler(int signum) /* Write to each unique event context. */ for (sl = sig_state->sig_handlers[signum]; sl; sl = sl->next) { - if (sl->se->event_ctx != ev) { + if (sl->se->event_ctx && sl->se->event_ctx != ev) { ev = sl->se->event_ctx; /* doesn't matter if this pipe overflows */ res = write(ev->pipe_fds[1], &c, 1); diff --git a/lib/util/asn1.c b/lib/util/asn1.c index 70c2c57450..946f71359c 100644 --- a/lib/util/asn1.c +++ b/lib/util/asn1.c @@ -214,7 +214,7 @@ bool asn1_write_BitString(struct asn1_data *data, const void *p, size_t length, return asn1_pop_tag(data); } -bool ber_write_OID_String(DATA_BLOB *blob, const char *OID) +bool ber_write_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *OID) { uint_t v, v2; const char *p = (const char *)OID; @@ -230,7 +230,7 @@ bool ber_write_OID_String(DATA_BLOB *blob, const char *OID) p = newp + 1; /*the ber representation can't use more space then the string one */ - *blob = data_blob(NULL, strlen(OID)); + *blob = data_blob_talloc(mem_ctx, NULL, strlen(OID)); if (!blob->data) return false; blob->data[0] = 40*v + v2; @@ -258,6 +258,41 @@ bool ber_write_OID_String(DATA_BLOB *blob, const char *OID) return true; } +/** + * Serialize partial OID string. + * Partial OIDs are in the form: + * 1:2.5.6:0x81 + * 1:2.5.6:0x8182 + */ +bool ber_write_partial_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *partial_oid) +{ + TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); + char *oid = talloc_strdup(tmp_ctx, partial_oid); + char *p; + + /* truncate partial part so ber_write_OID_String() works */ + p = strchr(oid, ':'); + if (p) { + *p = '\0'; + p++; + } + + if (!ber_write_OID_String(mem_ctx, blob, oid)) { + talloc_free(tmp_ctx); + return false; + } + + /* Add partially endcoded subidentifier */ + if (p) { + DATA_BLOB tmp_blob = strhex_to_data_blob(tmp_ctx, p); + data_blob_append(mem_ctx, blob, tmp_blob.data, tmp_blob.length); + } + + talloc_free(tmp_ctx); + + return true; +} + /* write an object ID to a ASN1 buffer */ bool asn1_write_OID(struct asn1_data *data, const char *OID) { @@ -265,7 +300,7 @@ bool asn1_write_OID(struct asn1_data *data, const char *OID) if (!asn1_push_tag(data, ASN1_OID)) return false; - if (!ber_write_OID_String(&blob, OID)) { + if (!ber_write_OID_String(NULL, &blob, OID)) { data->has_error = true; return false; } @@ -543,8 +578,13 @@ int asn1_tag_remaining(struct asn1_data *data) return remaining; } -/* read an object ID from a data blob */ -bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID) +/** + * Internal implementation for reading binary OIDs + * Reading is done as far in the buffer as valid OID + * till buffer ends or not valid sub-identifier is found. + */ +static bool _ber_read_OID_String_impl(TALLOC_CTX *mem_ctx, DATA_BLOB blob, + const char **OID, size_t *bytes_eaten) { int i; uint8_t *b; @@ -565,19 +605,63 @@ bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID) if ( ! (b[i] & 0x80)) { tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u", v); v = 0; + if (bytes_eaten) + *bytes_eaten = i+1; } if (!tmp_oid) goto nomem; } - if (v != 0) { - talloc_free(tmp_oid); + *OID = tmp_oid; + return true; + +nomem: + return false; +} + +/* read an object ID from a data blob */ +bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID) +{ + size_t bytes_eaten; + + if (!_ber_read_OID_String_impl(mem_ctx, blob, OID, &bytes_eaten)) + return false; + + return (bytes_eaten == blob.length); +} + +/** + * Deserialize partial OID string. + * Partial OIDs are in the form: + * 1:2.5.6:0x81 + * 1:2.5.6:0x8182 + */ +bool ber_read_partial_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **partial_oid) +{ + size_t bytes_left; + size_t bytes_eaten; + char *identifier = NULL; + char *tmp_oid = NULL; + + if (!_ber_read_OID_String_impl(mem_ctx, blob, (const char **)&tmp_oid, &bytes_eaten)) return false; + + if (bytes_eaten < blob.length) { + bytes_left = blob.length - bytes_eaten; + identifier = hex_encode_talloc(mem_ctx, &blob.data[bytes_eaten], bytes_left); + if (!identifier) goto nomem; + + *partial_oid = talloc_asprintf_append_buffer(tmp_oid, ":0x%s", identifier); + if (!*partial_oid) goto nomem; + TALLOC_FREE(identifier); + } else { + *partial_oid = tmp_oid; } - *OID = tmp_oid; return true; -nomem: +nomem: + TALLOC_FREE(identifier); + TALLOC_FREE(tmp_oid); return false; } diff --git a/lib/util/asn1.h b/lib/util/asn1.h index 9abae50d64..ded3244bed 100644 --- a/lib/util/asn1.h +++ b/lib/util/asn1.h @@ -61,7 +61,8 @@ bool asn1_pop_tag(struct asn1_data *data); bool asn1_write_implicit_Integer(struct asn1_data *data, int i); bool asn1_write_Integer(struct asn1_data *data, int i); bool asn1_write_BitString(struct asn1_data *data, const void *p, size_t length, uint8_t padding); -bool ber_write_OID_String(DATA_BLOB *blob, const char *OID); +bool ber_write_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *OID); +bool ber_write_partial_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *partial_oid); bool asn1_write_OID(struct asn1_data *data, const char *OID); bool asn1_write_OctetString(struct asn1_data *data, const void *p, size_t length); bool asn1_write_LDAPString(struct asn1_data *data, const char *s); @@ -83,6 +84,7 @@ bool asn1_start_tag(struct asn1_data *data, uint8_t tag); bool asn1_end_tag(struct asn1_data *data); int asn1_tag_remaining(struct asn1_data *data); bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID); +bool ber_read_partial_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **partial_oid); bool asn1_read_OID(struct asn1_data *data, TALLOC_CTX *mem_ctx, const char **OID); bool asn1_check_OID(struct asn1_data *data, const char *OID); bool asn1_read_LDAPString(struct asn1_data *data, TALLOC_CTX *mem_ctx, char **s); diff --git a/lib/util/talloc_stack.h b/lib/util/talloc_stack.h index bb22b8a029..777671164d 100644 --- a/lib/util/talloc_stack.h +++ b/lib/util/talloc_stack.h @@ -35,7 +35,7 @@ #ifndef _TALLOC_STACK_H #define _TALLOC_STACK_H -#include "../talloc/talloc.h" +#include "talloc.h" /* * Create a new talloc stack frame. diff --git a/lib/util/tests/asn1_tests.c b/lib/util/tests/asn1_tests.c new file mode 100644 index 0000000000..25c82227ae --- /dev/null +++ b/lib/util/tests/asn1_tests.c @@ -0,0 +1,260 @@ +/* + Unix SMB/CIFS implementation. + + util_asn1 testing + + Copyright (C) Kamen Mazdrashki <kamen.mazdrashki@postpath.com> 2009 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "torture/torture.h" +#include "../asn1.h" + +struct oid_data { + const char *oid; /* String OID */ + const char *bin_oid; /* Binary OID represented as string */ +}; + +/* Data for successful OIDs conversions */ +struct oid_data oid_data_ok[] = { + { + .oid = "2.5.4.0", + .bin_oid = "550400" + }, + { + .oid = "2.5.4.1", + .bin_oid = "550401" + }, + { + .oid = "2.5.4.130", + .bin_oid = "55048102" + }, + { + .oid = "2.5.130.4", + .bin_oid = "55810204" + }, + { + .oid = "2.5.4.16387", + .bin_oid = "5504818003" + }, + { + .oid = "2.5.16387.4", + .bin_oid = "5581800304" + }, + { + .oid = "2.5.2097155.4", + .bin_oid = "558180800304" + }, + { + .oid = "2.5.4.130.16387.2097155.268435459", + .bin_oid = "55048102818003818080038180808003" + }, +}; + +/* Data for successful Partial OIDs conversions */ +struct oid_data partial_oid_data_ok[] = { + { + .oid = "2.5.4.130:0x81", + .bin_oid = "5504810281" + }, + { + .oid = "2.5.4.16387:0x8180", + .bin_oid = "55048180038180" + }, + { + .oid = "2.5.4.16387:0x81", + .bin_oid = "550481800381" + }, + { + .oid = "2.5.2097155.4:0x818080", + .bin_oid = "558180800304818080" + }, + { + .oid = "2.5.2097155.4:0x8180", + .bin_oid = "5581808003048180" + }, + { + .oid = "2.5.2097155.4:0x81", + .bin_oid = "55818080030481" + }, +}; + + +/* Testing ber_write_OID_String() function */ +static bool test_ber_write_OID_String(struct torture_context *tctx) +{ + int i; + char *hex_str; + DATA_BLOB blob; + TALLOC_CTX *mem_ctx; + struct oid_data *data = oid_data_ok; + + mem_ctx = talloc_new(tctx); + + for (i = 0; i < ARRAY_SIZE(oid_data_ok); i++) { + torture_assert(tctx, ber_write_OID_String(mem_ctx, &blob, data[i].oid), + "ber_write_OID_String failed"); + + hex_str = hex_encode_talloc(mem_ctx, blob.data, blob.length); + torture_assert(tctx, hex_str, "No memory!"); + + torture_assert(tctx, strequal(data[i].bin_oid, hex_str), + talloc_asprintf(mem_ctx, + "Failed: oid=%s, bin_oid:%s", + data[i].oid, data[i].bin_oid)); + } + + talloc_free(mem_ctx); + + return true; +} + +/* Testing ber_read_OID_String() function */ +static bool test_ber_read_OID_String(struct torture_context *tctx) +{ + int i; + const char *oid; + DATA_BLOB oid_blob; + TALLOC_CTX *mem_ctx; + struct oid_data *data = oid_data_ok; + + mem_ctx = talloc_new(tctx); + + for (i = 0; i < ARRAY_SIZE(oid_data_ok); i++) { + oid_blob = strhex_to_data_blob(mem_ctx, data[i].bin_oid); + + torture_assert(tctx, ber_read_OID_String(mem_ctx, oid_blob, &oid), + "ber_read_OID_String failed"); + + torture_assert(tctx, strequal(data[i].oid, oid), + talloc_asprintf(mem_ctx, + "Failed: oid=%s, bin_oid:%s", + data[i].oid, data[i].bin_oid)); + } + + talloc_free(mem_ctx); + + return true; +} + +/* Testing ber_write_partial_OID_String() function */ +static bool test_ber_write_partial_OID_String(struct torture_context *tctx) +{ + int i; + char *hex_str; + DATA_BLOB blob; + TALLOC_CTX *mem_ctx; + struct oid_data *data = oid_data_ok; + + mem_ctx = talloc_new(tctx); + + /* ber_write_partial_OID_String() should work with not partial OIDs also */ + for (i = 0; i < ARRAY_SIZE(oid_data_ok); i++) { + torture_assert(tctx, ber_write_partial_OID_String(mem_ctx, &blob, data[i].oid), + "ber_write_partial_OID_String failed"); + + hex_str = hex_encode_talloc(mem_ctx, blob.data, blob.length); + torture_assert(tctx, hex_str, "No memory!"); + + torture_assert(tctx, strequal(data[i].bin_oid, hex_str), + talloc_asprintf(mem_ctx, + "Failed: oid=%s, bin_oid:%s", + data[i].oid, data[i].bin_oid)); + } + + /* ber_write_partial_OID_String() test with partial OIDs */ + data = partial_oid_data_ok; + for (i = 0; i < ARRAY_SIZE(partial_oid_data_ok); i++) { + torture_assert(tctx, ber_write_partial_OID_String(mem_ctx, &blob, data[i].oid), + "ber_write_partial_OID_String failed"); + + hex_str = hex_encode_talloc(mem_ctx, blob.data, blob.length); + torture_assert(tctx, hex_str, "No memory!"); + + torture_assert(tctx, strequal(data[i].bin_oid, hex_str), + talloc_asprintf(mem_ctx, + "Failed: oid=%s, bin_oid:%s", + data[i].oid, data[i].bin_oid)); + } + + talloc_free(mem_ctx); + + return true; +} + +/* Testing ber_read_partial_OID_String() function */ +static bool test_ber_read_partial_OID_String(struct torture_context *tctx) +{ + int i; + const char *oid; + DATA_BLOB oid_blob; + TALLOC_CTX *mem_ctx; + struct oid_data *data = oid_data_ok; + + mem_ctx = talloc_new(tctx); + + /* ber_read_partial_OID_String() should work with not partial OIDs also */ + for (i = 0; i < ARRAY_SIZE(oid_data_ok); i++) { + oid_blob = strhex_to_data_blob(mem_ctx, data[i].bin_oid); + + torture_assert(tctx, ber_read_partial_OID_String(mem_ctx, oid_blob, &oid), + "ber_read_partial_OID_String failed"); + + torture_assert(tctx, strequal(data[i].oid, oid), + talloc_asprintf(mem_ctx, + "Failed: oid=%s, bin_oid:%s", + data[i].oid, data[i].bin_oid)); + } + + /* ber_read_partial_OID_String() test with partial OIDs */ + data = partial_oid_data_ok; + for (i = 0; i < ARRAY_SIZE(partial_oid_data_ok); i++) { + oid_blob = strhex_to_data_blob(mem_ctx, data[i].bin_oid); + + torture_assert(tctx, ber_read_partial_OID_String(mem_ctx, oid_blob, &oid), + "ber_read_partial_OID_String failed"); + + torture_assert(tctx, strequal(data[i].oid, oid), + talloc_asprintf(mem_ctx, + "Failed: oid=%s, bin_oid:%s", + data[i].oid, data[i].bin_oid)); + } + + talloc_free(mem_ctx); + + return true; +} + + +/* LOCAL-ASN1 test suite creation */ +struct torture_suite *torture_local_util_asn1(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, "ASN1"); + + torture_suite_add_simple_test(suite, "ber_write_OID_String", + test_ber_write_OID_String); + + torture_suite_add_simple_test(suite, "ber_read_OID_String", + test_ber_read_OID_String); + + torture_suite_add_simple_test(suite, "ber_write_partial_OID_String", + test_ber_write_partial_OID_String); + + torture_suite_add_simple_test(suite, "ber_read_partial_OID_String", + test_ber_read_partial_OID_String); + + return suite; +} diff --git a/lib/util/tests/data_blob.c b/lib/util/tests/data_blob.c index 875e5fdef8..f0b02b8d17 100644 --- a/lib/util/tests/data_blob.c +++ b/lib/util/tests/data_blob.c @@ -78,7 +78,7 @@ static bool test_cmp(struct torture_context *tctx) static bool test_hex_string(struct torture_context *tctx) { DATA_BLOB a = data_blob_string_const("\xC\xA\xF\xE"); - torture_assert_str_equal(tctx, data_blob_hex_string(tctx, &a), "0C0A0F0E", "hex string"); + torture_assert_str_equal(tctx, data_blob_hex_string(tctx, &a), "0c0a0f0e", "hex string"); return true; } diff --git a/lib/util/util.c b/lib/util/util.c index 2a809d3ccb..fd0e6b8d79 100644 --- a/lib/util/util.c +++ b/lib/util/util.c @@ -579,18 +579,18 @@ _PUBLIC_ _PURE_ size_t count_chars(const char *s, char c) **/ _PUBLIC_ size_t strhex_to_str(char *p, size_t p_len, const char *strhex, size_t strhex_len) { - size_t i; + size_t i = 0; size_t num_chars = 0; uint8_t lonybble, hinybble; const char *hexchars = "0123456789ABCDEF"; char *p1 = NULL, *p2 = NULL; - for (i = 0; i < strhex_len && strhex[i] != 0; i++) { - if (strncasecmp(hexchars, "0x", 2) == 0) { - i++; /* skip two chars */ - continue; - } + /* skip leading 0x prefix */ + if (strncasecmp(strhex, "0x", 2) == 0) { + i += 2; /* skip two chars */ + } + for (; i < strhex_len && strhex[i] != 0; i++) { if (!(p1 = strchr(hexchars, toupper((unsigned char)strhex[i])))) break; @@ -804,8 +804,8 @@ static bool next_token_internal_talloc(TALLOC_CTX *ctx, const char *sep, bool ltrim) { - char *s; - char *saved_s; + const char *s; + const char *saved_s; char *pbuf; bool quoted; size_t len=1; @@ -815,7 +815,7 @@ static bool next_token_internal_talloc(TALLOC_CTX *ctx, return(false); } - s = (char *)*ptr; + s = *ptr; /* default to simple separators */ if (!sep) { diff --git a/lib/util/util_tdb.c b/lib/util/util_tdb.c index e107cbdc4a..cda8dc75b2 100644 --- a/lib/util/util_tdb.c +++ b/lib/util/util_tdb.c @@ -20,7 +20,7 @@ */ #include "includes.h" -#include "../tdb/include/tdb.h" +#include "tdb.h" #include "../lib/util/util_tdb.h" /* these are little tdb utility functions that are meant to make |