summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2018-10-10 16:12:28 +0200
committerJeremy Allison <jra@samba.org>2018-11-06 18:57:26 +0100
commit0d7f67f07cd96943dfe58e91254145e28e047ace (patch)
tree82a8346b97a752ea5d6cca5c4deb88bad7102009
parent72ec893d0aaa518a2cf22aa68b16c3907a17dfc8 (diff)
downloadsamba-0d7f67f07cd96943dfe58e91254145e28e047ace.tar.gz
gencache: Convert to a binary timestamp
Two reasons: The ascii conversion shows up on profiles. In a further commit we will get checksums for gencache entries to protect at hidden corruption due to a crash on the non-transactioned gencache.tdb. Next to the timestamp this is a second field that is gencache metadata, and I don't want to deal with a second ascii number when at least some of the gencache values are binary already. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r--source3/lib/gencache.c37
1 files changed, 6 insertions, 31 deletions
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index f566534a1a6..5aa52a06e7c 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -31,8 +31,6 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_TDB
-#define CACHE_DATA_FMT "%12u/"
-
static struct tdb_wrap *cache;
static struct tdb_wrap *cache_notrans;
@@ -269,8 +267,6 @@ bool gencache_set_data_blob(const char *keystr, DATA_BLOB blob,
{
TDB_DATA key;
int ret;
- fstring hdr;
- int hdr_len;
time_t last_stabilize;
static int writecount;
TDB_DATA dbufs[2];
@@ -297,13 +293,8 @@ bool gencache_set_data_blob(const char *keystr, DATA_BLOB blob,
return true;
}
- hdr_len = fstr_sprintf(hdr, CACHE_DATA_FMT, (int)timeout);
-
- if (hdr_len == -1) {
- return false;
- }
-
- dbufs[0] = (TDB_DATA) { .dptr = (uint8_t *)hdr, .dsize = hdr_len };
+ dbufs[0] = (TDB_DATA) { .dptr = (uint8_t *)&timeout,
+ .dsize = sizeof(time_t) };
dbufs[1] = (TDB_DATA) { .dptr = blob.data, .dsize = blob.length };
DEBUG(10, ("Adding cache entry with key=[%s] and timeout="
@@ -408,32 +399,16 @@ bool gencache_del(const char *keystr)
static bool gencache_pull_timeout(TDB_DATA data, time_t *pres, DATA_BLOB *payload)
{
- time_t res;
- char *slash = NULL;
- char *endptr;
-
- if (data.dptr == NULL) {
- return false;
- }
- slash = memchr(data.dptr, '/', data.dsize);
- if (slash == NULL) {
- return false;
- }
-
- res = strtol((char *)data.dptr, &endptr, 10);
-
- if ((endptr == NULL) || (*endptr != '/')) {
- DBG_WARNING("Invalid gencache data format\n");
+ if ((data.dptr == NULL) || (data.dsize < sizeof(time_t))) {
return false;
}
if (pres != NULL) {
- *pres = res;
+ memcpy(pres, data.dptr, sizeof(time_t));
}
if (payload != NULL) {
- endptr += 1;
*payload = (DATA_BLOB) {
- .data = discard_const_p(uint8_t, endptr),
- .length = data.dsize - PTR_DIFF(endptr, data.dptr),
+ .data = data.dptr + sizeof(time_t),
+ .length = data.dsize - sizeof(time_t),
};
}
return true;