static bool torture_test_syntax(struct torture_context *torture, struct torture_dsdb_syntax *priv, const char *oid, const char *attr_string, const char *ldb_str, const char *drs_str) { TALLOC_CTX *tmp_ctx = talloc_new(torture); DATA_BLOB drs_binary = hexstr_to_data_blob(tmp_ctx, drs_str); DATA_BLOB ldb_blob = data_blob_string_const(ldb_str); struct drsuapi_DsReplicaAttribute drs, drs2; struct drsuapi_DsAttributeValue val; const struct dsdb_syntax *syntax; const struct dsdb_attribute *attr; struct ldb_message_element el; struct ldb_context *ldb = priv->ldb; struct dsdb_schema *schema = priv->schema; struct dsdb_syntax_ctx syntax_ctx; /* use default syntax conversion context */ dsdb_syntax_ctx_init(&syntax_ctx, ldb, schema); drs.value_ctr.num_values = 1; drs.value_ctr.values = &val; val.blob = &drs_binary; torture_assert(torture, syntax = find_syntax_map_by_standard_oid(oid), "Failed to find syntax handler"); torture_assert(torture, attr = dsdb_attribute_by_lDAPDisplayName(schema, attr_string), "Failed to find attribute handler"); torture_assert_str_equal(torture, attr->syntax->name, syntax->name, "Syntax from schema not as expected"); torture_assert_werr_ok(torture, syntax->drsuapi_to_ldb(&syntax_ctx, attr, &drs, tmp_ctx, &el), "Failed to convert from DRS to ldb format"); torture_assert_data_blob_equal(torture, el.values[0], ldb_blob, "Incorrect conversion from DRS to ldb format"); torture_assert_werr_ok(torture, syntax->ldb_to_drsuapi(&syntax_ctx, attr, &el, tmp_ctx, &drs2), "Failed to convert from ldb to DRS format"); torture_assert(torture, drs2.value_ctr.values[0].blob, "No blob returned from conversion"); torture_assert_data_blob_equal(torture, *drs2.value_ctr.values[0].blob, drs_binary, "Incorrect conversion from ldb to DRS format"); return true; }
static bool wrap_ndr_pullpush_test(struct torture_context *tctx, struct torture_tcase *tcase, struct torture_test *test) { bool (*check_fn) (struct torture_context *ctx, void *data) = test->fn; const struct ndr_pull_test_data *data = (const struct ndr_pull_test_data *)test->data; struct ndr_pull *ndr = ndr_pull_init_blob(&(data->data), tctx); void *ds = talloc_zero_size(ndr, data->struct_size); bool ret; uint32_t highest_ofs; ndr->flags |= data->flags; ndr->flags |= LIBNDR_FLAG_REF_ALLOC; torture_assert_ndr_success(tctx, data->pull_fn(ndr, data->ndr_flags, ds), "pulling"); if (ndr->offset > ndr->relative_highest_offset) { highest_ofs = ndr->offset; } else { highest_ofs = ndr->relative_highest_offset; } torture_assert(tctx, highest_ofs == ndr->data_size, talloc_asprintf(tctx, "%d unread bytes", ndr->data_size - highest_ofs)); if (check_fn != NULL) { ret = check_fn(tctx, ds); } else { ret = true; } if (data->push_fn != NULL) { DATA_BLOB outblob; torture_assert_ndr_success(tctx, ndr_push_struct_blob(&outblob, ndr, ds, data->push_fn), "pushing"); torture_assert_data_blob_equal(tctx, outblob, data->data, "ndr push compare"); } talloc_free(ndr); return ret; }
static bool torture_ldb_attrs(struct torture_context *torture) { TALLOC_CTX *mem_ctx = talloc_new(torture); struct ldb_context *ldb; const struct ldb_schema_attribute *attr; struct ldb_val string_sid_blob, binary_sid_blob; struct ldb_val string_guid_blob, string_guid_blob2, binary_guid_blob; DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid); DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid); torture_assert(torture, ldb = ldb_init(mem_ctx, torture->ev), "Failed to init ldb"); torture_assert_int_equal(torture, ldb_register_samba_handlers(ldb), 0, "Failed to register Samba handlers"); ldb_set_utf8_fns(ldb, NULL, wrap_casefold); /* Test SID behaviour */ torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "objectSid"), "Failed to get objectSid schema attribute"); string_sid_blob = data_blob_string_const(sid); torture_assert_int_equal(torture, attr->syntax->ldif_read_fn(ldb, mem_ctx, &string_sid_blob, &binary_sid_blob), 0, "Failed to parse string SID"); torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob, "Read SID into blob form failed"); torture_assert_int_equal(torture, attr->syntax->ldif_read_fn(ldb, mem_ctx, &sid_blob, &binary_sid_blob), -1, "Should have failed to parse binary SID"); torture_assert_int_equal(torture, attr->syntax->ldif_write_fn(ldb, mem_ctx, &binary_sid_blob, &string_sid_blob), 0, "Failed to parse binary SID"); torture_assert_data_blob_equal(torture, string_sid_blob, data_blob_string_const(sid), "Write SID into string form failed"); torture_assert_int_equal(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &binary_sid_blob, &string_sid_blob), 0, "Failed to compare binary and string SID"); torture_assert_int_equal(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &string_sid_blob, &binary_sid_blob), 0, "Failed to compare string and binary binary SID"); torture_assert_int_equal(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &string_sid_blob, &string_sid_blob), 0, "Failed to compare string and string SID"); torture_assert_int_equal(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &binary_sid_blob, &binary_sid_blob), 0, "Failed to compare binary and binary SID"); torture_assert(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &guid_blob, &binary_sid_blob) != 0, "Failed to distinguish binary GUID and binary SID"); /* Test GUID behaviour */ torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "objectGUID"), "Failed to get objectGUID schema attribute"); string_guid_blob = data_blob_string_const(guid); torture_assert_int_equal(torture, attr->syntax->ldif_read_fn(ldb, mem_ctx, &string_guid_blob, &binary_guid_blob), 0, "Failed to parse string GUID"); torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob, "Read GUID into blob form failed"); string_guid_blob2 = data_blob_string_const(guid2); torture_assert_int_equal(torture, attr->syntax->ldif_read_fn(ldb, mem_ctx, &string_guid_blob2, &binary_guid_blob), 0, "Failed to parse string GUID"); torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob, "Read GUID into blob form failed"); torture_assert_int_equal(torture, attr->syntax->ldif_read_fn(ldb, mem_ctx, &guid_blob, &binary_guid_blob), 0, "Failed to parse binary GUID"); torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob, "Read GUID into blob form failed"); torture_assert_int_equal(torture, attr->syntax->ldif_write_fn(ldb, mem_ctx, &binary_guid_blob, &string_guid_blob), 0, "Failed to print binary GUID as string"); torture_assert_data_blob_equal(torture, string_sid_blob, data_blob_string_const(sid), "Write SID into string form failed"); torture_assert_int_equal(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &binary_guid_blob, &string_guid_blob), 0, "Failed to compare binary and string GUID"); torture_assert_int_equal(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &string_guid_blob, &binary_guid_blob), 0, "Failed to compare string and binary binary GUID"); torture_assert_int_equal(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &string_guid_blob, &string_guid_blob), 0, "Failed to compare string and string GUID"); torture_assert_int_equal(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &binary_guid_blob, &binary_guid_blob), 0, "Failed to compare binary and binary GUID"); talloc_free(mem_ctx); return true; }
static bool torture_ldb_dn_extended(struct torture_context *torture) { TALLOC_CTX *mem_ctx = talloc_new(torture); struct ldb_context *ldb; struct ldb_dn *dn, *dn2; DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid); DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid); const char *dn_str = "cn=admin,cn=users,dc=samba,dc=org"; torture_assert(torture, ldb = ldb_init(mem_ctx, torture->ev), "Failed to init ldb"); torture_assert_int_equal(torture, ldb_register_samba_handlers(ldb), 0, "Failed to register Samba handlers"); ldb_set_utf8_fns(ldb, NULL, wrap_casefold); /* Check behaviour of a normal DN */ torture_assert(torture, dn = ldb_dn_new(mem_ctx, ldb, dn_str), "Failed to create a 'normal' DN"); torture_assert(torture, ldb_dn_validate(dn), "Failed to validate 'normal' DN"); torture_assert(torture, ldb_dn_has_extended(dn) == false, "Should not find plain DN to be 'extended'"); torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL, "Should not find an SID on plain DN"); torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL, "Should not find an GUID on plain DN"); torture_assert(torture, ldb_dn_get_extended_component(dn, "WKGUID") == NULL, "Should not find an WKGUID on plain DN"); /* Now make an extended DN */ torture_assert(torture, dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>;<SID=%s>;%s", guid, sid, dn_str), "Failed to create an 'extended' DN"); torture_assert(torture, dn2 = ldb_dn_copy(mem_ctx, dn), "Failed to copy the 'extended' DN"); talloc_free(dn); dn = dn2; torture_assert(torture, ldb_dn_validate(dn), "Failed to validate 'extended' DN"); torture_assert(torture, ldb_dn_has_extended(dn) == true, "Should find extended DN to be 'extended'"); torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL, "Should find an SID on extended DN"); torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL, "Should find an GUID on extended DN"); torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob, "Extended DN SID incorect"); torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob, "Extended DN GUID incorect"); torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), dn_str, "linearized DN incorrect"); torture_assert_str_equal(torture, ldb_dn_get_casefold(dn), strupper_talloc(mem_ctx, dn_str), "casefolded DN incorrect"); torture_assert_str_equal(torture, ldb_dn_get_component_name(dn, 0), "cn", "componet zero incorrect"); torture_assert_data_blob_equal(torture, *ldb_dn_get_component_val(dn, 0), data_blob_string_const("admin"), "componet zero incorrect"); torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1), talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s", guid, sid, dn_str), "Clear extended linearized DN incorrect"); torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0), talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s", hex_guid, hex_sid, dn_str), "HEX extended linearized DN incorrect"); torture_assert(torture, ldb_dn_remove_child_components(dn, 1) == true, "Failed to remove DN child"); torture_assert(torture, ldb_dn_has_extended(dn) == false, "Extended DN flag should be cleared after child element removal"); torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL, "Should not find an SID on DN"); torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL, "Should not find an GUID on DN"); /* TODO: test setting these in the other order, and ensure it still comes out 'GUID first' */ torture_assert_int_equal(torture, ldb_dn_set_extended_component(dn, "GUID", &guid_blob), 0, "Failed to set a GUID on DN"); torture_assert_int_equal(torture, ldb_dn_set_extended_component(dn, "SID", &sid_blob), 0, "Failed to set a SID on DN"); torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob, "Extended DN SID incorect"); torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob, "Extended DN GUID incorect"); torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "cn=users,dc=samba,dc=org", "linearized DN incorrect"); torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1), talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s", guid, sid, "cn=users,dc=samba,dc=org"), "Clear extended linearized DN incorrect"); torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0), talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s", hex_guid, hex_sid, "cn=users,dc=samba,dc=org"), "HEX extended linearized DN incorrect"); /* Now check a 'just GUID' DN (clear format) */ torture_assert(torture, dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>", guid), "Failed to create an 'extended' DN"); torture_assert(torture, ldb_dn_validate(dn), "Failed to validate 'extended' DN"); torture_assert(torture, ldb_dn_has_extended(dn) == true, "Should find extended DN to be 'extended'"); torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL, "Should not find an SID on this DN"); torture_assert_int_equal(torture, ldb_dn_get_comp_num(dn), 0, "Should not find an 'normal' componet on this DN"); torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL, "Should find an GUID on this DN"); torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob, "Extended DN GUID incorect"); torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "", "linearized DN incorrect"); torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1), talloc_asprintf(mem_ctx, "<GUID=%s>", guid), "Clear extended linearized DN incorrect"); torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0), talloc_asprintf(mem_ctx, "<GUID=%s>", hex_guid), "HEX extended linearized DN incorrect"); /* Now check a 'just GUID' DN (HEX format) */ torture_assert(torture, dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>", hex_guid), "Failed to create an 'extended' DN"); torture_assert(torture, ldb_dn_validate(dn), "Failed to validate 'extended' DN"); torture_assert(torture, ldb_dn_has_extended(dn) == true, "Should find extended DN to be 'extended'"); torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL, "Should not find an SID on this DN"); torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL, "Should find an GUID on this DN"); torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob, "Extended DN GUID incorect"); torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "", "linearized DN incorrect"); /* Now check a 'just SID' DN (clear format) */ torture_assert(torture, dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>", sid), "Failed to create an 'extended' DN"); torture_assert(torture, ldb_dn_validate(dn), "Failed to validate 'extended' DN"); torture_assert(torture, ldb_dn_has_extended(dn) == true, "Should find extended DN to be 'extended'"); torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL, "Should not find an SID on this DN"); torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL, "Should find an SID on this DN"); torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob, "Extended DN SID incorect"); torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "", "linearized DN incorrect"); torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1), talloc_asprintf(mem_ctx, "<SID=%s>", sid), "Clear extended linearized DN incorrect"); torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0), talloc_asprintf(mem_ctx, "<SID=%s>", hex_sid), "HEX extended linearized DN incorrect"); /* Now check a 'just SID' DN (HEX format) */ torture_assert(torture, dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>", hex_sid), "Failed to create an 'extended' DN"); torture_assert(torture, ldb_dn_validate(dn), "Failed to validate 'extended' DN"); torture_assert(torture, ldb_dn_has_extended(dn) == true, "Should find extended DN to be 'extended'"); torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL, "Should not find an SID on this DN"); torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL, "Should find an SID on this DN"); torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob, "Extended DN SID incorect"); torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "", "linearized DN incorrect"); talloc_free(mem_ctx); return true; }
static bool torture_ldb_dn_attrs(struct torture_context *torture) { TALLOC_CTX *mem_ctx = talloc_new(torture); struct ldb_context *ldb; const struct ldb_dn_extended_syntax *attr; struct ldb_val string_sid_blob, binary_sid_blob; struct ldb_val string_guid_blob, binary_guid_blob; struct ldb_val hex_sid_blob, hex_guid_blob; DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid); DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid); torture_assert(torture, ldb = ldb_init(mem_ctx, torture->ev), "Failed to init ldb"); torture_assert_int_equal(torture, ldb_register_samba_handlers(ldb), 0, "Failed to register Samba handlers"); ldb_set_utf8_fns(ldb, NULL, wrap_casefold); /* Test SID behaviour */ torture_assert(torture, attr = ldb_dn_extended_syntax_by_name(ldb, "SID"), "Failed to get SID DN syntax"); string_sid_blob = data_blob_string_const(sid); torture_assert_int_equal(torture, attr->read_fn(ldb, mem_ctx, &string_sid_blob, &binary_sid_blob), 0, "Failed to parse string SID"); torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob, "Read SID into blob form failed"); hex_sid_blob = data_blob_string_const(hex_sid); torture_assert_int_equal(torture, attr->read_fn(ldb, mem_ctx, &hex_sid_blob, &binary_sid_blob), 0, "Failed to parse HEX SID"); torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob, "Read SID into blob form failed"); torture_assert_int_equal(torture, attr->read_fn(ldb, mem_ctx, &sid_blob, &binary_sid_blob), -1, "Should have failed to parse binary SID"); torture_assert_int_equal(torture, attr->write_hex_fn(ldb, mem_ctx, &sid_blob, &hex_sid_blob), 0, "Failed to parse binary SID"); torture_assert_data_blob_equal(torture, hex_sid_blob, data_blob_string_const(hex_sid), "Write SID into HEX string form failed"); torture_assert_int_equal(torture, attr->write_clear_fn(ldb, mem_ctx, &sid_blob, &string_sid_blob), 0, "Failed to parse binary SID"); torture_assert_data_blob_equal(torture, string_sid_blob, data_blob_string_const(sid), "Write SID into clear string form failed"); /* Test GUID behaviour */ torture_assert(torture, attr = ldb_dn_extended_syntax_by_name(ldb, "GUID"), "Failed to get GUID DN syntax"); string_guid_blob = data_blob_string_const(guid); torture_assert_int_equal(torture, attr->read_fn(ldb, mem_ctx, &string_guid_blob, &binary_guid_blob), 0, "Failed to parse string GUID"); torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob, "Read GUID into blob form failed"); hex_guid_blob = data_blob_string_const(hex_guid); torture_assert_int_equal(torture, attr->read_fn(ldb, mem_ctx, &hex_guid_blob, &binary_guid_blob), 0, "Failed to parse HEX GUID"); torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob, "Read GUID into blob form failed"); torture_assert_int_equal(torture, attr->read_fn(ldb, mem_ctx, &guid_blob, &binary_guid_blob), -1, "Should have failed to parse binary GUID"); torture_assert_int_equal(torture, attr->write_hex_fn(ldb, mem_ctx, &guid_blob, &hex_guid_blob), 0, "Failed to parse binary GUID"); torture_assert_data_blob_equal(torture, hex_guid_blob, data_blob_string_const(hex_guid), "Write GUID into HEX string form failed"); torture_assert_int_equal(torture, attr->write_clear_fn(ldb, mem_ctx, &guid_blob, &string_guid_blob), 0, "Failed to parse binary GUID"); torture_assert_data_blob_equal(torture, string_guid_blob, data_blob_string_const(guid), "Write GUID into clear string form failed"); talloc_free(mem_ctx); return true; }