示例#1
0
WERROR dsdb_read_prefixes_from_ldb(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct dsdb_schema_prefixmap **_pfm)
{
	WERROR werr;
	int ldb_ret;
	const struct ldb_val *prefix_val;
	struct smb_iconv_convenience *iconv_convenience;
	struct ldb_dn *schema_dn;
	struct ldb_result *schema_res = NULL;
	static const char *schema_attrs[] = {
		"prefixMap",
		NULL
	};

	schema_dn = samdb_schema_dn(ldb);
	if (!schema_dn) {
		DEBUG(0,("dsdb_read_prefixes_from_ldb: no schema dn present\n"));
		return WERR_FOOBAR;
	}

	ldb_ret = ldb_search(ldb, mem_ctx, &schema_res, schema_dn, LDB_SCOPE_BASE, schema_attrs, NULL);
	if (ldb_ret == LDB_ERR_NO_SUCH_OBJECT) {
		DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefix map present\n"));
		talloc_free(schema_res);
		return WERR_FOOBAR;
	} else if (ldb_ret != LDB_SUCCESS) {
		DEBUG(0,("dsdb_read_prefixes_from_ldb: failed to search the schema head\n"));
		talloc_free(schema_res);
		return WERR_FOOBAR;
	}

	prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
	if (!prefix_val) {
		DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefixMap attribute found\n"));
		talloc_free(schema_res);
		return WERR_FOOBAR;
	}

	iconv_convenience = lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm"));

	werr = _dsdb_prefixmap_from_ldb_val(prefix_val,
					    iconv_convenience,
					    mem_ctx,
					    _pfm);
	talloc_free(schema_res);
	W_ERROR_NOT_OK_RETURN(werr);

	return WERR_OK;
}
示例#2
0
WERROR dsdb_load_oid_mappings_ldb(struct dsdb_schema *schema,
				  const struct ldb_val *prefixMap,
				  const struct ldb_val *schemaInfo)
{
	WERROR werr;
	const char *schema_info;
	struct dsdb_schema_prefixmap *pfm;
	TALLOC_CTX *mem_ctx;

	/* verify schemaInfo blob is valid one */
	if (!dsdb_schema_info_blob_is_valid(schemaInfo)) {
		DEBUG(0,(__location__": dsdb_schema_info_blob_is_valid() failed.\n"));
	        return WERR_INVALID_PARAMETER;
	}

	mem_ctx = talloc_new(schema);
	W_ERROR_HAVE_NO_MEMORY(mem_ctx);

	/* fetch prefixMap */
	werr = _dsdb_prefixmap_from_ldb_val(prefixMap,
					    mem_ctx, &pfm);
	if (!W_ERROR_IS_OK(werr)) {
		DEBUG(0, (__location__ " _dsdb_prefixmap_from_ldb_val failed: %s\n", win_errstr(werr)));
		talloc_free(mem_ctx);
		return werr;
	}

	/* decode schema_info */
	schema_info = hex_encode_talloc(mem_ctx,
					schemaInfo->data,
					schemaInfo->length);
	if (!schema_info) {
		talloc_free(mem_ctx);
		return WERR_NOMEM;
	}

	/* store prefixMap and schema_info into cached Schema */
	talloc_free(schema->prefixmap);
	schema->prefixmap = talloc_steal(schema, pfm);

	talloc_free(discard_const(schema->schema_info));
	schema->schema_info = talloc_steal(schema, schema_info);

	/* clean up locally allocated mem */
	talloc_free(mem_ctx);

	return WERR_OK;
}
示例#3
0
WERROR dsdb_load_oid_mappings_ldb(struct dsdb_schema *schema,
				  const struct ldb_val *prefixMap,
				  const struct ldb_val *schemaInfo)
{
	WERROR status;
	const char *schema_info;
	struct dsdb_schema_prefixmap *pfm;
	TALLOC_CTX *mem_ctx;

	/* verify input params */
	if (schemaInfo->length != 21) {
		return WERR_INVALID_PARAMETER;
	}
	if (schemaInfo->data[0] != 0xFF) {
		return WERR_INVALID_PARAMETER;
	}

	mem_ctx = talloc_new(schema);
	W_ERROR_HAVE_NO_MEMORY(mem_ctx);

	/* fetch prefixMap */
	status = _dsdb_prefixmap_from_ldb_val(prefixMap,
					      schema->iconv_convenience,
					      mem_ctx, &pfm);
	W_ERROR_NOT_OK_RETURN(status);

	/* decode schema_info */
	schema_info = hex_encode_talloc(mem_ctx,
					schemaInfo->data,
					schemaInfo->length);
	if (!schema_info) {
		talloc_free(mem_ctx);
		return WERR_NOMEM;
	}

	/* store prefixMap and schema_info into cached Schema */
	talloc_free(schema->prefixmap);
	schema->prefixmap = talloc_steal(schema, pfm);

	talloc_free(discard_const(schema->schema_info));
	schema->schema_info = talloc_steal(schema, schema_info);

	/* clean up locally allocated mem */
	talloc_free(mem_ctx);

	return WERR_OK;
}