s4/drsuapi: ber_write_partial_OID_String() implementation
authorKamen Mazdrashki <kamen.mazdrashki@postpath.com>
Fri, 25 Sep 2009 13:38:54 +0000 (16:38 +0300)
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Thu, 1 Oct 2009 21:12:57 +0000 (23:12 +0200)
lib/util/asn1.c
lib/util/asn1.h

index 70c2c57450cc1de869fab961de8ea55911e8c9e4..61fb9555a77624f1a54aac275c9f21c8d0e62c8b 100644 (file)
@@ -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(DATA_BLOB *blob, const char *partial_oid)
+{
+       TALLOC_CTX *mem_ctx = talloc_new(NULL);
+       char *oid = talloc_strdup(mem_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(blob, oid)) {
+               talloc_free(mem_ctx);
+               return false;
+       }
+
+       /* Add partially endcoded subidentifier */
+       if (p) {
+               DATA_BLOB tmp_blob = strhex_to_data_blob(mem_ctx, p);
+               data_blob_append(NULL, blob, tmp_blob.data, tmp_blob.length);
+       }
+
+       talloc_free(mem_ctx);
+
+       return true;
+}
+
 /* write an object ID to a ASN1 buffer */
 bool asn1_write_OID(struct asn1_data *data, const char *OID)
 {
index 9abae50d64ef6c1e1c905076d647eaccaa4287b7..cd93195870f3444903de2bce052521382a04a62f 100644 (file)
@@ -62,6 +62,7 @@ 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_partial_OID_String(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);