summaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
authorKamen Mazdrashki <kamen.mazdrashki@postpath.com>2009-09-25 17:28:33 +0300
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>2009-10-01 23:12:58 +0200
commit55dfc116f47b7c7242567f596c82bfd8f81d7b98 (patch)
tree759aea711cc89cc3bdf193a0f8cd53749565e6e9 /lib/util
parent715c790600477b9b1ebdae7aa98779fc06be3bd1 (diff)
downloadsamba-55dfc116f47b7c7242567f596c82bfd8f81d7b98.tar.gz
samba-55dfc116f47b7c7242567f596c82bfd8f81d7b98.tar.bz2
samba-55dfc116f47b7c7242567f596c82bfd8f81d7b98.zip
s4/drsuapi: Internal implementation for ber_read_OID_String
Modified implementation _ber_read_OID_String_impl() returns how much bytes are converted. The intentation is to use this implementation both for reading OIDs and partial-OIDs in the future
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/asn1.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/util/asn1.c b/lib/util/asn1.c
index 61fb9555a7..0d08027a07 100644
--- a/lib/util/asn1.c
+++ b/lib/util/asn1.c
@@ -578,6 +578,46 @@ int asn1_tag_remaining(struct asn1_data *data)
return remaining;
}
+/**
+ * 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;
+ uint_t v;
+ char *tmp_oid = NULL;
+
+ if (blob.length < 2) return false;
+
+ b = blob.data;
+
+ tmp_oid = talloc_asprintf(mem_ctx, "%u", b[0]/40);
+ if (!tmp_oid) goto nomem;
+ tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u", b[0]%40);
+ if (!tmp_oid) goto nomem;
+
+ for(i = 1, v = 0; i < blob.length; i++) {
+ v = (v<<7) | (b[i]&0x7f);
+ 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;
+ }
+
+ *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)
{