1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

r17526: Move timestamp generation into the objectGUID module. It probably

needs to be renamed (operation_add?).

This allows me to match the behaviour and substitute with the
entryUUID module for remote LDAP connections.

Andrew Bartlett
This commit is contained in:
Andrew Bartlett 2006-08-14 00:59:57 +00:00 committed by Gerald (Jerry) Carter
parent af2bece4d3
commit af02b4d7c6
4 changed files with 98 additions and 43 deletions

View File

@ -50,6 +50,35 @@ static struct ldb_message_element *objectguid_find_attribute(const struct ldb_me
return NULL;
}
/*
add a time element to a record
*/
static int add_time_element(struct ldb_message *msg, const char *attr, time_t t)
{
struct ldb_message_element *el;
char *s;
if (ldb_msg_find_element(msg, attr) != NULL) {
return 0;
}
s = ldb_timestring(msg, t);
if (s == NULL) {
return -1;
}
if (ldb_msg_add_string(msg, attr, s) != 0) {
return -1;
}
el = ldb_msg_find_element(msg, attr);
/* always set as replace. This works because on add ops, the flag
is ignored */
el->flags = LDB_FLAG_MOD_REPLACE;
return 0;
}
/* add_record: add objectGUID attribute */
static int objectguid_add(struct ldb_module *module, struct ldb_request *req)
{
@ -60,6 +89,7 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req)
struct GUID guid;
NTSTATUS nt_status;
int ret;
time_t t = time(NULL);
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_add_record\n");
@ -82,6 +112,7 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req)
/* we have to copy the message as the caller might have it as a const */
down_req->op.add.message = msg = ldb_msg_copy_shallow(down_req, req->op.add.message);
if (msg == NULL) {
talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR;
}
@ -91,14 +122,70 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req)
nt_status = ndr_push_struct_blob(&v, msg, &guid,
(ndr_push_flags_fn_t)ndr_push_GUID);
if (!NT_STATUS_IS_OK(nt_status)) {
return -1;
talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR;
}
ret = ldb_msg_add_value(msg, "objectGUID", &v);
if (ret) {
talloc_free(down_req);
return ret;
}
if (add_time_element(msg, "whenCreated", t) != 0 ||
add_time_element(msg, "whenChanged", t) != 0) {
talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR;
}
ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
/* go on with the call chain */
ret = ldb_next_request(module, down_req);
/* do not free down_req as the call results may be linked to it,
* it will be freed when the upper level request get freed */
if (ret == LDB_SUCCESS) {
req->handle = down_req->handle;
}
return ret;
}
/* modify_record: update timestamps */
static int objectguid_modify(struct ldb_module *module, struct ldb_request *req)
{
struct ldb_request *down_req;
struct ldb_message *msg;
int ret;
time_t t = time(NULL);
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_add_record\n");
/* do not manipulate our control entries */
if (ldb_dn_is_special(req->op.add.message->dn)) {
return ldb_next_request(module, req);
}
down_req = talloc(req, struct ldb_request);
if (down_req == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
*down_req = *req;
/* we have to copy the message as the caller might have it as a const */
down_req->op.mod.message = msg = ldb_msg_copy_shallow(down_req, req->op.mod.message);
if (msg == NULL) {
talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR;
}
if (add_time_element(msg, "whenChanged", t) != 0) {
talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR;
}
ldb_set_timeout_from_prev_req(module->ldb, req, down_req);
/* go on with the call chain */

View File

@ -169,35 +169,6 @@ failed:
return -1;
}
/*
add a time element to a record
*/
static int add_time_element(struct ldb_message *msg, const char *attr, time_t t)
{
struct ldb_message_element *el;
char *s;
if (ldb_msg_find_element(msg, attr) != NULL) {
return 0;
}
s = ldb_timestring(msg, t);
if (s == NULL) {
return -1;
}
if (ldb_msg_add_string(msg, attr, s) != 0) {
return -1;
}
el = ldb_msg_find_element(msg, attr);
/* always set as replace. This works because on add ops, the flag
is ignored */
el->flags = LDB_FLAG_MOD_REPLACE;
return 0;
}
/*
add a uint64_t element to a record
*/
@ -348,7 +319,6 @@ static int operational_add(struct ldb_module *module, struct ldb_request *req)
{
struct ldb_request *down_req;
struct ldb_message *msg;
time_t t = time(NULL);
uint64_t seq_num;
int ret;
@ -368,11 +338,6 @@ static int operational_add(struct ldb_module *module, struct ldb_request *req)
if (msg == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
if (add_time_element(msg, "whenCreated", t) != 0 ||
add_time_element(msg, "whenChanged", t) != 0) {
talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR;
}
/* Get a sequence number from the backend */
ret = ldb_sequence_number(module->ldb, &seq_num);
@ -405,7 +370,6 @@ static int operational_modify(struct ldb_module *module, struct ldb_request *req
{
struct ldb_request *down_req;
struct ldb_message *msg;
time_t t = time(NULL);
uint64_t seq_num;
int ret;
@ -425,11 +389,6 @@ static int operational_modify(struct ldb_module *module, struct ldb_request *req
if (msg == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
if (add_time_element(msg, "whenChanged", t) != 0) {
talloc_free(down_req);
return LDB_ERR_OPERATIONS_ERROR;
}
/* Get a sequence number from the backend */
ret = ldb_sequence_number(module->ldb, &seq_num);
if (ret == LDB_SUCCESS) {

View File

@ -111,6 +111,12 @@ for (r in options) {
subobj[key] = options[r];
}
if (options["ldap-backend"] != undefined) {
subobj["LDAPMODULES"] = "entryUUID";
} else {
subobj["LDAPMODULES"] = "objectguid";
}
var blank = (options["blank"] != undefined);
var ldapbase = (options["ldap-base"] != undefined);

View File

@ -5,6 +5,9 @@ partition: ${BASEDN}:${LDAPBACKEND}
replicateEntries: @SUBCLASSES
replicateEntries: @ATTRIBUTES
replicateEntries: @INDEXLIST
modules:CN=Schema,CN=Configuration,${BASEDN}:objectguid
modules:CN=Configuration,${BASEDN}:objectguid
modules:${BASEDN}:${LDAPMODULES}
#Add modules to the list to activate them by default
#beware often order is important
@ -15,4 +18,4 @@ replicateEntries: @INDEXLIST
# - partition must be last
dn: @MODULES
@LIST: rootdse,kludge_acl,paged_results,server_sort,extended_dn,asq,samldb,objectguid,password_hash,operational,objectclass,rdn_name,partition
@LIST: rootdse,kludge_acl,paged_results,server_sort,extended_dn,asq,samldb,password_hash,operational,objectclass,rdn_name,partition