s4/drsuapi: ber_read_partial_OID_String() implementation
authorKamen Mazdrashki <kamen.mazdrashki@postpath.com>
Fri, 25 Sep 2009 14:29:05 +0000 (17:29 +0300)
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Thu, 1 Oct 2009 21:12:58 +0000 (23:12 +0200)
lib/util/asn1.c
lib/util/asn1.h

index 0d08027a070c914126c1bdb83aa5e67cd6533ccc..93d96c2bdfe89dd0b649284d0ba023c98a19bf3c 100644 (file)
@@ -656,6 +656,42 @@ nomem:
        return false;
 }
 
+/**
+ * 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;
+       }
+
+       return true;
+
+nomem:
+       TALLOC_FREE(identifier);
+       TALLOC_FREE(tmp_oid);
+       return false;
+}
+
 /* read an object ID from a ASN1 buffer */
 bool asn1_read_OID(struct asn1_data *data, TALLOC_CTX *mem_ctx, const char **OID)
 {
index cd93195870f3444903de2bce052521382a04a62f..3d8e37b8ab879722d02c94b83fa6bbcccb8a0252 100644 (file)
@@ -84,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);