Commit Graph

120 Commits

Author SHA1 Message Date
Joseph Sutton
cfb32a638e Introduce macro for common plugin structure elements
Heimdal's HDB plugin interface, and hence Samba's KDC that depends upon
it, doesn't work on 32-bit builds due to structure fields being arranged
in the wrong order. This problem presents itself in the form of
segmentation faults on 32-bit systems, but goes unnoticed on 64-bit
builds thanks to extra structure padding absorbing the errant fields.

This commit reorders the HDB plugin structure fields to prevent crashes
and introduces a common macro to ensure every plugin presents a
consistent interface.

Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=15110

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-11-17 17:15:21 -06:00
Jeffrey Altman
e0e61d2b91 lib/hdb: hdb_create consistently check cb_ctx.h
instead of testing both cb_ctx.h and cb_ctx.h->prefix
for non-NULL, ensure that cb_ctx.h is NULL after each
failed for() loop.  This also ensures that cb_ctx.h
is never left pointing to an invalid non-NULL value.

Change-Id: I3264577b0fbf1d620b00f87d251e8c43b81e0f29
2022-01-23 21:27:56 -05:00
Nicolas Williams
b991c4b2b3 hdb: Fix coverity warnings
This is a fix for a false positive that we can avoid by changing the
internal API in question.  Might as well.
2022-01-20 12:41:39 -06:00
Nicolas Williams
2e729a9aa2 hdb: Fix coverity warnings 2022-01-17 17:32:24 -06:00
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
4f8399a433 hdb: Fix warnings and leaks 2022-01-14 17:10:16 -06:00
Luke Howard
e5e87497b1 hdb: use memset_s to zero HDB keys 2022-01-08 08:49:45 +11:00
Nicolas Williams
831a5f9db3 hdb: Fix crash when expected KR is missing 2021-10-30 15:21:54 -05:00
Andrew Bartlett
c6df77a2cb Initialise err in hdb_create()
On Ubuntu 20.04 with gcc version 9.3.0 during a strict
Samba build with -Werror=maybe-uninitialized we get:

../../source4/heimdal/lib/hdb/hdb.c: In function ‘hdb_create’:
../../source4/heimdal/lib/hdb/hdb.c:831:13: error: ‘ret’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  831 |     if (*db && ret == 0)
      |         ~~~~^~~~~~~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-07-06 10:06:54 +10:00
