diff options
author | Andrew Bartlett <abartlet@samba.org> | 2006-09-21 06:44:12 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:19:11 -0500 |
commit | 77db3973c417cc934485dbd6bf1a8a1c84c1b30b (patch) | |
tree | 7c104933cbfc7b011f80a45394a2c9bd4a611399 /source4/lib/ldb/ldb_tdb | |
parent | f12584ccae9bdb4d3f31a719d90b881729321fab (diff) | |
download | samba-77db3973c417cc934485dbd6bf1a8a1c84c1b30b.tar.gz samba-77db3973c417cc934485dbd6bf1a8a1c84c1b30b.tar.bz2 samba-77db3973c417cc934485dbd6bf1a8a1c84c1b30b.zip |
r18781: Move the usnCreated and usnChanged handling around again.
This moves these attributes from objectguid into an optional backend
(objectguid), used by ltdb. For OpenLDAP, the entryUUID module
converts entryCSN into usnChanged.
This also changes the sequence number API, and uses 'time based'
sequence numbers, when an LDAP or similar backend is detected.
To assist this, we also store the last modified time in the TDB,
whenever we change a value.
Andrew Bartlett
(This used to be commit 72858f859483c0c532dddb2c146d6bd7b9be5072)
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_cache.c | 38 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.c | 23 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.h | 3 |
3 files changed, 53 insertions, 11 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 5634e9ad16..d6d66dd37f 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -413,8 +413,10 @@ int ltdb_increase_sequence_number(struct ldb_module *module) { struct ltdb_private *ltdb = module->private_data; struct ldb_message *msg; - struct ldb_message_element el; + struct ldb_message_element el[2]; struct ldb_val val; + struct ldb_val val_time; + time_t t = time(NULL); char *s = NULL; int ret; @@ -424,32 +426,50 @@ int ltdb_increase_sequence_number(struct ldb_module *module) return -1; } - s = talloc_asprintf(msg, "%.0f", ltdb->sequence_number+1); + s = talloc_asprintf(msg, "%llu", ltdb->sequence_number+1); if (!s) { errno = ENOMEM; return -1; } - msg->num_elements = 1; - msg->elements = ⪙ + msg->num_elements = ARRAY_SIZE(el); + msg->elements = el; msg->dn = ldb_dn_explode(msg, LTDB_BASEINFO); if (msg->dn == NULL) { talloc_free(msg); errno = ENOMEM; return -1; } - el.name = talloc_strdup(msg, LTDB_SEQUENCE_NUMBER); - if (el.name == NULL) { + el[0].name = talloc_strdup(msg, LTDB_SEQUENCE_NUMBER); + if (el[0].name == NULL) { talloc_free(msg); errno = ENOMEM; return -1; } - el.values = &val; - el.num_values = 1; - el.flags = LDB_FLAG_MOD_REPLACE; + el[0].values = &val; + el[0].num_values = 1; + el[0].flags = LDB_FLAG_MOD_REPLACE; val.data = (uint8_t *)s; val.length = strlen(s); + el[1].name = talloc_strdup(msg, LTDB_MOD_TIMESTAMP); + if (el[1].name == NULL) { + talloc_free(msg); + errno = ENOMEM; + return -1; + } + el[1].values = &val_time; + el[1].num_values = 1; + el[1].flags = LDB_FLAG_MOD_REPLACE; + + s = ldb_timestring(msg, t); + if (s == NULL) { + return -1; + } + + val_time.data = (uint8_t *)s; + val_time.length = strlen(s); + ret = ltdb_modify_internal(module, msg); talloc_free(msg); diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 5a19dd96fc..8f676654a6 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -944,6 +944,8 @@ static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *r return LDB_ERR_OPERATIONS_ERROR; } + req->op.seq_num.flags = 0; + tret = ltdb_search_dn1(module, dn, msg); if (tret != 1) { talloc_free(tmp_ctx); @@ -952,7 +954,26 @@ static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *r return LDB_SUCCESS; } - req->op.seq_num.seq_num = ldb_msg_find_attr_as_uint64(msg, LTDB_SEQUENCE_NUMBER, 0); + switch (req->op.seq_num.type) { + case LDB_SEQ_HIGHEST_SEQ: + req->op.seq_num.seq_num = ldb_msg_find_attr_as_uint64(msg, LTDB_SEQUENCE_NUMBER, 0); + break; + case LDB_SEQ_NEXT: + req->op.seq_num.seq_num = ldb_msg_find_attr_as_uint64(msg, LTDB_SEQUENCE_NUMBER, 0); + req->op.seq_num.seq_num++; + break; + case LDB_SEQ_HIGHEST_TIMESTAMP: + { + const char *date = ldb_msg_find_attr_as_string(msg, LTDB_MOD_TIMESTAMP, NULL); + if (date) { + req->op.seq_num.seq_num = ldb_string_to_time(date); + } else { + req->op.seq_num.seq_num = 0; + /* zero is as good as anything when we don't know */ + } + break; + } + } talloc_free(tmp_ctx); return LDB_SUCCESS; } diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h index fb28d00847..7b98b9ddee 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h @@ -14,7 +14,7 @@ struct ltdb_private { /* a double is used for portability and ease of string handling. It has plenty of digits of precision */ - double sequence_number; + unsigned long long sequence_number; struct ltdb_cache { struct ldb_message *baseinfo; @@ -58,6 +58,7 @@ struct ltdb_context { /* special attribute types */ #define LTDB_SEQUENCE_NUMBER "sequenceNumber" +#define LTDB_MOD_TIMESTAMP "whenChanged" #define LTDB_OBJECTCLASS "objectClass" /* The following definitions come from lib/ldb/ldb_tdb/ldb_cache.c */ |