summaryrefslogtreecommitdiff
path: root/source3/lib/gencache.c
AgeCommit message (Collapse)AuthorFilesLines
2026-04-07s3:gencache: make gencache.tdb none readable for othersRalph Wuerthner1-2/+2
Signed-off-by: Ralph Wuerthner <ralph.wuerthner@de.ibm.com> Reviewed-by: Xavi Hernandez <xhernandez@redhat.com> Reviewed-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Anoop C S <anoopcs@samba.org>
2021-01-06s3:lib: Create the cache path of user gencache recursivelyAndreas Schneider1-1/+1
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14601 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Wed Jan 6 23:59:58 UTC 2021 on sn-devel-184
2020-05-15s3:gencache: Allow to open gencache as read-onlyAndreas Schneider1-3/+60
This allows client tools to access the cache for ready-only operations as a normal user. Example: net ads status BUG: https://bugzilla.samba.org/show_bug.cgi?id=14370 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Fri May 15 14:40:32 UTC 2020 on sn-devel-184
2019-01-19s3:lib: Fix the debug message for adding cache entries.Andreas Schneider1-4/+4
To get correct values, we need to cast 'timeout' to 'long int' first in order to do calculation in that integer space! Calculations are don in the space of the lvalue! Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2018-11-16lib: Fix CID 1441264 Error handling issues (CHECKED_RETURN)Volker Lendecke1-4/+10
This is not worth keeping a CID around :-) Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2018-11-06gencache: Prune expired entriesVolker Lendecke1-0/+88
This solves the problem that gencache never shrinks right now. Whenever we write an entry, we now walk that entry's chain and delete expired entries. This should be a good balance between performance and cleanup actions: Reading is still unaffected, and those who write pay a small penalty while keeping gencache size under control. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2018-11-06gencache: Wipe corrupt databasesVolker Lendecke1-13/+53
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2018-11-06gencache: Remove transaction-based tdbVolker Lendecke1-414/+9
At more than one large site I've seen significant problems due to gencache_stabilize. gencache_stabilize was mainly introduced to survive machine crashes with the cache still being in place. Given that most installations crash rarely and this is still a cache, this safety is overkill and causes real problems. With the recent changes to tdb, we should be safe enough to run on completely corrupted databases and properly detect errors. A further commit will introduce code that wipes the gencache.tdb if such a corruption is detected. There is one kind of corruption that we don't properly handle: Orphaned space in the database. I don't have a good idea yet how to handle this in a graceful and efficient way during normal operations, but maybe this idea pops up at some point. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2018-11-06gencache: Add crc checkVolker Lendecke1-9/+39
This covers key, timestamp and data. This will detect silent corruption of gencache data after a system crash Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2018-11-06gencache: Convert to a binary timestampVolker Lendecke1-31/+6
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>
2018-10-19lib: Remove gencache.h from proto.hVolker Lendecke1-0/+1
It's a pain to recompile the world if gencache.h changes Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Fri Oct 19 18:52:50 CEST 2018 on sn-devel-144
2018-10-17gencache: Remove a redundant checkVolker Lendecke1-3/+0
tdb_storev itself is robust against overflow due to multiple buffers Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Wed Oct 17 22:22:51 CEST 2018 on sn-devel-144
2018-10-17gencache: Remove a redundant checkVolker Lendecke1-3/+0
gencache_pull_timeout checks for NULL ptr already Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2018-10-17gencache: Make gencache_pull_timeout return a payload DATA_BLOBVolker Lendecke1-12/+10
Both relevant callers created one anyway. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2018-10-17gencache: Make gencache_pull_timeout a bit more robustVolker Lendecke1-7/+12
The previous version assumed a well-formed "val", we just handed it to strtol without properly checking that it contains the delimiter. So strtol could well run off the end of "val" in case of data corruption. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2018-10-17gencache: Call string_term_tdb_data() only onceVolker Lendecke1-4/+6
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2018-10-17gencache: Swap tests: Do cheapest firstVolker Lendecke1-4/+4
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2018-10-17gencache: Avoid counting characters manuallyVolker Lendecke1-4/+6
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2018-10-16lib: Move the "expired" for gencache_parse calculation into gencache.cVolker Lendecke1-12/+26
Make it more robust Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Tue Oct 16 21:20:19 CEST 2018 on sn-devel-144
2018-08-17lib: Pass mem_ctx to cache_path()Volker Lendecke1-1/+1
Fix a confusing API: Many places TALLOC_FREE the path where it's not clear you have to do it. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Fri Aug 17 14:28:51 CEST 2018 on sn-devel-144
2018-08-17lib: Pass mem_ctx to lock_path()Volker Lendecke1-1/+1
Fix a confusing API: Many places TALLOC_FREE the path where it's not clear you have to do it. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2017-11-29lib: Pass blob instead of &blob to gencache_set_data_blobVolker Lendecke1-6/+6
Passing a whole DATA_BLOB is cheap enough to simplify the callers: A caller does not have to create a separate variable. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2017-08-17gencache: Simplify gencache_stabilizeVolker Lendecke1-45/+10
The only record that must remain in gencache_notrans.tdb is the last_stabilize marker. Use tdb_wipe_all and store the marker under the allrecord lock. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Thu Aug 17 15:49:00 CEST 2017 on sn-devel-144
2017-08-17gencache: Remove tdb_check from gencache_init()Volker Lendecke1-23/+0
This was legacy from times when we had just one non-transactioned gencache.tdb. With the split into transactioned gencache.tdb and fast, non-transactioned, mutexed clear-if-first gencache_notrans.tdb this has become unnecessary. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2017-03-03lib: Make gencache hash size configurable, default to 10000Volker Lendecke1-4/+7
For large deployments with many users, we put a lot of idmapping entries into gencache. Increase the hash size from our default 131. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2017-02-22Correct "successfuly" typos.Chris Lamb1-2/+2
Signed-off-by: Chris Lamb <chris@chris-lamb.co.uk> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
2016-09-20gencache: Bail out of stabilize if we can not get the allrecord lockVolker Lendecke1-1/+1
Bug: https://bugzilla.samba.org/show_bug.cgi?id=12045 Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Tue Sep 20 04:09:33 CEST 2016 on sn-devel-144
2016-08-29lib: Use tdb_storev in gencacheVolker Lendecke1-14/+5
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Mon Aug 29 22:51:34 CEST 2016 on sn-devel-144
2016-03-07lib: Avoid a gencache_parse when setting a delete markerVolker Lendecke1-1/+1
We know that we want to put something into _notrans, no point in doing another round trip into gencache.tdb. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2016-03-07lib: Avoid looking at fcntl'ed gencache.tdbVolker Lendecke1-0/+27
gencache_notrans.tdb is much cheaper to look at than gencache.tdb because it's mutexed and thus avoids expensive fcntl locks. This patch aggressively uses the shared _notrans tdb for both positive and negative entries. It's a replacement for the memcache copy in every process that was removed a few patches ago. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2016-03-07lib: Simplify gencache_pull_timeout callersVolker Lendecke1-11/+10
gencache_pull_timeout used to point at the "/" right after the timeout. None of the callers was interested in the "/", they are interested in the payload. Increment the endpointer in gencache_pull_timeout and rename it. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2016-03-07lib: Make gencache_pull_timeout look at uint8_tVolker Lendecke1-7/+7
At this point we're still looking at TDB_DATA. This patch moves the casts to a more appropriate place. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2016-03-07lib: Remove memcache from gencacheVolker Lendecke1-36/+0
The main reason for this was to avoid access to the fcntl-governed transaction based gencache.tdb. A later patch will make this unnecessary by filling gencache_notrans more aggressively. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2016-03-07lib: Fix a typo in gencacheVolker Lendecke1-1/+1
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2016-03-07lib: Simplify gencache_delVolker Lendecke1-19/+26
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2016-03-07lib: skip deleted entries in gencache_iterateVolker Lendecke1-0/+5
"net cache flush" can give nasty error messages like Couldn't delete entry! key = IDMAP/UID2SID/12345 These happen when there's an already deleted entry in gencache_notrans.tdb, indicated by a 0 timeout. This happens if two gencache_del function calls have happened right after the other and a gencache_stabilize has not wiped them. In gencache_iterate, don't show these deleted entries Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2016-02-03gencache: Remove unused definesChristof Schmitt1-4/+0
Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2015-12-14gencache: Refactor gencache_set_data_blobVolker Lendecke1-5/+11
Replace 3 calls into talloc with 1. Add an overflow check. With this change, it will be easier to avoid the talloc call for small blobs in the future and do it on the stack. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2015-12-14gencache: True->true, False->falseVolker Lendecke1-10/+16
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2015-04-28lib: Fix a typoVolker Lendecke1-1/+1
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2015-03-17lib: Remove tdb_errorstr_compatVolker Lendecke1-7/+7
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
2015-02-09gencache: don't fail gencache_stabilize if there were records to delete.Michael Adam1-1/+1
Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2014-11-26gencache: Request mutexes for gencache_notrans.tdbChristof Schmitt1-1/+2
The check in tdb_wrap ensures that mutexes are only used on systems that properly support them. Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Wed Nov 26 19:04:11 CET 2014 on sn-devel-104
2014-11-26gencache: Convert gencache.tdb to tdb_wrapChristof Schmitt1-30/+31
This change is not strictly necessary, but for consistency both gencache tdbs are now opened through tdb_wrap. Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2014-11-26gencache: Convert gencache_notrans to use tdb_wrapChristof Schmitt1-25/+28
This allows using on the mutex check in tdb_wrap. Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2014-11-26s3:gencache: don't use transaction non non-persistent gencache_notrans.tdbMichael Adam1-8/+44
gencache_notrans.tdb is a non-persistent cache layer above the persistent gencache.tdb. Despite its name, and despite the nature of non-persistent tdbs, the current stabilization code uses a transaction on gencache_notrans.tdb like this: transaction_start(cache) transaction_start(cache_notrans) traverse(cache_notrans, stabilize_fn) transaction_commit(cache) transaction_commit(cache_notrans) where stabilze_fn does this on a record: 1. store it to or delete it from cache (depending on the timeout) 2. delete it from the cache_notrans This patch changes gencache_notrans.tdb to avoid transactions by using an all-record lock like this: tdb_allrecord_lock(cache_notrans) transaction_start(cache) traverse(cache_notrans, stabilize_fn_mod) transaction_commit(cache) traverse(cache_notrans, wipe_fn) tdb_wipe_all(cache_notrans) tdb_allrecord_unlock(cache_notrans) with stabilize_fn_mod doing only: 1. store the record to or delete it from cache (depending on the timeout) and wipe_fn deleting the records from the gencache_notrans db. This is a step towards making non-persistent-db specific features like mutex locking usable for gencache_notrans.tdb. Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2014-11-26s3:gencache: simply stabilize() a bit more: remove error from stateMichael Adam1-5/+1
state.error is set to true if and only if the traverse callback returns error (-1), and hence only if the traverse fails. Hence the the error state is redundant. Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2014-11-26s3:gencache: fix logic in stabilization when deleting a record from stable cacheMichael Adam1-3/+3
Set state->written = true in the delete case if and only if the record has really been deleted. This does currently not seem to lead to an unneeded write to the DB, since failure to delete the record will cause the traverse and hence the transaction to cancel. But I think this is clearer. Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2014-11-26lib: Use tdb_parse_record in gencache_setVolker Lendecke1-7/+15
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Wed Nov 26 14:50:38 CET 2014 on sn-devel-104
2014-10-06gencache: don't leak cache_path onto talloc tosDavid Disseldorp1-0/+11
Also check for allocation failures. Reported-by: Franz Pförtsch <franz.pfoertsch@brose.com> Signed-off-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>