Nicolas Williams
5aaf12351a iprop: More default HDB type fixes 2021-05-04 14:53:40 -05:00
Nicolas Williams
db7763ca7b asn1: X.681/682/683 magic handling of open types
Status:

 - And it works!

 - We have an extensive test based on decoding a rich EK certficate.

   This test exercises all of:

    - decoding
    - encoding with and without decoded open types
    - copying of decoded values with decoded open types
    - freeing of decoded values with decoded open types

   Valgrind finds no memory errors.

 - Added a manual page for the compiler.

 - rfc2459.asn1 now has all three primary PKIX types that we care about
   defined as in RFC5912, with IOS constraints and parameterization:

    - `Extension`       (embeds open type in an `OCTET STRING`)
    - `OtherName`       (embeds open type in an        `ANY`-like type)
    - `SingleAttribute` (embeds open type in an        `ANY`-like type)
    - `AttributeSet`    (embeds open type in a  `SET OF ANY`-like type)

   All of these use OIDs as the open type type ID field, but integer
   open type type ID fields are also supported (and needed, for
   Kerberos).

   That will cover every typed hole pattern in all our ASN.1 modules.

   With this we'll be able to automatically and recursively decode
   through all subject DN attributes even when the subject DN is a
   directoryName SAN, and subjectDirectoryAttributes, and all
   extensions, and all SANs, and all authorization-data elements, and
   PA-data, and...

   We're not really using `SingleAttribute` and `AttributeSet` yet
   because various changes are needed in `lib/hx509` for that.

 - `asn1_compile` builds and recognizes the subset of X.681/682/683 that
   we need for, and now use in, rfc2459.asn1.  It builds the necessary
   AST, generates the correct C types, and generates templating for
   object sets and open types!

 - See READMEs for details.

 - Codegen backend not tested; I won't make it implement automatic open
   type handling, but it should at least not crash by substituting
   `heim_any` for open types not embedded in `OCTET STRING`.

 - We're _really_ starting to have problems with the ITU-T ASN.1
   grammar and our version of it...

   Type names have to start with upper-case, value names with
   lower-case, but it's not enough to disambiguate.

   The fact the we've allowed value and type names to violate their
   respective start-with case rules is causing us trouble now that we're
   adding grammar from X.681/682/683, and we're going to have to undo
   that.

   In preparation for that I'm capitalizing the `heim_any` and
   `heim_any_set` types, and doing some additional cleanup, which
   requires changes to other parts of Heimdal (all in this same commit
   for now).

   Problems we have because of this:

    - We cannot IMPORT values into modules because we have no idea if a
      symbol being imported refers to a value or a type because the only
      clue we would have is the symbol's name, so we assume IMPORTed
      symbols are for types.

      This means we can't import OIDs, for example, which is super
      annoying.

      One thing we might be able to do here is mark imported symbols as
      being of an undetermined-but-not-undefined type, then coerce the
      symbol's type the first time it's used in a context where its type
      is inferred as type, value, object, object set, or class.  (Though
      since we don't generate C symbols for objects or classes, we won't
      be able to import them, especially since we need to know them at
      compile time and cannot defer their handling to link- or
      run-time.)

    - The `NULL` type name, and the `NULL` value name now cause two
      reduce/reduce conflicts via the `FieldSetting` production.

    - Various shift/reduce conflicts involving `NULL` values in
      non-top-level contexts (in constraints, for example).

 - Currently I have a bug where to disambiguate the grammar I have a
   CLASS_IDENTIFIER token that is all caps, while TYPE_IDENTIFIER must
   start with a capital but not be all caps, but this breaks Kerberos
   since all its types are all capitalized -- oof!

   To fix this I made it so class names have to be all caps and
   start with an underscore (ick).

TBD:

 - Check all the XXX comments and address them
 - Apply this treatment to Kerberos!  Automatic handling of authz-data
   sounds useful :)
 - Apply this treatment to PKCS#10 (CSRs) and other ASN.1 modules too.
 - Replace various bits of code in `lib/hx509/` with uses of this
   feature.
 - Add JER.
 - Enhance `hxtool` and `asn1_print`.

Getting there!
2021-02-28 18:13:08 -06:00
Nicolas Williams
8c7900c40b hdb: Use db type preference from ./configure
Use the HDB backend type from the --with-db-type-preference=... option
to ./configure to make the default HDB backend more stable.
2020-10-05 14:51:03 -05:00
Nicolas Williams
93ada1fbf6 hdb: Remove default HDB backend footgun
Do not allow a change in build configuration time default HDB backend
selection cause existing default HDBs to not be possible to open.

Otherwise such a change will cause a KDC configured to use the default
HDB (i.e., without setting it in the "database" stanza in the "[kdc]"
section of krb5.conf) to not start.
2020-10-05 14:51:03 -05: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
ea90ca8666 Move some infra bits of lib/krb5/ to lib/base/ (2)
This is the second of two commits in a series that must be picked together.

This series of two commits moves parts of lib/krb5/ infrastructure
functionality to lib/base/, leaving behind wrappers.

Some parts of libkrb5 are entirely generic or easily made so, and could
be useful in various parts of Heimdal that are not specific to the krb5
API, such as:

 - lib/gssapi/  (especially since the integration of NegoEx)
 - lib/hx509/
 - bx509d       (which should really move out of kdc/)

For the above we need to move these bits of lib/krb5/:

 - lib/krb5/config_file.c   (all of it, leaving forwardings behind)
 - lib/krb5/config_reg.c    (all of it)
 - lib/krb5/plugin.c        (all of it, leaving forwardings behind)
 - lib/krb5/log.c           (all of it, ditto)
 - lib/krb5/heim_err.et     (all of it)

