⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldb_map_outbound.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 3 页
字号:
		ret = ldb_msg_el_merge(ac->module, local, remote, 				       attrs[i]);		if (ret == LDB_ERR_NO_SUCH_ATTRIBUTE) {		} else if (ret) {			return ret;		}	}	return LDB_SUCCESS;}/* Mapping search results * ====================== *//* Map a search result back into the local partition. */static int map_reply_remote(struct map_context *ac, struct ldb_reply *ares){	struct ldb_message *msg;	struct ldb_dn *dn;	int ret;	/* There is no result message, skip */	if (ares->type != LDB_REPLY_ENTRY) {		return 0;	}	/* Create a new result message */	msg = ldb_msg_new(ares);	if (msg == NULL) {		map_oom(ac->module);		return -1;	}	/* Merge remote message into new message */	ret = ldb_msg_merge_remote(ac, msg, ares->message);	if (ret) {		talloc_free(msg);		return ret;	}	/* Create corresponding local DN */	dn = ldb_dn_map_rebase_remote(ac->module, msg, ares->message->dn);	if (dn == NULL) {		talloc_free(msg);		return -1;	}	msg->dn = dn;	/* Store new message with new DN as the result */	talloc_free(ares->message);	ares->message = msg;	return 0;}/* Mapping parse trees * =================== *//* Check whether a parse tree can safely be split in two. */static bool ldb_parse_tree_check_splittable(const struct ldb_parse_tree *tree){	const struct ldb_parse_tree *subtree = tree;	bool negate = false;	while (subtree) {		switch (subtree->operation) {		case LDB_OP_NOT:			negate = !negate;			subtree = subtree->u.isnot.child;			continue;		case LDB_OP_AND:			return !negate;	/* if negate: False */		case LDB_OP_OR:			return negate;	/* if negate: True */		default:			return true;	/* simple parse tree */		}	}	return true;			/* no parse tree */}/* Collect a list of attributes required to match a given parse tree. */static int ldb_parse_tree_collect_attrs(struct ldb_module *module, void *mem_ctx, const char ***attrs, const struct ldb_parse_tree *tree){	const char **new_attrs;	int i, ret;	if (tree == NULL) {		return 0;	}	switch (tree->operation) {	case LDB_OP_OR:	case LDB_OP_AND:		/* attributes stored in list of subtrees */		for (i = 0; i < tree->u.list.num_elements; i++) {			ret = ldb_parse_tree_collect_attrs(module, mem_ctx, 							   attrs, tree->u.list.elements[i]);			if (ret) {				return ret;			}		}		return 0;	case LDB_OP_NOT:		/* attributes stored in single subtree */		return ldb_parse_tree_collect_attrs(module, mem_ctx, attrs, tree->u.isnot.child);	default:			/* single attribute in tree */		new_attrs = ldb_attr_list_copy_add(mem_ctx, *attrs, tree->u.equality.attr);		talloc_free(*attrs);		*attrs = new_attrs;		return 0;	}	return -1;}static int map_subtree_select_local(struct ldb_module *module, void *mem_ctx, struct ldb_parse_tree **new, const struct ldb_parse_tree *tree);/* Select a negated subtree that queries attributes in the local partition */static int map_subtree_select_local_not(struct ldb_module *module, void *mem_ctx, struct ldb_parse_tree **new, const struct ldb_parse_tree *tree){	struct ldb_parse_tree *child;	int ret;	/* Prepare new tree */	*new = talloc_memdup(mem_ctx, tree, sizeof(struct ldb_parse_tree));	if (*new == NULL) {		map_oom(module);		return -1;	}	/* Generate new subtree */	ret = map_subtree_select_local(module, *new, &child, tree->u.isnot.child);	if (ret) {		talloc_free(*new);		return ret;	}	/* Prune tree without subtree */	if (child == NULL) {		talloc_free(*new);		*new = NULL;		return 0;	}	(*new)->u.isnot.child = child;	return ret;}/* Select a list of subtrees that query attributes in the local partition */static int map_subtree_select_local_list(struct ldb_module *module, void *mem_ctx, struct ldb_parse_tree **new, const struct ldb_parse_tree *tree){	int i, j, ret=0;	/* Prepare new tree */	*new = talloc_memdup(mem_ctx, tree, sizeof(struct ldb_parse_tree));	if (*new == NULL) {		map_oom(module);		return -1;	}	/* Prepare list of subtrees */	(*new)->u.list.num_elements = 0;	(*new)->u.list.elements = talloc_array(*new, struct ldb_parse_tree *, tree->u.list.num_elements);	if ((*new)->u.list.elements == NULL) {		map_oom(module);		talloc_free(*new);		return -1;	}	/* Generate new list of subtrees */	j = 0;	for (i = 0; i < tree->u.list.num_elements; i++) {		struct ldb_parse_tree *child;		ret = map_subtree_select_local(module, *new, &child, tree->u.list.elements[i]);		if (ret) {			talloc_free(*new);			return ret;		}		if (child) {			(*new)->u.list.elements[j] = child;			j++;		}	}	/* Prune tree without subtrees */	if (j == 0) {		talloc_free(*new);		*new = NULL;		return 0;	}	/* Fix subtree list size */	(*new)->u.list.num_elements = j;	(*new)->u.list.elements = talloc_realloc(*new, (*new)->u.list.elements, struct ldb_parse_tree *, (*new)->u.list.num_elements);	return ret;}/* Select a simple subtree that queries attributes in the local partition */static int map_subtree_select_local_simple(struct ldb_module *module, void *mem_ctx, struct ldb_parse_tree **new, const struct ldb_parse_tree *tree){	/* Prepare new tree */	*new = talloc_memdup(mem_ctx, tree, sizeof(struct ldb_parse_tree));	if (*new == NULL) {		map_oom(module);		return -1;	}	return 0;}/* Select subtrees that query attributes in the local partition */static int map_subtree_select_local(struct ldb_module *module, void *mem_ctx, struct ldb_parse_tree **new, const struct ldb_parse_tree *tree){	const struct ldb_map_context *data = map_get_context(module);	if (tree == NULL) {		return 0;	}	if (tree->operation == LDB_OP_NOT) {		return map_subtree_select_local_not(module, mem_ctx, new, tree);	}	if (tree->operation == LDB_OP_AND || tree->operation == LDB_OP_OR) {		return map_subtree_select_local_list(module, mem_ctx, new, tree);	}	if (map_attr_check_remote(data, tree->u.equality.attr)) {		*new = NULL;		return 0;	}	return map_subtree_select_local_simple(module, mem_ctx, new, tree);}static int map_subtree_collect_remote(struct ldb_module *module, void *mem_ctx, struct ldb_parse_tree **new, const struct ldb_parse_tree *tree);/* Collect a negated subtree that queries attributes in the remote partition */static int map_subtree_collect_remote_not(struct ldb_module *module, void *mem_ctx, struct ldb_parse_tree **new, const struct ldb_parse_tree *tree){	struct ldb_parse_tree *child;	int ret;	/* Prepare new tree */	*new = talloc_memdup(mem_ctx, tree, sizeof(struct ldb_parse_tree));	if (*new == NULL) {		map_oom(module);		return -1;	}	/* Generate new subtree */	ret = map_subtree_collect_remote(module, *new, &child, tree->u.isnot.child);	if (ret) {		talloc_free(*new);		return ret;	}	/* Prune tree without subtree */	if (child == NULL) {		talloc_free(*new);		*new = NULL;		return 0;	}	(*new)->u.isnot.child = child;	return ret;}/* Collect a list of subtrees that query attributes in the remote partition */static int map_subtree_collect_remote_list(struct ldb_module *module, void *mem_ctx, struct ldb_parse_tree **new, const struct ldb_parse_tree *tree){	int i, j, ret=0;	/* Prepare new tree */	*new = talloc_memdup(mem_ctx, tree, sizeof(struct ldb_parse_tree));	if (*new == NULL) {		map_oom(module);		return -1;	}	/* Prepare list of subtrees */	(*new)->u.list.num_elements = 0;	(*new)->u.list.elements = talloc_array(*new, struct ldb_parse_tree *, tree->u.list.num_elements);	if ((*new)->u.list.elements == NULL) {		map_oom(module);		talloc_free(*new);		return -1;	}	/* Generate new list of subtrees */	j = 0;	for (i = 0; i < tree->u.list.num_elements; i++) {		struct ldb_parse_tree *child;		ret = map_subtree_collect_remote(module, *new, &child, tree->u.list.elements[i]);		if (ret) {			talloc_free(*new);			return ret;		}		if (child) {			(*new)->u.list.elements[j] = child;			j++;		}	}	/* Prune tree without subtrees */	if (j == 0) {		talloc_free(*new);		*new = NULL;		return 0;	}	/* Fix subtree list size */	(*new)->u.list.num_elements = j;	(*new)->u.list.elements = talloc_realloc(*new, (*new)->u.list.elements, struct ldb_parse_tree *, (*new)->u.list.num_elements);	return ret;}/* Collect a simple subtree that queries attributes in the remote partition */int map_subtree_collect_remote_simple(struct ldb_module *module, void *mem_ctx, struct ldb_parse_tree **new, const struct ldb_parse_tree *tree, const struct ldb_map_attribute *map){	const char *attr;	/* Prepare new tree */	*new = talloc(mem_ctx, struct ldb_parse_tree);	if (*new == NULL) {		map_oom(module);		return -1;	}	**new = *tree;		if (map->type == MAP_KEEP) {		/* Nothing to do here */		return 0;	}	/* Store attribute and value in new tree */	switch (tree->operation) {	case LDB_OP_PRESENT:		attr = map_attr_map_local(*new, map, tree->u.present.attr);		(*new)->u.present.attr = attr;		break;	case LDB_OP_SUBSTRING:	{		attr = map_attr_map_local(*new, map, tree->u.substring.attr);		(*new)->u.substring.attr = attr;		break;	}	case LDB_OP_EQUALITY:		attr = map_attr_map_local(*new, map, tree->u.equality.attr);		(*new)->u.equality.attr = attr;		break;	case LDB_OP_LESS:	case LDB_OP_GREATER:	case LDB_OP_APPROX:		attr = map_attr_map_local(*new, map, tree->u.comparison.attr);		(*new)->u.comparison.attr = attr;		break;	case LDB_OP_EXTENDED:		attr = map_attr_map_local(*new, map, tree->u.extended.attr);		(*new)->u.extended.attr = attr;		break;	default:			/* unknown kind of simple subtree */		talloc_free(*new);		return -1;	}	if (attr == NULL) {		talloc_free(*new);		*new = NULL;		return 0;	}	if (map->type == MAP_RENAME) {		/* Nothing more to do here, the attribute has been renamed */		return 0;	}	/* Store attribute and value in new tree */	switch (tree->operation) {	case LDB_OP_PRESENT:		break;	case LDB_OP_SUBSTRING:	{		int i;		/* Map value */		(*new)->u.substring.chunks = NULL;		for (i=0; tree->u.substring.chunks[i]; i++) {			(*new)->u.substring.chunks = talloc_realloc(*new, (*new)->u.substring.chunks, struct ldb_val *, i+2);			if (!(*new)->u.substring.chunks) {				talloc_free(*new);				*new = NULL;				return 0;			}			(*new)->u.substring.chunks[i] = talloc(*new, struct ldb_val);			if (!(*new)->u.substring.chunks[i]) {				talloc_free(*new);				*new = NULL;				return 0;			}			*(*new)->u.substring.chunks[i] = ldb_val_map_local(module, *new, map, tree->u.substring.chunks[i]);			(*new)->u.substring.chunks[i+1] = NULL;		}		break;	}	case LDB_OP_EQUALITY:		(*new)->u.equality.value = ldb_val_map_local(module, *new, map, &tree->u.equality.value);		break;	case LDB_OP_LESS:	case LDB_OP_GREATER:	case LDB_OP_APPROX:		(*new)->u.comparison.value = ldb_val_map_local(module, *new, map, &tree->u.comparison.value);		break;	case LDB_OP_EXTENDED:		(*new)->u.extended.value = ldb_val_map_local(module, *new, map, &tree->u.extended.value);		(*new)->u.extended.rule_id = talloc_strdup(*new, tree->u.extended.rule_id);		break;	default:			/* unknown kind of simple subtree */		talloc_free(*new);		return -1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -