1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-29 11:21:54 +03:00

r19491: backport changes from samba4

(This used to be commit aa464c9fda)
This commit is contained in:
Simo Sorce 2006-10-25 02:06:05 +00:00 committed by Gerald (Jerry) Carter
parent e6b56f9f0c
commit 151237477b
8 changed files with 44 additions and 35 deletions

View File

@ -613,7 +613,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
} }
if (empty) { if (empty) {
if (ldb_msg_add_empty(msg, (char *)value.data, flags) != 0) { if (ldb_msg_add_empty(msg, (char *)value.data, flags, NULL) != 0) {
goto failed; goto failed;
} }
continue; continue;

View File

@ -119,7 +119,10 @@ struct ldb_val ldb_val_dup(void *mem_ctx, const struct ldb_val *v)
/* /*
add an empty element to a message add an empty element to a message
*/ */
int ldb_msg_add_empty(struct ldb_message *msg, const char *attr_name, int flags) int ldb_msg_add_empty(struct ldb_message *msg,
const char *attr_name,
int flags,
struct ldb_message_element **return_el)
{ {
struct ldb_message_element *els; struct ldb_message_element *els;
@ -146,6 +149,10 @@ int ldb_msg_add_empty(struct ldb_message *msg, const char *attr_name, int flags)
msg->elements = els; msg->elements = els;
msg->num_elements++; msg->num_elements++;
if (return_el) {
*return_el = &els[msg->num_elements-1];
}
return LDB_SUCCESS; return LDB_SUCCESS;
} }
@ -156,7 +163,7 @@ int ldb_msg_add(struct ldb_message *msg,
const struct ldb_message_element *el, const struct ldb_message_element *el,
int flags) int flags)
{ {
if (ldb_msg_add_empty(msg, el->name, flags) != 0) { if (ldb_msg_add_empty(msg, el->name, flags, NULL) != 0) {
return LDB_ERR_OPERATIONS_ERROR; return LDB_ERR_OPERATIONS_ERROR;
} }
@ -171,18 +178,19 @@ int ldb_msg_add(struct ldb_message *msg,
*/ */
int ldb_msg_add_value(struct ldb_message *msg, int ldb_msg_add_value(struct ldb_message *msg,
const char *attr_name, const char *attr_name,
const struct ldb_val *val) const struct ldb_val *val,
struct ldb_message_element **return_el)
{ {
struct ldb_message_element *el; struct ldb_message_element *el;
struct ldb_val *vals; struct ldb_val *vals;
int ret;
el = ldb_msg_find_element(msg, attr_name); el = ldb_msg_find_element(msg, attr_name);
if (!el) { if (!el) {
ldb_msg_add_empty(msg, attr_name, 0); ret = ldb_msg_add_empty(msg, attr_name, 0, &el);
el = ldb_msg_find_element(msg, attr_name); if (ret != LDB_SUCCESS) {
} return ret;
if (!el) { }
return LDB_ERR_OPERATIONS_ERROR;
} }
vals = talloc_realloc(msg, el->values, struct ldb_val, el->num_values+1); vals = talloc_realloc(msg, el->values, struct ldb_val, el->num_values+1);
@ -194,6 +202,10 @@ int ldb_msg_add_value(struct ldb_message *msg,
el->values[el->num_values] = *val; el->values[el->num_values] = *val;
el->num_values++; el->num_values++;
if (return_el) {
*return_el = el;
}
return LDB_SUCCESS; return LDB_SUCCESS;
} }
@ -206,12 +218,10 @@ int ldb_msg_add_steal_value(struct ldb_message *msg,
struct ldb_val *val) struct ldb_val *val)
{ {
int ret; int ret;
ret = ldb_msg_add_value(msg, attr_name, val); struct ldb_message_element *el;
ret = ldb_msg_add_value(msg, attr_name, val, &el);
if (ret == LDB_SUCCESS) { if (ret == LDB_SUCCESS) {
struct ldb_message_element *el;
if (!(el = ldb_msg_find_element(msg, attr_name))) {
return LDB_ERR_OPERATIONS_ERROR;
}
talloc_steal(el->values, val->data); talloc_steal(el->values, val->data);
} }
return ret; return ret;
@ -234,7 +244,7 @@ int ldb_msg_add_string(struct ldb_message *msg,
return LDB_SUCCESS; return LDB_SUCCESS;
} }
return ldb_msg_add_value(msg, attr_name, &val); return ldb_msg_add_value(msg, attr_name, &val, NULL);
} }
/* /*
@ -578,7 +588,7 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
if (!el) { if (!el) {
if (ldb_msg_add_empty(mod, if (ldb_msg_add_empty(mod,
msg1->elements[i].name, msg1->elements[i].name,
LDB_FLAG_MOD_DELETE) != 0) { LDB_FLAG_MOD_DELETE, NULL) != 0) {
return NULL; return NULL;
} }
} }

View File

@ -1227,7 +1227,10 @@ struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el,
/** /**
add a new empty element to a ldb_message add a new empty element to a ldb_message
*/ */
int ldb_msg_add_empty(struct ldb_message *msg, const char *attr_name, int flags); int ldb_msg_add_empty(struct ldb_message *msg,
const char *attr_name,
int flags,
struct ldb_message_element **return_el);
/** /**
add a element to a ldb_message add a element to a ldb_message
@ -1237,7 +1240,8 @@ int ldb_msg_add(struct ldb_message *msg,
int flags); int flags);
int ldb_msg_add_value(struct ldb_message *msg, int ldb_msg_add_value(struct ldb_message *msg,
const char *attr_name, const char *attr_name,
const struct ldb_val *val); const struct ldb_val *val,
struct ldb_message_element **return_el);
int ldb_msg_add_steal_value(struct ldb_message *msg, int ldb_msg_add_steal_value(struct ldb_message *msg,
const char *attr_name, const char *attr_name,
struct ldb_val *val); struct ldb_val *val);

View File

@ -964,7 +964,7 @@ struct ldb_request *map_build_fixup_req(struct map_context *ac, const struct ldb
if (dn == NULL) { if (dn == NULL) {
goto failed; goto failed;
} }
if (ldb_msg_add_empty(msg, IS_MAPPED, LDB_FLAG_MOD_REPLACE) != 0) { if (ldb_msg_add_empty(msg, IS_MAPPED, LDB_FLAG_MOD_REPLACE, NULL) != 0) {
goto failed; goto failed;
} }
if (ldb_msg_add_string(msg, IS_MAPPED, dn) != 0) { if (ldb_msg_add_string(msg, IS_MAPPED, dn) != 0) {

View File

@ -345,7 +345,7 @@ int map_modify_do_local(struct ldb_handle *handle)
/* Add local 'IS_MAPPED' */ /* Add local 'IS_MAPPED' */
/* TODO: use GUIDs here instead */ /* TODO: use GUIDs here instead */
dn = ldb_dn_linearize(msg, ac->remote_req->op.mod.message->dn); dn = ldb_dn_linearize(msg, ac->remote_req->op.mod.message->dn);
if (ldb_msg_add_empty(msg, IS_MAPPED, LDB_FLAG_MOD_ADD) != 0) { if (ldb_msg_add_empty(msg, IS_MAPPED, LDB_FLAG_MOD_ADD, NULL) != 0) {
return LDB_ERR_OPERATIONS_ERROR; return LDB_ERR_OPERATIONS_ERROR;
} }
if (ldb_msg_add_string(msg, IS_MAPPED, dn) != 0) { if (ldb_msg_add_string(msg, IS_MAPPED, dn) != 0) {

View File

@ -192,12 +192,7 @@ static int ldb_msg_replace(struct ldb_message *msg, const struct ldb_message_ele
/* no local result, add as new element */ /* no local result, add as new element */
if (old == NULL) { if (old == NULL) {
if (ldb_msg_add_empty(msg, el->name, 0) != 0) { if (ldb_msg_add_empty(msg, el->name, 0, &old) != 0) {
return -1;
}
old = ldb_msg_find_element(msg, el->name);
if (old == NULL) {
return -1; return -1;
} }
} }

View File

@ -250,7 +250,7 @@ static int objectclass_add(struct ldb_module *module, struct ldb_request *req)
} }
ldb_msg_remove_attr(msg, "objectClass"); ldb_msg_remove_attr(msg, "objectClass");
ret = ldb_msg_add_empty(msg, "objectClass", 0); ret = ldb_msg_add_empty(msg, "objectClass", 0, NULL);
if (ret != LDB_SUCCESS) { if (ret != LDB_SUCCESS) {
talloc_free(mem_ctx); talloc_free(mem_ctx);
@ -351,7 +351,7 @@ static int objectclass_modify(struct ldb_module *module, struct ldb_request *req
* because we need it sorted */ * because we need it sorted */
ldb_msg_remove_attr(msg, "objectClass"); ldb_msg_remove_attr(msg, "objectClass");
ret = ldb_msg_add_empty(msg, "objectClass", LDB_FLAG_MOD_REPLACE); ret = ldb_msg_add_empty(msg, "objectClass", LDB_FLAG_MOD_REPLACE, NULL);
if (ret != LDB_SUCCESS) { if (ret != LDB_SUCCESS) {
talloc_free(mem_ctx); talloc_free(mem_ctx);
@ -537,7 +537,7 @@ static int objectclass_do_mod(struct ldb_handle *h) {
* We could do a constrained add/del, but we are meant to be * We could do a constrained add/del, but we are meant to be
* in a transaction... */ * in a transaction... */
ret = ldb_msg_add_empty(msg, "objectClass", LDB_FLAG_MOD_REPLACE); ret = ldb_msg_add_empty(msg, "objectClass", LDB_FLAG_MOD_REPLACE, NULL);
if (ret != LDB_SUCCESS) { if (ret != LDB_SUCCESS) {
ldb_set_errstring(ac->module->ldb, "objectclass: could not clear objectclass in modify msg"); ldb_set_errstring(ac->module->ldb, "objectclass: could not clear objectclass in modify msg");
talloc_free(mem_ctx); talloc_free(mem_ctx);

View File

@ -91,7 +91,7 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req)
attribute->num_values = 0; attribute->num_values = 0;
} }
if (ldb_msg_add_value(msg, "name", &rdn->value) != 0) { if (ldb_msg_add_value(msg, "name", &rdn->value, NULL) != 0) {
talloc_free(down_req); talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR; return LDB_ERR_OPERATIONS_ERROR;
} }
@ -99,7 +99,7 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req)
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) != 0) { if (ldb_msg_add_value(msg, rdn->name, &rdn->value, NULL) != 0) {
talloc_free(down_req); talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR; return LDB_ERR_OPERATIONS_ERROR;
} }
@ -213,16 +213,16 @@ 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) != 0) { if (ldb_msg_add_empty(msg, rdn->name, LDB_FLAG_MOD_REPLACE, NULL) != 0) {
return LDB_ERR_OPERATIONS_ERROR; return LDB_ERR_OPERATIONS_ERROR;
} }
if (ldb_msg_add_value(msg, rdn->name, &rdn->value) != 0) { if (ldb_msg_add_value(msg, rdn->name, &rdn->value, NULL) != 0) {
return LDB_ERR_OPERATIONS_ERROR; return LDB_ERR_OPERATIONS_ERROR;
} }
if (ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_REPLACE) != 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) != 0) { if (ldb_msg_add_value(msg, "name", &rdn->value, NULL) != 0) {
return LDB_ERR_OPERATIONS_ERROR; return LDB_ERR_OPERATIONS_ERROR;
} }