And because of those two, these too must also move:

 - lib/krb5/expand_path.c   (all of it, leaving forwardings behind)
 - lib/krb5/warn.c          (just the warning functions, ditto)

The changes to the moved files are mostly quite straightforward and are
best reviewed with --word-diff=color.

We're also creating a heim_context and a heim API to go with it.  But
it's as thin as possible, with as little state as necessary to enable
this move.  Functions for dealing with error messages use callbacks.

Moving plugin.c does have one knock-on effect on all users of the old
krb5 plugin API (which remains), which is that a global search and
replace of struct krb5_plugin_data to struct heim_plugin_data was
needed, though the layout and size of that structure doesn't change, so
the ABI doesn't either.

As well, we now build lib/vers/ and lib/com_err/ before lib/base/ so as
to be able to move lib/krb5/heim_err.et to lib/base/ so that we can make
use of HEIM_ERR_* in lib/base/, specifically in the files that moved.

Once this is all done we'll be able to use config files and plugins in
lib/hx509/, we'll be able to move bx509d out of kdc/, and so on.

Most if not all of the new functions in lib/base/ are Heimdal-private,
thus calling conventions for them are not declared.

Status:

 - builds and passes CIs (Travis, Appveyor)
 - ran make check-valgrind and no new leaks or other memory errors
 - ready for review

HOW TO REVIEW:

     $ # Review file moves:
     $ git log --stat -n1 HEAD^
     $
     $ # Review changes to moved files using --word-diff=color
     $ git log -p -b -w --word-diff=color HEAD^..HEAD   \
               lib/base/config_file.c                   \
               lib/base/config_reg.c                    \
               lib/base/expand_path.c                   \
               lib/base/warn.c                          \
               lib/krb5/config_file.c                   \
               lib/krb5/config_reg.c                    \
               lib/krb5/expand_path.c                   \
               lib/krb5/warn.c
     $
     $ # Review the whole thing, possibly adding -b and/or -w, and
     $ # maybe --word-diff=color:
     $ git log -p origin/master..HEAD
     $ git log -p -b -w origin/master..HEAD
     $ git log -p -b -w --word-diff=color origin/master..HEAD

TBD (future commits):

 - make lib/gssapi use the new heimbase functions
 - move kx509/bx509d common code to lib/hx509/ or other approp. location
 - move bx509d out of kdc/
2020-03-02 10:56:13 -06:00
Jeffrey Altman
387684aa93 WIN32: fix calling conventions for 32-bit builds
On 32-bit Windows Intel builds the __cdecl and __stdcall calling
conventions are different so labeling the functions that are
exported or assigned to function pointers matters.

Change-Id: I03b6f34baeb9ffb2e683fd979f12f27a5078a4da
2019-01-14 06:12:36 -05:00
Luke Howard
803efebca5 krb5, kadm5: refactor plugin API
Refactor plugin framework to use a single list of loaded plugins; add a new
plugin API where DSOs export a load function that can declare dependencies and
export multiple plugins; refactor kadm5 hook API to use krb5 plugin framework.

More information in krb5-plugin(7).
2019-01-03 20:06:27 -06:00
Nicolas Williams
1c81ddf4e2 Round #2 of scan-build warnings cleanup 2016-11-16 17:03:14 -06:00
Nicolas Williams
995966f9d1 Fix hdb_create() HDB dbname parsing 2016-11-15 15:35:19 -06:00
Nicolas Williams
09f0a25fda kdc --builtin-hdb should list loadable backends
This fixes the following problems from #210:

 - hdb_ldap doesn't load even when installed correctly
 - loadable hdb backends not listed by kdc --builtin-hdb

Not fixed:

 - hdb_ldap.so not installed in plugin dir
2016-11-15 11:34:54 -06:00
Nicolas Williams
b83cf2f3bd Support db1 and db3 at the same time 2016-11-08 15:41:38 -06:00
Nicolas Williams
16275048b8 Prefer LMDB to Berkeley DB 2016-02-26 00:55:32 -06:00
Nicolas Williams
a94dc50114 Add --with-db-type-preference config param 2016-02-26 00:55:32 -06:00
Nicolas Williams
c6f24e99f0 Revamp cf/db.m4; test LMDB 2016-02-26 00:55:32 -06:00
Love Hörnquist Åstrand
d8d0e659ce make sure h is set at when we find a match, from [GITHUB #54] 2014-01-31 08:45:29 +01:00
Love Hornquist Astrand
9b6cae5408 remove unused code that I meant to drop 2013-03-05 20:06:15 -08:00
Nicolas Williams
d9764a5399 Make lib/hdb/hdb.c build (but hdb plugins broken) 2013-03-05 21:47:21 -06:00
Love Hornquist Astrand
1eb4e2516e unify hdb_so_method and hdb_method 2013-03-04 10:18:16 -08:00
Tollef Fog Heen
4787ea76a9 Update hdb's use of the plugin interface
The various _krb5_plugin_* functions are gone, replace this with the new world order.

Signed-off-by: Love Hornquist Astrand <lha@h5l.org>
2013-03-04 10:00:41 -08:00
Howard Chu
9f95207933 Add support for OpenLDAP libmdb 2012-10-07 16:47:45 -07:00
Love Hornquist Astrand
216bfa564d rename mdb to mitdb 2012-10-06 15:38:56 -07:00
Nicolas Williams
c9609cdb37 Initial patch for dealing with AD x-realm key rollover
AD issues x-realm TGTs with kvno 0.  On key x-realm trust key change
    we need to be able to try current and previous keys for trust, else
    we will have some failures.
2011-11-15 21:53:33 -06:00
Nicolas Williams
cf1c898e95 Undo a s/size_t/int/. Iterators must be unsigned. 2011-07-22 16:07:05 -05:00
Nicolas Williams
fca53990e4 Initial commit for second approach for multiple kvno. NOT TESTED! 2011-07-22 16:04:51 -05:00
Love Hornquist Astrand
0879b9831a remove trailing whitespace 2011-05-21 11:57:31 -07:00
Love Hornquist Astrand
f5f9014c90 Warning fixes from Christos Zoulas
- shadowed variables
- signed/unsigned confusion
- const lossage
- incomplete structure initializations
- unused code
2011-04-29 20:25:05 -07:00
Love Hornquist Astrand
7a4d4c5f4e Add HAVE_SQLITE3 that allows control if you want sqlite or not 2011-04-16 10:26:43 -07:00
Asanka C. Herath
2f8031c1d1 Cast dlsym() returns before use 2010-11-24 15:33:10 -05:00
Gabor Gombas
75a53f54fc the MIT DB code is between "#if HAVE_DB1... #endif"
use the same check in the descriptor table

Signed-off-by: Love Hornquist Astrand <lha@h5l.org>
2009-11-25 05:10:29 -08:00
Love Hornquist Astrand
7b42f760b8 add _hdb_keytab2hdb_entry 2009-11-22 12:52:08 -08:00
Love Hornquist Astrand
4dc9ccf0cb add new database backends 2009-11-22 12:49:13 -08:00
Love Hornquist Astrand
39a751d6fb expose hdb_interface_version 2009-10-13 09:35:39 -07:00
Love Hornquist Astrand
82150be255 allow loading sqlite 2009-07-19 17:58:53 -07: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
421cb259bd doxygen
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25080 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-04-03 17:21:59 +00:00
Love Hörnquist Åstrand
1a488a85b7 doxygen
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24977 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-03-28 17:08:57 +00:00
Love Hörnquist Åstrand
4fd6aad19a include krb5_locl.h only, no need to pull in krb5.h twice
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24087 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-12-11 04:57:09 +00:00
Love Hörnquist Åstrand
7592a925b5 avoid strndup since it doesnt do what we expect on aix
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24086 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-12-11 04:56:54 +00:00
Love Hörnquist Åstrand
2ceccf84e8 make compile
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24033 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-11-12 04:19:29 +00:00