summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/modules/timestamps.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2005-07-21 07:59:01 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:29:52 -0500
commit2a0cf520e3255d8e1bdec1bedd710489619de614 (patch)
treea8d22ca77e1496ed94b611a29e58a7bd00cdc39e /source4/lib/ldb/modules/timestamps.c
parentc7204bd9856dd4a58c420a590f1b2abab8aaa70e (diff)
downloadsamba-2a0cf520e3255d8e1bdec1bedd710489619de614.tar.gz
samba-2a0cf520e3255d8e1bdec1bedd710489619de614.tar.bz2
samba-2a0cf520e3255d8e1bdec1bedd710489619de614.zip
r8667: Further simply the provision script, by removing the 'name' attribute.
This is now calculated on the fly for every add and modify. Andrew Bartlett (This used to be commit ed1f2e029c840d2b3ecb49dbe6e8cd67588eeeed)
Diffstat (limited to 'source4/lib/ldb/modules/timestamps.c')
-rw-r--r--source4/lib/ldb/modules/timestamps.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/source4/lib/ldb/modules/timestamps.c b/source4/lib/ldb/modules/timestamps.c
index c1db85a284..b067d8e8d6 100644
--- a/source4/lib/ldb/modules/timestamps.c
+++ b/source4/lib/ldb/modules/timestamps.c
@@ -60,8 +60,8 @@ static int timestamps_search_bytree(struct ldb_module *module, const char *base,
static int add_time_element(struct ldb_module *module, struct ldb_message *msg,
const char *attr_name, const char *time_string, unsigned int flags)
{
- struct ldb_val *values;
- char *name, *timestr;
+ struct ldb_message_element *attribute = NULL;
+
int i;
for (i = 0; i < msg->num_elements; i++) {
@@ -70,23 +70,22 @@ static int add_time_element(struct ldb_module *module, struct ldb_message *msg,
}
}
- msg->elements = talloc_realloc(msg, msg->elements,
- struct ldb_message_element, msg->num_elements + 1);
- name = talloc_strdup(msg->elements, attr_name);
- timestr = talloc_strdup(msg->elements, time_string);
- values = talloc(msg->elements, struct ldb_val);
- if (!msg->elements || !name || !timestr || !values) {
+ if (ldb_msg_add_string(module->ldb, msg, attr_name, time_string) != 0) {
return -1;
}
- msg->elements[msg->num_elements].name = name;
- msg->elements[msg->num_elements].flags = flags;
- msg->elements[msg->num_elements].num_values = 1;
- msg->elements[msg->num_elements].values = values;
- msg->elements[msg->num_elements].values[0].data = timestr;
- msg->elements[msg->num_elements].values[0].length = strlen(timestr);
+ for (i = 0; i < msg->num_elements; i++) {
+ if (ldb_attr_cmp(attr_name, msg->elements[i].name) == 0) {
+ attribute = &msg->elements[i];
+ break;
+ }
+ }
- msg->num_elements += 1;
+ if (!attribute) {
+ return -1;
+ }
+
+ attribute->flags = flags;
return 0;
}
@@ -196,12 +195,8 @@ static int timestamps_modify_record(struct ldb_module *module, const struct ldb_
add_time_element(module, msg2, "modifyTimestamp", timestr, LDB_FLAG_MOD_REPLACE);
add_time_element(module, msg2, "whenChanged", timestr, LDB_FLAG_MOD_REPLACE);
- if (msg2) {
- ret = ldb_next_modify_record(module, msg2);
- talloc_free(msg2);
- } else {
- ret = ldb_next_modify_record(module, msg);
- }
+ ret = ldb_next_modify_record(module, msg2);
+ talloc_free(msg2);
return ret;
}