59 Commits

Author SHA1 Message Date
Luke Howard
0e8c4ccc6e hdb: eliminate hdb_entry_ex
Remove hdb_entry_ex and revert to the original design of hdb_entry (except with
an additional context member in hdb_entry which is managed by the free_entry
method in HDB).
2022-01-15 18:54:57 +11:00
Luke Howard
c5551775e2 hdb: decorate HDB_entry with context member
Decorate HDB_entry with context and move free_entry callback into HDB structure
itself. Requires updating hdb_free_entry() signature to include HDB parameter.
A follow-up commit will consolidate hdb_entry_ex (which has a single hdb_entry
member) into hdb_entry.
2022-01-15 18:54:57 +11:00
Nicolas Williams
5447b81fb1 hdb: Move virtual principals into HDB layer
This is a large commit that adds several features:

 - Revamps and moves virtual host-based service principal functionality
   from kdc/ to lib/hdb/ so that it may be automatically visible to
   lib/kadm5/, as well as kadmin(1)/kadmind(8) and ktutil(1).

   The changes are backwards-incompatible.

 - Completes support for documenting a service principal's supported
   enctypes in its HDB entry independently of its long-term keys.  This
   will reduce HDB bloat by not requiring that service principals have
   more long-term keys than they need just to document the service's
   supported enctypes.

 - Adds support for storing krb5.conf content in principals' HDB
   entries.  This may eventually be used for causing Heimdal KDC
   services to reconfigure primary/secondary roles automatically by
   discovering the configured primary in an HDB entry for the realm.

   For now this will be used to help reduce the amount of configuration
   needed by clients of an upcoming HTTP binding of the kadmin service.
2020-09-08 00:25:36 -05:00
Nicolas Williams
5bcbe2125b Add hdb_set_sync() method 2017-10-10 13:07:18 -05:00
Nicolas Williams
b83cf2f3bd Support db1 and db3 at the same time 2016-11-08 15:41:38 -06:00
Marcin Cieślak
033001e732 Prefer BDB3/4/5 to BDB1/2 2016-11-08 15:48:40 -05:00
Nicolas Williams
20df2c8706 Two-phase HDB commit via iprop log, + GC for log
We used to update the iprop log and HDB in different orders depending on
the kadm5 operation, which then led to various race conditions.

The iprop log now functions as a two-phase commit (with roll forward)
log for HDB changes.  The log is auto-truncated, keeping the latest
entries that fit in a configurable maximum number of bytes (defaults to
50MB).  See the log-max-size parameter description in krb5.conf(5).

The iprop log format and the protocol remain backwards-compatible with
earlier versions of Heimdal.  This is NOT a flag-day; there is NO need
to update all the slaves at once with the master, though it is advisable
in general.  Rolling upgrades and downgrades should work.

The sequence of updates is now (with HDB and log open and locked):

a) check that the HDB operation will succeed if attempted,
b) append to iprop log and fsync() it,
c) write to HDB (which should fsync()),
d) mark last log record committed (no fsync in this case).

Every kadm5 write operation recover transactions not yet confirmed as
committed, thus there can be at most one unconfirmed commit on a master
KDC.

Reads via kadm5_get_principal() also attempt to lock the log, and if
successful, recover unconfirmed transactions; readers must have write
access and must win any race to lock the iprop log.

The ipropd-master daemon also attempts to recover unconfirmed
transactions when idle.

The log now starts with a nop record whose payload records the offset of
the logical end of the log: the end of the last confirmed committed
transaction.  This is kown as the "uber record".  Its purpose is
two-fold: act as the confirmation of committed transactions, and provide
an O(1) method of finding the end of the log (i.e., without having to
traverse the entire log front to back).

Two-phase commit makes all kadm5 writes single-operation atomic
transactions (though some kadm5 operations, such as renames of
principals, and changes to principals' aliases, use multiple low-level
HDB write operations, but still all in one transaction).  One can still
hold a lock on the HDB across many operations (e.g., by using the lock
command in a kadmin -l or calling kadm5_lock()) in order to push
multiple transactions in sequence, but this sequence will not be atomic
if the process or host crashes in the middle.

As before, HDB writes which do not go through the kadm5 API are excluded
from all of this, but there should be no such writes.

