mirror of
https://github.com/samba-team/samba.git
synced 2025-08-02 00:22:11 +03:00
r19531: Make struct ldb_dn opaque and local to ldb_dn.c
(This used to be commit 889fb983ba
)
This commit is contained in:
committed by
Gerald (Jerry) Carter
parent
d046e8d0cc
commit
b7774527fa
@ -316,7 +316,7 @@ static int partition_search(struct ldb_module *module, struct ldb_request *req)
|
|||||||
ac = talloc_get_type(h->private_data, struct partition_context);
|
ac = talloc_get_type(h->private_data, struct partition_context);
|
||||||
|
|
||||||
/* Search from the base DN */
|
/* Search from the base DN */
|
||||||
if (!req->op.search.base || req->op.search.base->comp_num == 0) {
|
if (!req->op.search.base || (ldb_dn_get_comp_num(req->op.search.base) == 0)) {
|
||||||
return partition_send_all(module, ac, req);
|
return partition_send_all(module, ac, req);
|
||||||
}
|
}
|
||||||
for (i=0; data && data->partitions && data->partitions[i]; i++) {
|
for (i=0; data && data->partitions && data->partitions[i]; i++) {
|
||||||
|
@ -173,7 +173,7 @@ static int rootdse_search(struct ldb_module *module, struct ldb_request *req)
|
|||||||
|
|
||||||
/* see if its for the rootDSE */
|
/* see if its for the rootDSE */
|
||||||
if (req->op.search.scope != LDB_SCOPE_BASE ||
|
if (req->op.search.scope != LDB_SCOPE_BASE ||
|
||||||
(req->op.search.base && req->op.search.base->comp_num != 0)) {
|
(req->op.search.base && ldb_dn_get_comp_num(req->op.search.base) != 0)) {
|
||||||
return ldb_next_request(module, req);
|
return ldb_next_request(module, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,7 +433,7 @@ static int samldb_fill_group_object(struct ldb_module *module, const struct ldb_
|
|||||||
int ret;
|
int ret;
|
||||||
const char *name;
|
const char *name;
|
||||||
struct ldb_message *msg2;
|
struct ldb_message *msg2;
|
||||||
struct ldb_dn_component *rdn;
|
const char *rdn_name;
|
||||||
TALLOC_CTX *mem_ctx = talloc_new(msg);
|
TALLOC_CTX *mem_ctx = talloc_new(msg);
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
if (!mem_ctx) {
|
if (!mem_ctx) {
|
||||||
@ -457,10 +457,10 @@ static int samldb_fill_group_object(struct ldb_module *module, const struct ldb_
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
rdn = ldb_dn_get_rdn(msg2, msg2->dn);
|
rdn_name = ldb_dn_get_rdn_name(msg2->dn);
|
||||||
|
|
||||||
if (strcasecmp(rdn->name, "cn") != 0) {
|
if (strcasecmp(rdn_name, "cn") != 0) {
|
||||||
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_fill_group_object: Bad RDN (%s) for group!\n", rdn->name);
|
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_fill_group_object: Bad RDN (%s) for group!\n", rdn_name);
|
||||||
talloc_free(mem_ctx);
|
talloc_free(mem_ctx);
|
||||||
return LDB_ERR_CONSTRAINT_VIOLATION;
|
return LDB_ERR_CONSTRAINT_VIOLATION;
|
||||||
}
|
}
|
||||||
@ -496,7 +496,7 @@ static int samldb_fill_user_or_computer_object(struct ldb_module *module, const
|
|||||||
int ret;
|
int ret;
|
||||||
char *name;
|
char *name;
|
||||||
struct ldb_message *msg2;
|
struct ldb_message *msg2;
|
||||||
struct ldb_dn_component *rdn;
|
const char *rdn_name;
|
||||||
TALLOC_CTX *mem_ctx = talloc_new(msg);
|
TALLOC_CTX *mem_ctx = talloc_new(msg);
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
if (!mem_ctx) {
|
if (!mem_ctx) {
|
||||||
@ -556,10 +556,10 @@ static int samldb_fill_user_or_computer_object(struct ldb_module *module, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rdn = ldb_dn_get_rdn(msg2, msg2->dn);
|
rdn_name = ldb_dn_get_rdn_name(msg2->dn);
|
||||||
|
|
||||||
if (strcasecmp(rdn->name, "cn") != 0) {
|
if (strcasecmp(rdn_name, "cn") != 0) {
|
||||||
ldb_asprintf_errstring(module->ldb, "Bad RDN (%s=) for user/computer, should be CN=!\n", rdn->name);
|
ldb_asprintf_errstring(module->ldb, "Bad RDN (%s=) for user/computer, should be CN=!\n", rdn_name);
|
||||||
talloc_free(mem_ctx);
|
talloc_free(mem_ctx);
|
||||||
return LDB_ERR_CONSTRAINT_VIOLATION;
|
return LDB_ERR_CONSTRAINT_VIOLATION;
|
||||||
}
|
}
|
||||||
@ -598,7 +598,7 @@ static int samldb_fill_foreignSecurityPrincipal_object(struct ldb_module *module
|
|||||||
struct ldb_message **ret_msg)
|
struct ldb_message **ret_msg)
|
||||||
{
|
{
|
||||||
struct ldb_message *msg2;
|
struct ldb_message *msg2;
|
||||||
struct ldb_dn_component *rdn;
|
const char *rdn_name;
|
||||||
struct dom_sid *dom_sid;
|
struct dom_sid *dom_sid;
|
||||||
struct dom_sid *sid;
|
struct dom_sid *sid;
|
||||||
const char *dom_attrs[] = { "name", NULL };
|
const char *dom_attrs[] = { "name", NULL };
|
||||||
@ -631,10 +631,10 @@ static int samldb_fill_foreignSecurityPrincipal_object(struct ldb_module *module
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
rdn = ldb_dn_get_rdn(msg2, msg2->dn);
|
rdn_name = ldb_dn_get_rdn_name(msg2->dn);
|
||||||
|
|
||||||
if (strcasecmp(rdn->name, "cn") != 0) {
|
if (strcasecmp(rdn_name, "cn") != 0) {
|
||||||
ldb_asprintf_errstring(module->ldb, "Bad RDN (%s=) for ForeignSecurityPrincipal, should be CN=!", rdn->name);
|
ldb_asprintf_errstring(module->ldb, "Bad RDN (%s=) for ForeignSecurityPrincipal, should be CN=!", rdn_name);
|
||||||
talloc_free(mem_ctx);
|
talloc_free(mem_ctx);
|
||||||
return LDB_ERR_CONSTRAINT_VIOLATION;
|
return LDB_ERR_CONSTRAINT_VIOLATION;
|
||||||
}
|
}
|
||||||
@ -643,7 +643,7 @@ static int samldb_fill_foreignSecurityPrincipal_object(struct ldb_module *module
|
|||||||
* domain SIDs ending up there, it would cause all sorts of
|
* domain SIDs ending up there, it would cause all sorts of
|
||||||
* pain */
|
* pain */
|
||||||
|
|
||||||
sid = dom_sid_parse_talloc(msg2, (const char *)rdn->value.data);
|
sid = dom_sid_parse_talloc(msg2, (const char *)ldb_dn_get_rdn_val(msg2->dn)->data);
|
||||||
if (!sid) {
|
if (!sid) {
|
||||||
ldb_set_errstring(module->ldb, "No valid found SID in ForeignSecurityPrincipal CN!");
|
ldb_set_errstring(module->ldb, "No valid found SID in ForeignSecurityPrincipal CN!");
|
||||||
talloc_free(mem_ctx);
|
talloc_free(mem_ctx);
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
#define VALID_DN_SYNTAX(dn,i) do {\
|
#define VALID_DN_SYNTAX(dn,i) do {\
|
||||||
if (!(dn)) {\
|
if (!(dn)) {\
|
||||||
return NT_STATUS_NO_MEMORY;\
|
return NT_STATUS_NO_MEMORY;\
|
||||||
} else if ((dn)->comp_num < (i)) {\
|
} else if (ldb_dn_get_comp_num(dn) < (i)) {\
|
||||||
result = LDAP_INVALID_DN_SYNTAX;\
|
result = LDAP_INVALID_DN_SYNTAX;\
|
||||||
errstr = "Invalid DN (" #i " components needed for '" #dn "')";\
|
errstr = "Invalid DN (" #i " components needed for '" #dn "')";\
|
||||||
goto reply;\
|
goto reply;\
|
||||||
@ -641,7 +641,7 @@ static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call)
|
|||||||
goto reply;
|
goto reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newrdn->comp_num > 1) {
|
if (ldb_dn_get_comp_num(newrdn) > 1) {
|
||||||
result = LDAP_NAMING_VIOLATION;
|
result = LDAP_NAMING_VIOLATION;
|
||||||
errstr = "Error new RDN invalid";
|
errstr = "Error new RDN invalid";
|
||||||
goto reply;
|
goto reply;
|
||||||
@ -652,7 +652,7 @@ static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call)
|
|||||||
VALID_DN_SYNTAX(parentdn, 0);
|
VALID_DN_SYNTAX(parentdn, 0);
|
||||||
DEBUG(10, ("ModifyDNRequest: newsuperior: [%s]\n", req->newsuperior));
|
DEBUG(10, ("ModifyDNRequest: newsuperior: [%s]\n", req->newsuperior));
|
||||||
|
|
||||||
if (parentdn->comp_num < 1) {
|
if (ldb_dn_get_comp_num(parentdn) < 1) {
|
||||||
result = LDAP_AFFECTS_MULTIPLE_DSAS;
|
result = LDAP_AFFECTS_MULTIPLE_DSAS;
|
||||||
errstr = "Error new Superior DN invalid";
|
errstr = "Error new Superior DN invalid";
|
||||||
goto reply;
|
goto reply;
|
||||||
@ -664,7 +664,10 @@ static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call)
|
|||||||
NT_STATUS_HAVE_NO_MEMORY(parentdn);
|
NT_STATUS_HAVE_NO_MEMORY(parentdn);
|
||||||
}
|
}
|
||||||
|
|
||||||
newdn = ldb_dn_make_child(local_ctx, ldb_dn_get_rdn(local_ctx, newrdn), parentdn);
|
newdn = ldb_dn_build_child(local_ctx,
|
||||||
|
ldb_dn_get_rdn_name(newrdn),
|
||||||
|
(char *)ldb_dn_get_rdn_val(newrdn)->data,
|
||||||
|
parentdn);
|
||||||
NT_STATUS_HAVE_NO_MEMORY(newdn);
|
NT_STATUS_HAVE_NO_MEMORY(newdn);
|
||||||
|
|
||||||
reply:
|
reply:
|
||||||
|
@ -41,6 +41,19 @@
|
|||||||
|
|
||||||
#define LDB_SPECIAL "@SPECIAL"
|
#define LDB_SPECIAL "@SPECIAL"
|
||||||
|
|
||||||
|
/**
|
||||||
|
internal ldb exploded dn structures
|
||||||
|
*/
|
||||||
|
struct ldb_dn_component {
|
||||||
|
char *name;
|
||||||
|
struct ldb_val value;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ldb_dn {
|
||||||
|
int comp_num;
|
||||||
|
struct ldb_dn_component *components;
|
||||||
|
};
|
||||||
|
|
||||||
int ldb_dn_is_special(const struct ldb_dn *dn)
|
int ldb_dn_is_special(const struct ldb_dn *dn)
|
||||||
{
|
{
|
||||||
if (dn == NULL || dn->comp_num != 1) return 0;
|
if (dn == NULL || dn->comp_num != 1) return 0;
|
||||||
@ -688,6 +701,26 @@ static struct ldb_dn_component ldb_dn_copy_component(void *mem_ctx, struct ldb_d
|
|||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Copy a DN but replace the old with the new base DN. */
|
||||||
|
struct ldb_dn *ldb_dn_copy_rebase(void *mem_ctx, const struct ldb_dn *old, const struct ldb_dn *old_base, const struct ldb_dn *new_base)
|
||||||
|
{
|
||||||
|
struct ldb_dn *new;
|
||||||
|
int i, offset;
|
||||||
|
|
||||||
|
/* Perhaps we don't need to rebase at all? */
|
||||||
|
if (!old_base || !new_base) {
|
||||||
|
return ldb_dn_copy(mem_ctx, old);
|
||||||
|
}
|
||||||
|
|
||||||
|
offset = old->comp_num - old_base->comp_num;
|
||||||
|
new = ldb_dn_copy_partial(mem_ctx, new_base, offset + new_base->comp_num);
|
||||||
|
for (i = 0; i < offset; i++) {
|
||||||
|
new->components[i] = ldb_dn_copy_component(new->components, &(old->components[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new;
|
||||||
|
}
|
||||||
|
|
||||||
/* copy specified number of elements of a dn into a new one
|
/* copy specified number of elements of a dn into a new one
|
||||||
element are copied from top level up to the unique rdn
|
element are copied from top level up to the unique rdn
|
||||||
num_el may be greater than dn->comp_num (see ldb_dn_make_child)
|
num_el may be greater than dn->comp_num (see ldb_dn_make_child)
|
||||||
@ -799,15 +832,6 @@ failed:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ldb_dn *ldb_dn_make_child(void *mem_ctx, const struct ldb_dn_component *component,
|
|
||||||
const struct ldb_dn *base)
|
|
||||||
{
|
|
||||||
if (component == NULL) return NULL;
|
|
||||||
|
|
||||||
return ldb_dn_build_child(mem_ctx, component->name,
|
|
||||||
(char *)component->value.data, base);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const struct ldb_dn *dn2)
|
struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const struct ldb_dn *dn2)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -872,28 +896,6 @@ struct ldb_dn *ldb_dn_string_compose(void *mem_ctx, const struct ldb_dn *base, c
|
|||||||
return dn;
|
return dn;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ldb_dn_component *ldb_dn_get_rdn(void *mem_ctx, const struct ldb_dn *dn)
|
|
||||||
{
|
|
||||||
struct ldb_dn_component *rdn;
|
|
||||||
|
|
||||||
if (dn == NULL) return NULL;
|
|
||||||
|
|
||||||
if (dn->comp_num < 1) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
rdn = talloc(mem_ctx, struct ldb_dn_component);
|
|
||||||
if (rdn == NULL) return NULL;
|
|
||||||
|
|
||||||
*rdn = ldb_dn_copy_component(mem_ctx, &dn->components[0]);
|
|
||||||
if (rdn->name == NULL) {
|
|
||||||
talloc_free(rdn);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rdn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create a 'canonical name' string from a DN:
|
/* Create a 'canonical name' string from a DN:
|
||||||
|
|
||||||
ie dc=samba,dc=org -> samba.org/
|
ie dc=samba,dc=org -> samba.org/
|
||||||
@ -962,3 +964,58 @@ char *ldb_dn_canonical_string(void *mem_ctx, const struct ldb_dn *dn) {
|
|||||||
char *ldb_dn_canonical_ex_string(void *mem_ctx, const struct ldb_dn *dn) {
|
char *ldb_dn_canonical_ex_string(void *mem_ctx, const struct ldb_dn *dn) {
|
||||||
return ldb_dn_canonical(mem_ctx, dn, 1);
|
return ldb_dn_canonical(mem_ctx, dn, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ldb_dn_get_comp_num(const struct ldb_dn *dn)
|
||||||
|
{
|
||||||
|
return dn->comp_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *ldb_dn_get_component_name(const struct ldb_dn *dn, unsigned int num)
|
||||||
|
{
|
||||||
|
if (num >= dn->comp_num) return NULL;
|
||||||
|
return dn->components[num].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct ldb_val *ldb_dn_get_component_val(const struct ldb_dn *dn, unsigned int num)
|
||||||
|
{
|
||||||
|
if (num >= dn->comp_num) return NULL;
|
||||||
|
return &dn->components[num].value;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *ldb_dn_get_rdn_name(const struct ldb_dn *dn) {
|
||||||
|
if (dn->comp_num == 0) return NULL;
|
||||||
|
return dn->components[0].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct ldb_val *ldb_dn_get_rdn_val(const struct ldb_dn *dn) {
|
||||||
|
if (dn->comp_num == 0) return NULL;
|
||||||
|
return &dn->components[0].value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ldb_dn_set_component(struct ldb_dn *dn, int num, const char *name, const struct ldb_val val)
|
||||||
|
{
|
||||||
|
char *n;
|
||||||
|
struct ldb_val v;
|
||||||
|
|
||||||
|
if (num >= dn->comp_num) {
|
||||||
|
return LDB_ERR_OTHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = talloc_strdup(dn, name);
|
||||||
|
if ( ! n) {
|
||||||
|
return LDB_ERR_OTHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
v.length = val.length;
|
||||||
|
v.data = (uint8_t *)talloc_memdup(dn, val.data, v.length+1);
|
||||||
|
if ( ! v.data) {
|
||||||
|
return LDB_ERR_OTHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
talloc_free(dn->components[num].name);
|
||||||
|
talloc_free(dn->components[num].value.data);
|
||||||
|
dn->components[num].name = n;
|
||||||
|
dn->components[num].value = v;
|
||||||
|
|
||||||
|
return LDB_SUCCESS;
|
||||||
|
}
|
||||||
|
@ -58,7 +58,7 @@ static int ldb_match_scope(struct ldb_context *ldb,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LDB_SCOPE_ONELEVEL:
|
case LDB_SCOPE_ONELEVEL:
|
||||||
if (dn->comp_num == (base->comp_num + 1)) {
|
if (ldb_dn_get_comp_num(dn) == (ldb_dn_get_comp_num(base) + 1)) {
|
||||||
if (ldb_dn_compare_base(ldb, base, dn) == 0) {
|
if (ldb_dn_compare_base(ldb, base, dn) == 0) {
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
Copyright (C) Andrew Tridgell 2004
|
Copyright (C) Andrew Tridgell 2004
|
||||||
Copyright (C) Stefan Metzmacher 2004
|
Copyright (C) Stefan Metzmacher 2004
|
||||||
Copyright (C) Simo Sorce 2005
|
Copyright (C) Simo Sorce 2005-2006
|
||||||
|
|
||||||
** NOTE! The following LGPL license applies to the ldb
|
** NOTE! The following LGPL license applies to the ldb
|
||||||
** library. This does NOT imply that all of Samba is released
|
** library. This does NOT imply that all of Samba is released
|
||||||
@ -86,18 +86,9 @@ struct ldb_val {
|
|||||||
#endif
|
#endif
|
||||||
/*! \endcond */
|
/*! \endcond */
|
||||||
|
|
||||||
/**
|
/* opaque ldb_dn structures, see ldb_dn.c for internals */
|
||||||
internal ldb exploded dn structures
|
struct ldb_dn_component;
|
||||||
*/
|
struct ldb_dn;
|
||||||
struct ldb_dn_component {
|
|
||||||
char *name;
|
|
||||||
struct ldb_val value;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ldb_dn {
|
|
||||||
int comp_num;
|
|
||||||
struct ldb_dn_component *components;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
There are a number of flags that are used with ldap_modify() in
|
There are a number of flags that are used with ldap_modify() in
|
||||||
@ -193,12 +184,6 @@ enum ldb_scope {LDB_SCOPE_DEFAULT=-1,
|
|||||||
|
|
||||||
struct ldb_context;
|
struct ldb_context;
|
||||||
|
|
||||||
/*
|
|
||||||
the fuction type for the callback used in traversing the database
|
|
||||||
*/
|
|
||||||
typedef int (*ldb_traverse_fn)(struct ldb_context *, const struct ldb_message *);
|
|
||||||
|
|
||||||
|
|
||||||
/* debugging uses one of the following levels */
|
/* debugging uses one of the following levels */
|
||||||
enum ldb_debug_level {LDB_DEBUG_FATAL, LDB_DEBUG_ERROR,
|
enum ldb_debug_level {LDB_DEBUG_FATAL, LDB_DEBUG_ERROR,
|
||||||
LDB_DEBUG_WARNING, LDB_DEBUG_TRACE};
|
LDB_DEBUG_WARNING, LDB_DEBUG_TRACE};
|
||||||
@ -333,22 +318,25 @@ char *ldb_binary_encode_string(void *mem_ctx, const char *string);
|
|||||||
typedef int (*ldb_attr_handler_t)(struct ldb_context *, void *mem_ctx, const struct ldb_val *, struct ldb_val *);
|
typedef int (*ldb_attr_handler_t)(struct ldb_context *, void *mem_ctx, const struct ldb_val *, struct ldb_val *);
|
||||||
typedef int (*ldb_attr_comparison_t)(struct ldb_context *, void *mem_ctx, const struct ldb_val *, const struct ldb_val *);
|
typedef int (*ldb_attr_comparison_t)(struct ldb_context *, void *mem_ctx, const struct ldb_val *, const struct ldb_val *);
|
||||||
|
|
||||||
struct ldb_attrib_handler {
|
/*
|
||||||
const char *attr;
|
attribute handler structure
|
||||||
|
|
||||||
/* LDB_ATTR_FLAG_* */
|
attr -> The attribute name
|
||||||
|
flags -> LDB_ATTR_FLAG_*
|
||||||
|
ldif_read_fn -> convert from ldif to binary format
|
||||||
|
ldif_write_fn -> convert from binary to ldif format
|
||||||
|
canonicalise_fn -> canonicalise a value, for use by indexing and dn construction
|
||||||
|
comparison_fn -> compare two values
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct ldb_attrib_handler {
|
||||||
|
|
||||||
|
const char *attr;
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
|
|
||||||
/* convert from ldif to binary format */
|
|
||||||
ldb_attr_handler_t ldif_read_fn;
|
ldb_attr_handler_t ldif_read_fn;
|
||||||
|
|
||||||
/* convert from binary to ldif format */
|
|
||||||
ldb_attr_handler_t ldif_write_fn;
|
ldb_attr_handler_t ldif_write_fn;
|
||||||
|
|
||||||
/* canonicalise a value, for use by indexing and dn construction */
|
|
||||||
ldb_attr_handler_t canonicalise_fn;
|
ldb_attr_handler_t canonicalise_fn;
|
||||||
|
|
||||||
/* compare two values */
|
|
||||||
ldb_attr_comparison_t comparison_fn;
|
ldb_attr_comparison_t comparison_fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1295,18 +1283,25 @@ struct ldb_dn *ldb_dn_casefold(struct ldb_context *ldb, void *mem_ctx, const str
|
|||||||
struct ldb_dn *ldb_dn_explode_casefold(struct ldb_context *ldb, void *mem_ctx, const char *dn);
|
struct ldb_dn *ldb_dn_explode_casefold(struct ldb_context *ldb, void *mem_ctx, const char *dn);
|
||||||
struct ldb_dn *ldb_dn_copy_partial(void *mem_ctx, const struct ldb_dn *dn, int num_el);
|
struct ldb_dn *ldb_dn_copy_partial(void *mem_ctx, const struct ldb_dn *dn, int num_el);
|
||||||
struct ldb_dn *ldb_dn_copy(void *mem_ctx, const struct ldb_dn *dn);
|
struct ldb_dn *ldb_dn_copy(void *mem_ctx, const struct ldb_dn *dn);
|
||||||
|
struct ldb_dn *ldb_dn_copy_rebase(void *mem_ctx, const struct ldb_dn *old, const struct ldb_dn *old_base, const struct ldb_dn *new_base);
|
||||||
struct ldb_dn *ldb_dn_get_parent(void *mem_ctx, const struct ldb_dn *dn);
|
struct ldb_dn *ldb_dn_get_parent(void *mem_ctx, const struct ldb_dn *dn);
|
||||||
struct ldb_dn_component *ldb_dn_build_component(void *mem_ctx, const char *attr,
|
struct ldb_dn_component *ldb_dn_build_component(void *mem_ctx, const char *attr,
|
||||||
const char *val);
|
const char *val);
|
||||||
struct ldb_dn *ldb_dn_build_child(void *mem_ctx, const char *attr,
|
struct ldb_dn *ldb_dn_build_child(void *mem_ctx, const char *attr,
|
||||||
const char * value,
|
const char * value,
|
||||||
const struct ldb_dn *base);
|
const struct ldb_dn *base);
|
||||||
struct ldb_dn *ldb_dn_make_child(void *mem_ctx,
|
|
||||||
const struct ldb_dn_component *component,
|
|
||||||
const struct ldb_dn *base);
|
|
||||||
struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const struct ldb_dn *dn2);
|
struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const struct ldb_dn *dn2);
|
||||||
struct ldb_dn *ldb_dn_string_compose(void *mem_ctx, const struct ldb_dn *base, const char *child_fmt, ...) PRINTF_ATTRIBUTE(3,4);
|
struct ldb_dn *ldb_dn_string_compose(void *mem_ctx, const struct ldb_dn *base, const char *child_fmt, ...) PRINTF_ATTRIBUTE(3,4);
|
||||||
struct ldb_dn_component *ldb_dn_get_rdn(void *mem_ctx, const struct ldb_dn *dn);
|
char *ldb_dn_canonical_string(void *mem_ctx, const struct ldb_dn *dn);
|
||||||
|
char *ldb_dn_canonical_ex_string(void *mem_ctx, const struct ldb_dn *dn);
|
||||||
|
int ldb_dn_get_comp_num(const struct ldb_dn *dn);
|
||||||
|
const char *ldb_dn_get_component_name(const struct ldb_dn *dn, unsigned int num);
|
||||||
|
const struct ldb_val *ldb_dn_get_component_val(const struct ldb_dn *dn, unsigned int num);
|
||||||
|
const char *ldb_dn_get_rdn_name(const struct ldb_dn *dn);
|
||||||
|
const struct ldb_val *ldb_dn_get_rdn_val(const struct ldb_dn *dn);
|
||||||
|
int ldb_dn_set_component(struct ldb_dn *dn, int num, const char *name, const struct ldb_val val);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* useful functions for ldb_message structure manipulation */
|
/* useful functions for ldb_message structure manipulation */
|
||||||
int ldb_dn_cmp(struct ldb_context *ldb, const char *dn1, const char *dn2);
|
int ldb_dn_cmp(struct ldb_context *ldb, const char *dn1, const char *dn2);
|
||||||
@ -1546,9 +1541,6 @@ char *ldb_timestring(void *mem_ctx, time_t t);
|
|||||||
*/
|
*/
|
||||||
time_t ldb_string_to_time(const char *s);
|
time_t ldb_string_to_time(const char *s);
|
||||||
|
|
||||||
char *ldb_dn_canonical_string(void *mem_ctx, const struct ldb_dn *dn);
|
|
||||||
char *ldb_dn_canonical_ex_string(void *mem_ctx, const struct ldb_dn *dn);
|
|
||||||
|
|
||||||
|
|
||||||
void ldb_qsort (void *const pbase, size_t total_elems, size_t size, void *opaque, ldb_qsort_cmp_fn_t cmp);
|
void ldb_qsort (void *const pbase, size_t total_elems, size_t size, void *opaque, ldb_qsort_cmp_fn_t cmp);
|
||||||
#endif
|
#endif
|
||||||
|
@ -639,8 +639,8 @@ static int ildb_rename(struct ldb_module *module, struct ldb_request *req)
|
|||||||
|
|
||||||
msg->r.ModifyDNRequest.newrdn =
|
msg->r.ModifyDNRequest.newrdn =
|
||||||
talloc_asprintf(msg, "%s=%s",
|
talloc_asprintf(msg, "%s=%s",
|
||||||
req->op.rename.newdn->components[0].name,
|
ldb_dn_get_rdn_name(req->op.rename.newdn),
|
||||||
ldb_dn_escape_value(msg, req->op.rename.newdn->components[0].value));
|
ldb_dn_escape_value(msg, *ldb_dn_get_rdn_val(req->op.rename.newdn)));
|
||||||
if (msg->r.ModifyDNRequest.newrdn == NULL) {
|
if (msg->r.ModifyDNRequest.newrdn == NULL) {
|
||||||
talloc_free(msg);
|
talloc_free(msg);
|
||||||
return LDB_ERR_OPERATIONS_ERROR;
|
return LDB_ERR_OPERATIONS_ERROR;
|
||||||
|
@ -464,7 +464,7 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req)
|
|||||||
struct ldb_reply *ares;
|
struct ldb_reply *ares;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if ((req->op.search.base == NULL || req->op.search.base->comp_num == 0) &&
|
if ((req->op.search.base == NULL || ldb_dn_get_comp_num(req->op.search.base) == 0) &&
|
||||||
(req->op.search.scope == LDB_SCOPE_BASE || req->op.search.scope == LDB_SCOPE_ONELEVEL))
|
(req->op.search.scope == LDB_SCOPE_BASE || req->op.search.scope == LDB_SCOPE_ONELEVEL))
|
||||||
return LDB_ERR_OPERATIONS_ERROR;
|
return LDB_ERR_OPERATIONS_ERROR;
|
||||||
|
|
||||||
|
@ -181,60 +181,16 @@ BOOL map_check_local_db(struct ldb_module *module)
|
|||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* WARK: verbatim copy from ldb_dn.c */
|
|
||||||
static struct ldb_dn_component ldb_dn_copy_component(void *mem_ctx, struct ldb_dn_component *src)
|
|
||||||
{
|
|
||||||
struct ldb_dn_component dst;
|
|
||||||
|
|
||||||
memset(&dst, 0, sizeof(dst));
|
|
||||||
|
|
||||||
if (src == NULL) {
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
dst.value = ldb_val_dup(mem_ctx, &(src->value));
|
|
||||||
if (dst.value.data == NULL) {
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
dst.name = talloc_strdup(mem_ctx, src->name);
|
|
||||||
if (dst.name == NULL) {
|
|
||||||
talloc_free(dst.value.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy a DN but replace the old with the new base DN. */
|
|
||||||
static struct ldb_dn *ldb_dn_rebase(void *mem_ctx, const struct ldb_dn *old, const struct ldb_dn *old_base, const struct ldb_dn *new_base)
|
|
||||||
{
|
|
||||||
struct ldb_dn *new;
|
|
||||||
int i, offset;
|
|
||||||
|
|
||||||
/* Perhaps we don't need to rebase at all? */
|
|
||||||
if (!old_base || !new_base) {
|
|
||||||
return ldb_dn_copy(mem_ctx, old);
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = old->comp_num - old_base->comp_num;
|
|
||||||
new = ldb_dn_copy_partial(mem_ctx, new_base, offset + new_base->comp_num);
|
|
||||||
for (i = 0; i < offset; i++) {
|
|
||||||
new->components[i] = ldb_dn_copy_component(new->components, &(old->components[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy a DN with the base DN of the local partition. */
|
/* Copy a DN with the base DN of the local partition. */
|
||||||
static struct ldb_dn *ldb_dn_rebase_local(void *mem_ctx, const struct ldb_map_context *data, const struct ldb_dn *dn)
|
static struct ldb_dn *ldb_dn_rebase_local(void *mem_ctx, const struct ldb_map_context *data, const struct ldb_dn *dn)
|
||||||
{
|
{
|
||||||
return ldb_dn_rebase(mem_ctx, dn, data->remote_base_dn, data->local_base_dn);
|
return ldb_dn_copy_rebase(mem_ctx, dn, data->remote_base_dn, data->local_base_dn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy a DN with the base DN of the remote partition. */
|
/* Copy a DN with the base DN of the remote partition. */
|
||||||
static struct ldb_dn *ldb_dn_rebase_remote(void *mem_ctx, const struct ldb_map_context *data, const struct ldb_dn *dn)
|
static struct ldb_dn *ldb_dn_rebase_remote(void *mem_ctx, const struct ldb_map_context *data, const struct ldb_dn *dn)
|
||||||
{
|
{
|
||||||
return ldb_dn_rebase(mem_ctx, dn, data->local_base_dn, data->remote_base_dn);
|
return ldb_dn_copy_rebase(mem_ctx, dn, data->local_base_dn, data->remote_base_dn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run a request and make sure it targets the remote partition. */
|
/* Run a request and make sure it targets the remote partition. */
|
||||||
@ -460,23 +416,23 @@ int map_attrs_merge(struct ldb_module *module, void *mem_ctx, const char ***attr
|
|||||||
* ================== */
|
* ================== */
|
||||||
|
|
||||||
/* Map an ldb value into the remote partition. */
|
/* Map an ldb value into the remote partition. */
|
||||||
struct ldb_val ldb_val_map_local(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, struct ldb_val val)
|
struct ldb_val ldb_val_map_local(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, const struct ldb_val *val)
|
||||||
{
|
{
|
||||||
if (map && (map->type == MAP_CONVERT) && (map->u.convert.convert_local)) {
|
if (map && (map->type == MAP_CONVERT) && (map->u.convert.convert_local)) {
|
||||||
return map->u.convert.convert_local(module, mem_ctx, &val);
|
return map->u.convert.convert_local(module, mem_ctx, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ldb_val_dup(mem_ctx, &val);
|
return ldb_val_dup(mem_ctx, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Map an ldb value back into the local partition. */
|
/* Map an ldb value back into the local partition. */
|
||||||
struct ldb_val ldb_val_map_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, struct ldb_val val)
|
struct ldb_val ldb_val_map_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, const struct ldb_val *val)
|
||||||
{
|
{
|
||||||
if (map && (map->type == MAP_CONVERT) && (map->u.convert.convert_remote)) {
|
if (map && (map->type == MAP_CONVERT) && (map->u.convert.convert_remote)) {
|
||||||
return map->u.convert.convert_remote(module, mem_ctx, &val);
|
return map->u.convert.convert_remote(module, mem_ctx, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ldb_val_dup(mem_ctx, &val);
|
return ldb_val_dup(mem_ctx, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -500,10 +456,11 @@ struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, const
|
|||||||
{
|
{
|
||||||
const struct ldb_map_context *data = map_get_context(module);
|
const struct ldb_map_context *data = map_get_context(module);
|
||||||
struct ldb_dn *newdn;
|
struct ldb_dn *newdn;
|
||||||
struct ldb_dn_component *old, *new;
|
|
||||||
const struct ldb_map_attribute *map;
|
const struct ldb_map_attribute *map;
|
||||||
enum ldb_map_attr_type map_type;
|
enum ldb_map_attr_type map_type;
|
||||||
int i;
|
const char *name;
|
||||||
|
struct ldb_val value;
|
||||||
|
int i, ret;
|
||||||
|
|
||||||
if (dn == NULL) {
|
if (dn == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -516,10 +473,8 @@ struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* For each RDN, map the component name and possibly the value */
|
/* For each RDN, map the component name and possibly the value */
|
||||||
for (i = 0; i < newdn->comp_num; i++) {
|
for (i = 0; i < ldb_dn_get_comp_num(newdn); i++) {
|
||||||
old = &dn->components[i];
|
map = map_attr_find_local(data, ldb_dn_get_component_name(dn, i));
|
||||||
new = &newdn->components[i];
|
|
||||||
map = map_attr_find_local(data, old->name);
|
|
||||||
|
|
||||||
/* Unknown attribute - leave this RDN as is and hope the best... */
|
/* Unknown attribute - leave this RDN as is and hope the best... */
|
||||||
if (map == NULL) {
|
if (map == NULL) {
|
||||||
@ -533,21 +488,30 @@ struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, const
|
|||||||
case MAP_GENERATE:
|
case MAP_GENERATE:
|
||||||
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
|
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
|
||||||
"MAP_IGNORE/MAP_GENERATE attribute '%s' "
|
"MAP_IGNORE/MAP_GENERATE attribute '%s' "
|
||||||
"used in DN!\n", old->name);
|
"used in DN!\n", ldb_dn_get_component_name(dn, i));
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
case MAP_CONVERT:
|
case MAP_CONVERT:
|
||||||
if (map->u.convert.convert_local == NULL) {
|
if (map->u.convert.convert_local == NULL) {
|
||||||
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
|
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
|
||||||
"'convert_local' not set for attribute '%s' "
|
"'convert_local' not set for attribute '%s' "
|
||||||
"used in DN!\n", old->name);
|
"used in DN!\n", ldb_dn_get_component_name(dn, i));
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case MAP_KEEP:
|
case MAP_KEEP:
|
||||||
case MAP_RENAME:
|
case MAP_RENAME:
|
||||||
new->name = discard_const_p(char, map_attr_map_local(newdn->components, map, old->name));
|
name = map_attr_map_local(newdn, map, ldb_dn_get_component_name(dn, i));
|
||||||
new->value = ldb_val_map_local(module, newdn->components, map, old->value);
|
if (name == NULL) goto failed;
|
||||||
|
|
||||||
|
value = ldb_val_map_local(module, newdn, map, ldb_dn_get_component_val(dn, i));
|
||||||
|
if (value.data == NULL) goto failed;
|
||||||
|
|
||||||
|
ret = ldb_dn_set_component(newdn, i, name, value);
|
||||||
|
if (ret != LDB_SUCCESS) {
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -564,10 +528,11 @@ struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, const
|
|||||||
{
|
{
|
||||||
const struct ldb_map_context *data = map_get_context(module);
|
const struct ldb_map_context *data = map_get_context(module);
|
||||||
struct ldb_dn *newdn;
|
struct ldb_dn *newdn;
|
||||||
struct ldb_dn_component *old, *new;
|
|
||||||
const struct ldb_map_attribute *map;
|
const struct ldb_map_attribute *map;
|
||||||
enum ldb_map_attr_type map_type;
|
enum ldb_map_attr_type map_type;
|
||||||
int i;
|
const char *name;
|
||||||
|
struct ldb_val value;
|
||||||
|
int i, ret;
|
||||||
|
|
||||||
if (dn == NULL) {
|
if (dn == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -580,10 +545,8 @@ struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* For each RDN, map the component name and possibly the value */
|
/* For each RDN, map the component name and possibly the value */
|
||||||
for (i = 0; i < newdn->comp_num; i++) {
|
for (i = 0; i < ldb_dn_get_comp_num(newdn); i++) {
|
||||||
old = &dn->components[i];
|
map = map_attr_find_remote(data, ldb_dn_get_component_name(dn, i));
|
||||||
new = &newdn->components[i];
|
|
||||||
map = map_attr_find_remote(data, old->name);
|
|
||||||
|
|
||||||
/* Unknown attribute - leave this RDN as is and hope the best... */
|
/* Unknown attribute - leave this RDN as is and hope the best... */
|
||||||
if (map == NULL) {
|
if (map == NULL) {
|
||||||
@ -597,21 +560,30 @@ struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, const
|
|||||||
case MAP_GENERATE:
|
case MAP_GENERATE:
|
||||||
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
|
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
|
||||||
"MAP_IGNORE/MAP_GENERATE attribute '%s' "
|
"MAP_IGNORE/MAP_GENERATE attribute '%s' "
|
||||||
"used in DN!\n", old->name);
|
"used in DN!\n", ldb_dn_get_component_name(dn, i));
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
case MAP_CONVERT:
|
case MAP_CONVERT:
|
||||||
if (map->u.convert.convert_remote == NULL) {
|
if (map->u.convert.convert_remote == NULL) {
|
||||||
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
|
ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: "
|
||||||
"'convert_remote' not set for attribute '%s' "
|
"'convert_remote' not set for attribute '%s' "
|
||||||
"used in DN!\n", old->name);
|
"used in DN!\n", ldb_dn_get_component_name(dn, i));
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case MAP_KEEP:
|
case MAP_KEEP:
|
||||||
case MAP_RENAME:
|
case MAP_RENAME:
|
||||||
new->name = discard_const_p(char, map_attr_map_remote(newdn->components, map, old->name));
|
name = map_attr_map_remote(newdn, map, ldb_dn_get_component_name(dn, i));
|
||||||
new->value = ldb_val_map_remote(module, newdn->components, map, old->value);
|
if (name == NULL) goto failed;
|
||||||
|
|
||||||
|
value = ldb_val_map_remote(module, newdn, map, ldb_dn_get_component_val(dn, i));
|
||||||
|
if (value.data == NULL) goto failed;
|
||||||
|
|
||||||
|
ret = ldb_dn_set_component(newdn, i, name, value);
|
||||||
|
if (ret != LDB_SUCCESS) {
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ static struct ldb_message_element *ldb_msg_el_map_local(struct ldb_module *modul
|
|||||||
el->name = map_attr_map_local(el, map, old->name);
|
el->name = map_attr_map_local(el, map, old->name);
|
||||||
|
|
||||||
for (i = 0; i < el->num_values; i++) {
|
for (i = 0; i < el->num_values; i++) {
|
||||||
el->values[i] = ldb_val_map_local(module, el->values, map, old->values[i]);
|
el->values[i] = ldb_val_map_local(module, el->values, map, &old->values[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return el;
|
return el;
|
||||||
|
@ -235,7 +235,7 @@ static struct ldb_message_element *ldb_msg_el_map_remote(struct ldb_module *modu
|
|||||||
el->name = map_attr_map_remote(el, map, old->name);
|
el->name = map_attr_map_remote(el, map, old->name);
|
||||||
|
|
||||||
for (i = 0; i < el->num_values; i++) {
|
for (i = 0; i < el->num_values; i++) {
|
||||||
el->values[i] = ldb_val_map_remote(module, el->values, map, old->values[i]);
|
el->values[i] = ldb_val_map_remote(module, el->values, map, &old->values[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return el;
|
return el;
|
||||||
@ -729,21 +729,21 @@ int map_subtree_collect_remote_simple(struct ldb_module *module, void *mem_ctx,
|
|||||||
*new = NULL;
|
*new = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*(*new)->u.substring.chunks[i] = ldb_val_map_local(module, *new, map, *tree->u.substring.chunks[i]);
|
*(*new)->u.substring.chunks[i] = ldb_val_map_local(module, *new, map, tree->u.substring.chunks[i]);
|
||||||
(*new)->u.substring.chunks[i+1] = NULL;
|
(*new)->u.substring.chunks[i+1] = NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LDB_OP_EQUALITY:
|
case LDB_OP_EQUALITY:
|
||||||
(*new)->u.equality.value = ldb_val_map_local(module, *new, map, tree->u.equality.value);
|
(*new)->u.equality.value = ldb_val_map_local(module, *new, map, &tree->u.equality.value);
|
||||||
break;
|
break;
|
||||||
case LDB_OP_LESS:
|
case LDB_OP_LESS:
|
||||||
case LDB_OP_GREATER:
|
case LDB_OP_GREATER:
|
||||||
case LDB_OP_APPROX:
|
case LDB_OP_APPROX:
|
||||||
(*new)->u.comparison.value = ldb_val_map_local(module, *new, map, tree->u.comparison.value);
|
(*new)->u.comparison.value = ldb_val_map_local(module, *new, map, &tree->u.comparison.value);
|
||||||
break;
|
break;
|
||||||
case LDB_OP_EXTENDED:
|
case LDB_OP_EXTENDED:
|
||||||
(*new)->u.extended.value = ldb_val_map_local(module, *new, map, tree->u.extended.value);
|
(*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);
|
(*new)->u.extended.rule_id = talloc_strdup(*new, tree->u.extended.rule_id);
|
||||||
break;
|
break;
|
||||||
default: /* unknown kind of simple subtree */
|
default: /* unknown kind of simple subtree */
|
||||||
|
@ -77,8 +77,8 @@ const char *map_attr_map_local(void *mem_ctx, const struct ldb_map_attribute *ma
|
|||||||
const char *map_attr_map_remote(void *mem_ctx, const struct ldb_map_attribute *map, const char *attr);
|
const char *map_attr_map_remote(void *mem_ctx, const struct ldb_map_attribute *map, const char *attr);
|
||||||
int map_attrs_merge(struct ldb_module *module, void *mem_ctx, const char ***attrs, const char * const *more_attrs);
|
int map_attrs_merge(struct ldb_module *module, void *mem_ctx, const char ***attrs, const char * const *more_attrs);
|
||||||
|
|
||||||
struct ldb_val ldb_val_map_local(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, struct ldb_val val);
|
struct ldb_val ldb_val_map_local(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, const struct ldb_val *val);
|
||||||
struct ldb_val ldb_val_map_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, struct ldb_val val);
|
struct ldb_val ldb_val_map_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_map_attribute *map, const struct ldb_val *val);
|
||||||
|
|
||||||
struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, const struct ldb_dn *dn);
|
struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, const struct ldb_dn *dn);
|
||||||
struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_dn *dn);
|
struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_dn *dn);
|
||||||
|
@ -58,7 +58,8 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req)
|
|||||||
struct ldb_request *down_req;
|
struct ldb_request *down_req;
|
||||||
struct ldb_message *msg;
|
struct ldb_message *msg;
|
||||||
struct ldb_message_element *attribute;
|
struct ldb_message_element *attribute;
|
||||||
struct ldb_dn_component *rdn;
|
const char *rdn_name;
|
||||||
|
struct ldb_val rdn_val;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
|
||||||
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_add_record\n");
|
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_add_record\n");
|
||||||
@ -80,43 +81,45 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req)
|
|||||||
return LDB_ERR_OPERATIONS_ERROR;
|
return LDB_ERR_OPERATIONS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
rdn = ldb_dn_get_rdn(msg, msg->dn);
|
rdn_name = ldb_dn_get_rdn_name(msg->dn);
|
||||||
if (rdn == NULL) {
|
if (rdn_name == NULL) {
|
||||||
talloc_free(down_req);
|
talloc_free(down_req);
|
||||||
return LDB_ERR_OPERATIONS_ERROR;
|
return LDB_ERR_OPERATIONS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rdn_val = ldb_val_dup(msg, ldb_dn_get_rdn_val(msg->dn));
|
||||||
|
|
||||||
/* Perhaps someone above us tried to set this? */
|
/* Perhaps someone above us tried to set this? */
|
||||||
if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) {
|
if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) {
|
||||||
attribute->num_values = 0;
|
attribute->num_values = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ldb_msg_add_value(msg, "name", &rdn->value, NULL) != 0) {
|
if (ldb_msg_add_value(msg, "name", &rdn_val, NULL) != 0) {
|
||||||
talloc_free(down_req);
|
talloc_free(down_req);
|
||||||
return LDB_ERR_OPERATIONS_ERROR;
|
return LDB_ERR_OPERATIONS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
attribute = rdn_name_find_attribute(msg, rdn->name);
|
attribute = rdn_name_find_attribute(msg, rdn_name);
|
||||||
|
|
||||||
if (!attribute) {
|
if (!attribute) {
|
||||||
if (ldb_msg_add_value(msg, rdn->name, &rdn->value, NULL) != 0) {
|
if (ldb_msg_add_value(msg, rdn_name, &rdn_val, NULL) != 0) {
|
||||||
talloc_free(down_req);
|
talloc_free(down_req);
|
||||||
return LDB_ERR_OPERATIONS_ERROR;
|
return LDB_ERR_OPERATIONS_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const struct ldb_attrib_handler *handler = ldb_attrib_handler(module->ldb, rdn->name);
|
const struct ldb_attrib_handler *handler = ldb_attrib_handler(module->ldb, rdn_name);
|
||||||
|
|
||||||
for (i = 0; i < attribute->num_values; i++) {
|
for (i = 0; i < attribute->num_values; i++) {
|
||||||
if (handler->comparison_fn(module->ldb, msg, &rdn->value, &attribute->values[i]) == 0) {
|
if (handler->comparison_fn(module->ldb, msg, &rdn_val, &attribute->values[i]) == 0) {
|
||||||
/* overwrite so it matches in case */
|
/* overwrite so it matches in case */
|
||||||
attribute->values[i] = rdn->value;
|
attribute->values[i] = rdn_val;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i == attribute->num_values) {
|
if (i == attribute->num_values) {
|
||||||
ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
|
ldb_debug_set(module->ldb, LDB_DEBUG_FATAL,
|
||||||
"RDN mismatch on %s: %s",
|
"RDN mismatch on %s: %s (%s)",
|
||||||
ldb_dn_linearize(msg, msg->dn), rdn->name);
|
ldb_dn_linearize(msg, msg->dn), rdn_name, rdn_val.data);
|
||||||
talloc_free(down_req);
|
talloc_free(down_req);
|
||||||
return LDB_ERR_OPERATIONS_ERROR;
|
return LDB_ERR_OPERATIONS_ERROR;
|
||||||
}
|
}
|
||||||
@ -190,16 +193,12 @@ static int rdn_name_rename(struct ldb_module *module, struct ldb_request *req)
|
|||||||
static int rdn_name_rename_do_mod(struct ldb_handle *h) {
|
static int rdn_name_rename_do_mod(struct ldb_handle *h) {
|
||||||
|
|
||||||
struct rename_context *ac;
|
struct rename_context *ac;
|
||||||
struct ldb_dn_component *rdn;
|
const char *rdn_name;
|
||||||
|
struct ldb_val rdn_val;
|
||||||
struct ldb_message *msg;
|
struct ldb_message *msg;
|
||||||
|
|
||||||
ac = talloc_get_type(h->private_data, struct rename_context);
|
ac = talloc_get_type(h->private_data, struct rename_context);
|
||||||
|
|
||||||
rdn = ldb_dn_get_rdn(ac, ac->orig_req->op.rename.newdn);
|
|
||||||
if (rdn == NULL) {
|
|
||||||
return LDB_ERR_OPERATIONS_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
ac->mod_req = talloc_zero(ac, struct ldb_request);
|
ac->mod_req = talloc_zero(ac, struct ldb_request);
|
||||||
|
|
||||||
ac->mod_req->operation = LDB_MODIFY;
|
ac->mod_req->operation = LDB_MODIFY;
|
||||||
@ -213,16 +212,23 @@ static int rdn_name_rename_do_mod(struct ldb_handle *h) {
|
|||||||
return LDB_ERR_OPERATIONS_ERROR;
|
return LDB_ERR_OPERATIONS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ldb_msg_add_empty(msg, rdn->name, LDB_FLAG_MOD_REPLACE, NULL) != 0) {
|
rdn_name = ldb_dn_get_rdn_name(ac->orig_req->op.rename.newdn);
|
||||||
|
if (rdn_name == NULL) {
|
||||||
return LDB_ERR_OPERATIONS_ERROR;
|
return LDB_ERR_OPERATIONS_ERROR;
|
||||||
}
|
}
|
||||||
if (ldb_msg_add_value(msg, rdn->name, &rdn->value, NULL) != 0) {
|
|
||||||
|
rdn_val = ldb_val_dup(msg, ldb_dn_get_rdn_val(ac->orig_req->op.rename.newdn));
|
||||||
|
|
||||||
|
if (ldb_msg_add_empty(msg, rdn_name, LDB_FLAG_MOD_REPLACE, NULL) != 0) {
|
||||||
|
return LDB_ERR_OPERATIONS_ERROR;
|
||||||
|
}
|
||||||
|
if (ldb_msg_add_value(msg, rdn_name, &rdn_val, NULL) != 0) {
|
||||||
return LDB_ERR_OPERATIONS_ERROR;
|
return LDB_ERR_OPERATIONS_ERROR;
|
||||||
}
|
}
|
||||||
if (ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_REPLACE, NULL) != 0) {
|
if (ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_REPLACE, NULL) != 0) {
|
||||||
return LDB_ERR_OPERATIONS_ERROR;
|
return LDB_ERR_OPERATIONS_ERROR;
|
||||||
}
|
}
|
||||||
if (ldb_msg_add_value(msg, "name", &rdn->value, NULL) != 0) {
|
if (ldb_msg_add_value(msg, "name", &rdn_val, NULL) != 0) {
|
||||||
return LDB_ERR_OPERATIONS_ERROR;
|
return LDB_ERR_OPERATIONS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,9 +300,9 @@ static int ldif_canonicalise_objectCategory(struct ldb_context *ldb, void *mem_c
|
|||||||
dn1 = ldb_dn_explode(mem_ctx, (char *)in->data);
|
dn1 = ldb_dn_explode(mem_ctx, (char *)in->data);
|
||||||
if (dn1 == NULL) {
|
if (dn1 == NULL) {
|
||||||
oc1 = talloc_strndup(mem_ctx, (char *)in->data, in->length);
|
oc1 = talloc_strndup(mem_ctx, (char *)in->data, in->length);
|
||||||
} else if (dn1->comp_num >= 1 && strcasecmp(dn1->components[0].name, "cn") == 0) {
|
} else if (ldb_dn_get_comp_num(dn1) >= 1 && strcasecmp(ldb_dn_get_rdn_name(dn1), "cn") == 0) {
|
||||||
oc1 = talloc_strndup(mem_ctx, (char *)dn1->components[0].value.data,
|
const struct ldb_val *val = ldb_dn_get_rdn_val(dn1);
|
||||||
dn1->components[0].value.length);
|
oc1 = talloc_strndup(mem_ctx, (char *)val->data, val->length);
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -325,9 +325,9 @@ static int ldif_comparison_objectCategory(struct ldb_context *ldb, void *mem_ctx
|
|||||||
dn1 = ldb_dn_explode(mem_ctx, (char *)v1->data);
|
dn1 = ldb_dn_explode(mem_ctx, (char *)v1->data);
|
||||||
if (dn1 == NULL) {
|
if (dn1 == NULL) {
|
||||||
oc1 = talloc_strndup(mem_ctx, (char *)v1->data, v1->length);
|
oc1 = talloc_strndup(mem_ctx, (char *)v1->data, v1->length);
|
||||||
} else if (dn1->comp_num >= 1 && strcasecmp(dn1->components[0].name, "cn") == 0) {
|
} else if (ldb_dn_get_comp_num(dn1) >= 1 && strcasecmp(ldb_dn_get_rdn_name(dn1), "cn") == 0) {
|
||||||
oc1 = talloc_strndup(mem_ctx, (char *)dn1->components[0].value.data,
|
const struct ldb_val *val = ldb_dn_get_rdn_val(dn1);
|
||||||
dn1->components[0].value.length);
|
oc1 = talloc_strndup(mem_ctx, (char *)val->data, val->length);
|
||||||
} else {
|
} else {
|
||||||
oc1 = NULL;
|
oc1 = NULL;
|
||||||
}
|
}
|
||||||
@ -335,9 +335,9 @@ static int ldif_comparison_objectCategory(struct ldb_context *ldb, void *mem_ctx
|
|||||||
dn2 = ldb_dn_explode(mem_ctx, (char *)v2->data);
|
dn2 = ldb_dn_explode(mem_ctx, (char *)v2->data);
|
||||||
if (dn2 == NULL) {
|
if (dn2 == NULL) {
|
||||||
oc2 = talloc_strndup(mem_ctx, (char *)v2->data, v2->length);
|
oc2 = talloc_strndup(mem_ctx, (char *)v2->data, v2->length);
|
||||||
} else if (dn2->comp_num >= 2 && strcasecmp(dn2->components[0].name, "cn") == 0) {
|
} else if (ldb_dn_get_comp_num(dn2) >= 2 && strcasecmp(ldb_dn_get_rdn_name(dn2), "cn") == 0) {
|
||||||
oc2 = talloc_strndup(mem_ctx, (char *)dn2->components[0].value.data,
|
const struct ldb_val *val = ldb_dn_get_rdn_val(dn2);
|
||||||
dn2->components[0].value.length);
|
oc2 = talloc_strndup(mem_ctx, (char *)val->data, val->length);
|
||||||
} else {
|
} else {
|
||||||
oc2 = NULL;
|
oc2 = NULL;
|
||||||
}
|
}
|
||||||
|
@ -179,6 +179,7 @@ static NTSTATUS winsdb_nbt_name(TALLOC_CTX *mem_ctx, struct ldb_dn *dn, struct n
|
|||||||
{
|
{
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
struct nbt_name *name;
|
struct nbt_name *name;
|
||||||
|
unsigned int comp_num;
|
||||||
uint32_t cur = 0;
|
uint32_t cur = 0;
|
||||||
|
|
||||||
name = talloc(mem_ctx, struct nbt_name);
|
name = talloc(mem_ctx, struct nbt_name);
|
||||||
@ -187,20 +188,22 @@ static NTSTATUS winsdb_nbt_name(TALLOC_CTX *mem_ctx, struct ldb_dn *dn, struct n
|
|||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dn->comp_num > 3) {
|
comp_num = ldb_dn_get_comp_num(dn);
|
||||||
|
|
||||||
|
if (comp_num > 3) {
|
||||||
status = NT_STATUS_INTERNAL_DB_CORRUPTION;
|
status = NT_STATUS_INTERNAL_DB_CORRUPTION;
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dn->comp_num > cur && strcasecmp("scope", dn->components[cur].name) == 0) {
|
if (comp_num > cur && strcasecmp("scope", ldb_dn_get_component_name(dn, cur)) == 0) {
|
||||||
name->scope = (const char *)talloc_steal(name, dn->components[cur].value.data);
|
name->scope = (const char *)talloc_strdup(name, (char *)ldb_dn_get_component_val(dn, cur)->data);
|
||||||
cur++;
|
cur++;
|
||||||
} else {
|
} else {
|
||||||
name->scope = NULL;
|
name->scope = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dn->comp_num > cur && strcasecmp("name", dn->components[cur].name) == 0) {
|
if (comp_num > cur && strcasecmp("name", ldb_dn_get_component_name(dn, cur)) == 0) {
|
||||||
name->name = (const char *)talloc_steal(name, dn->components[cur].value.data);
|
name->name = (const char *)talloc_strdup(name, (char *)ldb_dn_get_component_val(dn, cur)->data);
|
||||||
cur++;
|
cur++;
|
||||||
} else {
|
} else {
|
||||||
name->name = talloc_strdup(name, "");
|
name->name = talloc_strdup(name, "");
|
||||||
@ -210,8 +213,8 @@ static NTSTATUS winsdb_nbt_name(TALLOC_CTX *mem_ctx, struct ldb_dn *dn, struct n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dn->comp_num > cur && strcasecmp("type", dn->components[cur].name) == 0) {
|
if (comp_num > cur && strcasecmp("type", ldb_dn_get_component_name(dn, cur)) == 0) {
|
||||||
name->type = strtoul((char *)dn->components[cur].value.data, NULL, 0);
|
name->type = strtoul((char *)ldb_dn_get_component_val(dn, cur)->data, NULL, 0);
|
||||||
cur++;
|
cur++;
|
||||||
} else {
|
} else {
|
||||||
status = NT_STATUS_INTERNAL_DB_CORRUPTION;
|
status = NT_STATUS_INTERNAL_DB_CORRUPTION;
|
||||||
|
Reference in New Issue
Block a user