lib/util Split data_blob_hex_string() into upper and lower
authorAndrew Bartlett <abartlet@samba.org>
Wed, 4 Nov 2009 06:42:53 +0000 (17:42 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 12 Nov 2009 05:34:01 +0000 (16:34 +1100)
Rather than have a repeat of the bugs we found at the plugfest where
hexidecimal strings must be in upper or lower case in particular
places, ensure that each caller chooses which case they want.

This reverts most of the callers back to upper case, as things were
before tridge's patch.  The critical call in the extended DN code is
of course handled in lower case.

Andrew Bartlett

lib/util/data_blob.c
lib/util/data_blob.h
lib/util/tests/data_blob.c
librpc/ndr/ndr_drsuapi.c
librpc/ndr/uuid.c
librpc/rpc/binding.c
source4/dsdb/samdb/ldb_modules/password_hash.c
source4/lib/ldb-samba/ldif_handlers.c
source4/lib/registry/util.c
source4/torture/ldap/schema.c
source4/torture/rpc/samsync.c

index 825d8cf88ca11c1c2a10a17b89d7184fd4bdaf1a..6e7557f8ef64372c531628fe9fbbbfbb3725245e 100644 (file)
@@ -153,7 +153,7 @@ _PUBLIC_ int data_blob_cmp(const DATA_BLOB *d1, const DATA_BLOB *d2)
 /**
 print the data_blob as hex string
 **/
-_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
+_PUBLIC_ char *data_blob_hex_string_lower(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
 {
        int i;
        char *hex_string;
@@ -173,6 +173,23 @@ _PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
        return hex_string;
 }
 
+_PUBLIC_ char *data_blob_hex_string_upper(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
+{
+       int i;
+       char *hex_string;
+
+       hex_string = talloc_array(mem_ctx, char, (blob->length*2)+1);
+       if (!hex_string) {
+               return NULL;
+       }
+
+       for (i = 0; i < blob->length; i++)
+               slprintf(&hex_string[i*2], 3, "%02X", blob->data[i]);
+
+       hex_string[(blob->length*2)] = '\0';
+       return hex_string;
+}
+
 /**
   useful for constructing data blobs in test suites, while
   avoiding const warnings
index ffde51cf33600abfb9461b3ceb3cfd79752ed48d..c294533960c8ec14c20553d4836b43d481b8cb8f 100644 (file)
@@ -96,7 +96,12 @@ _PUBLIC_ int data_blob_cmp(const DATA_BLOB *d1, const DATA_BLOB *d2);
 /**
 print the data_blob as hex string
 **/
-_PUBLIC_ char *data_blob_hex_string(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob);
+_PUBLIC_ char *data_blob_hex_string_upper(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob);
+
+/**
+print the data_blob as hex string
+**/
+_PUBLIC_ char *data_blob_hex_string_lower(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob);
 
 /**
   useful for constructing data blobs in test suites, while
index f0b02b8d171969437a90c19b85da148ce0be66f0..53330a4afd5c2b3ab3b68830b355e02bdb0ba8f3 100644 (file)
@@ -78,7 +78,8 @@ 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_lower(tctx, &a), "0c0a0f0e", "hex string");
+       torture_assert_str_equal(tctx, data_blob_hex_string_upper(tctx, &a), "0C0A0F0E", "hex string");
        return true;
 }
 
index bfc3c75b4e704eec2b46b031a381f11c38ced306..15f2f842bdc1a508418cba57402c200e0ce285b6 100644 (file)
@@ -91,7 +91,7 @@ _PUBLIC_ void ndr_print_drsuapi_DsReplicaOID(struct ndr_print *ndr, const char *
        if (r->binary_oid) {
                char *partial_oid = NULL;
                DATA_BLOB oid_blob = data_blob_const(r->binary_oid, r->length);
-               char *hex_str = data_blob_hex_string(ndr, &oid_blob);
+               char *hex_str = data_blob_hex_string_upper(ndr, &oid_blob);
                ber_read_partial_OID_String(ndr, oid_blob, (const char **)&partial_oid);
                ndr->depth++;
                ndr->print(ndr, "%-25s: 0x%s (%s)", "binary_oid", hex_str, partial_oid);
index 004a8d35ccf1059d9cee53c8a717f7c60979c20a..df17d7824e96864d0cb6d96bd3902008c941007d 100644 (file)
@@ -291,7 +291,7 @@ _PUBLIC_ char *GUID_hexstring(TALLOC_CTX *mem_ctx, const struct GUID *guid)
                return NULL;
        }
 
-       ret = data_blob_hex_string(mem_ctx, &guid_blob);
+       ret = data_blob_hex_string_upper(mem_ctx, &guid_blob);
        talloc_free(tmp_mem);
        return ret;
 }
index 734471451b7adbbb952e3064f2ae3a24cfc49300..20c3a389f16fcc838c1240c8faeeacc2da0ed5ae 100644 (file)
@@ -113,7 +113,7 @@ const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor)
                                return talloc_asprintf(mem_ctx, " uuid %s/0x%02x", uuidstr, syntax.if_version);
                        } else { /* IPX */
                                return talloc_asprintf(mem_ctx, "IPX:%s", 
-                                               data_blob_hex_string(mem_ctx, &epm_floor->rhs.uuid.unknown));
+                                               data_blob_hex_string_upper(mem_ctx, &epm_floor->rhs.uuid.unknown));
                        }
 
                case EPM_PROTOCOL_NCACN:
index 7779a1752be8e093c06240c4e3835301cccb5e0f..8791db2bc4fcd4d31cf223e25f2ae5af0b9fc1c9 100644 (file)
@@ -1137,7 +1137,7 @@ static int setup_supplemental_field(struct setup_password_fields_io *io)
                                               nt_errstr(status));
                        return LDB_ERR_OPERATIONS_ERROR;
                }
-               pknb_hexstr = data_blob_hex_string(io->ac, &pknb_blob);
+               pknb_hexstr = data_blob_hex_string_upper(io->ac, &pknb_blob);
                if (!pknb_hexstr) {
                        ldb_oom(ldb);
                        return LDB_ERR_OPERATIONS_ERROR;
@@ -1169,7 +1169,7 @@ static int setup_supplemental_field(struct setup_password_fields_io *io)
                                       nt_errstr(status));
                return LDB_ERR_OPERATIONS_ERROR;
        }
-       pkb_hexstr = data_blob_hex_string(io->ac, &pkb_blob);
+       pkb_hexstr = data_blob_hex_string_upper(io->ac, &pkb_blob);
        if (!pkb_hexstr) {
                ldb_oom(ldb);
                return LDB_ERR_OPERATIONS_ERROR;
@@ -1200,7 +1200,7 @@ static int setup_supplemental_field(struct setup_password_fields_io *io)
                                       nt_errstr(status));
                return LDB_ERR_OPERATIONS_ERROR;
        }
-       pdb_hexstr = data_blob_hex_string(io->ac, &pdb_blob);
+       pdb_hexstr = data_blob_hex_string_upper(io->ac, &pdb_blob);
        if (!pdb_hexstr) {
                ldb_oom(ldb);
                return LDB_ERR_OPERATIONS_ERROR;
@@ -1229,7 +1229,7 @@ static int setup_supplemental_field(struct setup_password_fields_io *io)
                                               nt_errstr(status));
                        return LDB_ERR_OPERATIONS_ERROR;
                }
-               pcb_hexstr = data_blob_hex_string(io->ac, &pcb_blob);
+               pcb_hexstr = data_blob_hex_string_upper(io->ac, &pcb_blob);
                if (!pcb_hexstr) {
                        ldb_oom(ldb);
                        return LDB_ERR_OPERATIONS_ERROR;
@@ -1255,7 +1255,7 @@ static int setup_supplemental_field(struct setup_password_fields_io *io)
                                       nt_errstr(status));
                return LDB_ERR_OPERATIONS_ERROR;
        }
-       pb_hexstr = data_blob_hex_string(io->ac, &pb_blob);
+       pb_hexstr = data_blob_hex_string_upper(io->ac, &pb_blob);
        if (!pb_hexstr) {
                ldb_oom(ldb);
                return LDB_ERR_OPERATIONS_ERROR;
index 9467bef87351217ab97d6f41d7551efd17c6c34f..d8edeb0beb255d1d5f99a22d72938e840239aaa5 100644 (file)
@@ -784,7 +784,7 @@ static int ldif_write_replUpToDateVector(struct ldb_context *ldb, void *mem_ctx,
 static int extended_dn_write_hex(struct ldb_context *ldb, void *mem_ctx,
                                 const struct ldb_val *in, struct ldb_val *out)
 {
-       *out = data_blob_string_const(data_blob_hex_string(mem_ctx, in));
+       *out = data_blob_string_const(data_blob_hex_string_lower(mem_ctx, in));
        if (!out->data) {
                return -1;
        }
index a1897eff2e78e12f4d7ae6d0ada148293d860dfb..038b23fc8743b92e1cb300c4e93a9a669c28ac8d 100644 (file)
@@ -68,7 +68,7 @@ _PUBLIC_ char *reg_val_data_string(TALLOC_CTX *mem_ctx,
                                              (void **)&ret, NULL, false);
                        return ret;
                case REG_BINARY:
-                       ret = data_blob_hex_string(mem_ctx, &data);
+                       ret = data_blob_hex_string_upper(mem_ctx, &data);
                        return ret;
                case REG_DWORD:
                        if (*(int *)data.data == 0)
index 7fe171691a656d63e4d96d09077417c6fc71c6ad..b0a4892d7a54650e841ea25ba3d603abe1436cf0 100644 (file)
@@ -356,7 +356,7 @@ static bool test_dump_sorted_syntax(struct ldb_context *ldb, struct test_rootDSE
 
                        if (strcmp(syntaxes[i], a->attributeSyntax_oid) != 0) continue;
 
-                       om_hex = data_blob_hex_string(ldb, &a->oMObjectClass);
+                       om_hex = data_blob_hex_string_upper(ldb, &a->oMObjectClass);
                        if (!om_hex) {
                                return false;
                        }
index 52df4eb6b976cb1d6db4cebe37d2a78232003af7..19060c69a944626deaf084d91445b613f7d46875 100644 (file)
@@ -593,11 +593,11 @@ static bool samsync_handle_user(struct torture_context *tctx, TALLOC_CTX *mem_ct
 
        if (nt_hash_p) {
                DATA_BLOB nt_hash_blob = data_blob_const(nt_hash_p, 16);
-               DEBUG(100,("ACCOUNT [%s\\%-25s] NTHASH %s\n", samsync_state->domain_name[0], username, data_blob_hex_string(mem_ctx, &nt_hash_blob)));
+               DEBUG(100,("ACCOUNT [%s\\%-25s] NTHASH %s\n", samsync_state->domain_name[0], username, data_blob_hex_string_upper(mem_ctx, &nt_hash_blob)));
        }
        if (lm_hash_p) {
                DATA_BLOB lm_hash_blob = data_blob_const(lm_hash_p, 16);
-               DEBUG(100,("ACCOUNT [%s\\%-25s] LMHASH %s\n", samsync_state->domain_name[0], username, data_blob_hex_string(mem_ctx, &lm_hash_blob)));
+               DEBUG(100,("ACCOUNT [%s\\%-25s] LMHASH %s\n", samsync_state->domain_name[0], username, data_blob_hex_string_upper(mem_ctx, &lm_hash_blob)));
        }
 
        nt_status = test_SamLogon(samsync_state->p_netlogon_wksta, mem_ctx, samsync_state->creds_netlogon_wksta,