Lastly, the iprop-log(1) command is enhanced as follows:

 - The dump, last-version, truncate, and replay sub-commands now have an
   option to not lock the log.  This is useful for inspecting a running
   system's log file, especially on slave KDCs.

 - The dump, last-version, truncate, and replay sub-commands now take an
   optional iprop log file positional argument, so that they may be used
   to inspect log files other than the running system's
   configured/default log file.

Extensive code review and some re-writing for clarity by Viktor Dukhovni.
2016-02-26 00:55:33 -06:00
Nicolas Williams
c6f24e99f0 Revamp cf/db.m4; test LMDB 2016-02-26 00:55:32 -06:00
Roland C. Dowdeswell
2656659fc2 Fix a typo in a comment. 2012-05-21 17:12:16 +01:00
Roland C. Dowdeswell
1f63d6e4dc Fix locking issues in DB1 HDB backend.
Multiple concurrent writers would cause the HDB to become corrupted
as the locking was not sufficient to prevent these sorts of issues
from occurring.  We have changed the locking to obtain the appropriate
kind of lock on database open and to hold that lock until the
database closes.  We need to do this as Berkeley DB 1.85 will cache
information from the database in memory and if if this information
is updated without our knowledge then our later writes will corrupt
the database.  We speculate that there would be issues with a single
writer and reader but did not reproduce them.
2012-05-18 12:39:08 +01:00
Nicolas Williams
95262936c7 s/assert/heim_assert/ and remove dead code 2011-07-24 11:07:27 -05:00
Nicolas Williams
abd94953e2 Fixes to lock nesting code. 2011-07-22 16:04:52 -05:00
Nicolas Williams
58d72035f1 Added kadm5_lock() and unlock. 2011-07-22 16:04:52 -05:00
Love Hornquist Astrand
6c6726d76c drop hdb_fetch 2010-11-28 11:46:46 -08:00
Love Hornquist Astrand
ee8c2e45b4 use _hdb_fetch_kvno 2010-11-28 11:20:31 -08:00
Love Hörnquist Åstrand
5a9dd54e95 drop RCSID
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25319 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-07-05 05:09:16 +00:00
Love Hörnquist Åstrand
6aa38c372c Push enterprise support into the bdblayer.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25318 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-07-05 05:09:04 +00:00
Love Hörnquist Åstrand
54b5beeb98 set hdb_capability_flags = 0
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25311 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-07-05 05:07:41 +00:00
Love Hörnquist Åstrand
cdc2b37670 switch to krb5_clear_error_message
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23913 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-10-14 02:56:07 +00:00
Love Hörnquist Åstrand
6937d41a02 remove trailing whitespace
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23815 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-09-13 09:21:03 +00:00
Love Hörnquist Åstrand
e172367898 switch to utf8 encoding of all files
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23814 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-09-13 08:53:55 +00:00
Love Hörnquist Åstrand
7fcd266fdd use krb5_set_error_message
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23316 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-06-23 04:32:32 +00:00
Love Hörnquist Åstrand
7aaf3af6e4 Be better at setting and clearing error string.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20215 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-02-09 21:59:53 +00:00
Love Hörnquist Åstrand
ee9b01aa50 By using full function calling conversion (*func) we avoid problem
when close(fd) is overridden using a macro.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18079 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-09-12 18:12:37 +00:00
Love Hörnquist Åstrand
91026474ad memset hdb_entry_ex before use
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16395 ec53bebd-3082-4978-b11e-865c3cabbd6b
2005-12-13 11:54:10 +00:00
Love Hörnquist Åstrand
0c2369acd0 Wrap hdb_entry with hdb_entry_ex, patch originally from Andrew Bartlet
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16378 ec53bebd-3082-4978-b11e-865c3cabbd6b
2005-12-12 12:40:12 +00:00
Love Hörnquist Åstrand
0fa794702c (hdb_db_create): use calloc to callocate memory
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16304 ec53bebd-3082-4978-b11e-865c3cabbd6b
2005-11-28 23:33:24 +00:00
Love Hörnquist Åstrand
c5ac9b9af6 (DB_open): in case of error, close database
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@15508 ec53bebd-3082-4978-b11e-865c3cabbd6b
2005-06-23 13:34:17 +00:00
Love Hörnquist Åstrand
0540f13b86 prefix all struct HDB elements with hdb_
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@12880 ec53bebd-3082-4978-b11e-865c3cabbd6b
2003-09-19 00:25:35 +00:00
Assar Westerlund
334c7ffa33 merge of DB-NEW
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@10453 ec53bebd-3082-4978-b11e-865c3cabbd6b
2001-08-09 08:41:49 +00:00
Assar Westerlund
c7562eda65 add some more error strings
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@10338 ec53bebd-3082-4978-b11e-865c3cabbd6b
2001-07-13 06:30:42 +00:00
Assar Westerlund
c7c19f07f3 adapt to new hdb_seal_keys and hdb_unseal_keys
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@9595 ec53bebd-3082-4978-b11e-865c3cabbd6b
2001-01-30 01:24:29 +00:00
Johan Danielsson
bb90aecaee pass context to seal/unseal_keys
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8551 ec53bebd-3082-4978-b11e-865c3cabbd6b
2000-07-05 13:17:32 +00:00
Assar Westerlund
f498ac3c40 add berkeley db3 interface. contributed by Derrick J Brashear <shadow@dementia.org>
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8312 ec53bebd-3082-4978-b11e-865c3cabbd6b
2000-06-05 01:08:47 +00:00
Johan Danielsson
c5b916ca6f remove advertising clause
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@7464 ec53bebd-3082-4978-b11e-865c3cabbd6b
1999-12-02 17:05:13 +00:00
Johan Danielsson
f604b5db10 add flags to DB_seq, DB_firstkey, and DB_nextkey
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@6089 ec53bebd-3082-4978-b11e-865c3cabbd6b
1999-05-03 16:51:51 +00:00
Assar Westerlund
2974b8e4cc (DB_destroy): clear master key
(DB_open): check malloc


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@5760 ec53bebd-3082-4978-b11e-865c3cabbd6b
1999-03-25 03:38:56 +00:00
Johan Danielsson
0b5e5caf89 (DB_open): try to open database w/o .db extension
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@5397 ec53bebd-3082-4978-b11e-865c3cabbd6b
1999-02-20 15:40:16 +00:00
Johan Danielsson
20c97f7f5e (DB_open): add test for database format
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@5394 ec53bebd-3082-4978-b11e-865c3cabbd6b
1999-02-20 15:11:27 +00:00
Assar Westerlund
aebdc83e68 (DB_seq): unseal key
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@5298 ec53bebd-3082-4978-b11e-865c3cabbd6b
1999-01-30 18:21:42 +00:00
Assar Westerlund
2032781fa8 rename delete -> remove
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@5241 ec53bebd-3082-4978-b11e-865c3cabbd6b
1998-11-23 11:54:22 +00:00
Johan Danielsson
ea12bdc9e8 Remove unused stuff.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3966 ec53bebd-3082-4978-b11e-865c3cabbd6b
1997-11-12 00:47:52 +00:00
Assar Westerlund
593cda47a5 implement new interface
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3626 ec53bebd-3082-4978-b11e-865c3cabbd6b
1997-10-16 04:13:04 +00:00
Johan Danielsson
a2a09b5eab Add _del routine, use common fetch/store/delete.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3292 ec53bebd-3082-4978-b11e-865c3cabbd6b
1997-08-30 19:29:05 +00:00
Assar Westerlund
601d7c81e1 (DB__get): fix parameters in call to `krb5_data_copy'
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3235 ec53bebd-3082-4978-b11e-865c3cabbd6b
1997-08-28 22:10:52 +00:00
Assar Westerlund
3a8615c2ad (DB_seq): check for valid hdb_entries
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3214 ec53bebd-3082-4978-b11e-865c3cabbd6b
1997-08-28 01:26:09 +00:00
Johan Danielsson
5c5e6599d9 Add _put.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3171 ec53bebd-3082-4978-b11e-865c3cabbd6b
1997-08-26 22:29:08 +00:00
Johan Danielsson
5af8445972 Free name in close.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@2979 ec53bebd-3082-4978-b11e-865c3cabbd6b
1997-08-14 22:18:04 +00:00
Johan Danielsson
f813822cdd +DB_rename
.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@2861 ec53bebd-3082-4978-b11e-865c3cabbd6b
1997-08-09 20:34:15 +00:00
Johan Danielsson
be512825c6 Add database locking.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@2670 ec53bebd-3082-4978-b11e-865c3cabbd6b
1997-08-01 14:53:18 +00:00