Commit Graph

117 Commits

Author SHA1 Message Date
Minsoo Choo
aff90c322e Fix spelling 2024-06-16 23:30:48 -04:00
Taylor R Campbell
f051c36471 Pass NI_NUMERICSERV|NI_NUMERICSCOPE if NI_NUMERICHOST to getnameinfo.
This addresses part of https://github.com/heimdal/heimdal/issues/1214
to audit potential network leaks with [libdefaults] block_dns = yes.

NI_NUMERICHOST is _probably_ sufficient -- we probably won't see many
systems using NIS to look up service names by number if we fail to
specify NI_NUMERICSERV, and such systems probably require careful
auditing of their own.  And I don't know of any way NI_NUMERICSCOPE
could trigger network leaks.  But named scope ids are such a niche
option with IPv6 that setting it to forestall concerns can't hurt
much, and it makes reviewing easier if we just unconditionally flip
on all the numeric-only options.
2024-01-09 21:19:30 -06:00
Taylor R Campbell
e75e549252 Use AI_NUMERICSERV if block_dns, and use local getaddrinfo to audit.
This change has two parts:

1. Provide our own local implementation of numeric-only getaddrinfo
   in auditdns.c used to audit for DNS leaks, rather than deferring
   to dlsym(RTLD_NEXT, "getaddrinfo"), in terms of inet_pton.

   To keep review and implementation simple, this is limited to
   AI_NUMERICHOST _and_ AI_NUMERICSERV -- this requires that we
   arrange to pass AI_NUMERICSERV in callers too.

2. Wherever we implement block_dns, set AI_NUMERICSERV in addition to
   AI_NUMERICHOST as needed by the new auditdns.c getaddrinfo.

   (In principle this might also avoid other network leaks -- POSIX
   guarantees no name resolution service will be invoked, and gives
   NIS+ as an example.)

   One tiny semantic change to avoid tripping over the auditor:
   kadmin(8) now uses the string "749" rather than the string
   "kerberos-adm".  (Currently we don't audit kadmin(8) for DNS leaks
   but let's avoid leaving a rake to step on.)  Every other caller I
   found is already guaranteed to pass a numeric service rather than
   named service to getaddrinfo.

fix https://github.com/heimdal/heimdal/issues/1212
2024-01-09 16:06:32 -06:00
Taylor R Campbell
19505537fd Ensure all calls to rk_dns_lookup are headed by a block_dns check.
Exception: In lib/kafs/common.c, we don't have a krb5_context in
which to check.
2024-01-08 10:22:02 -06:00
Taylor R Campbell
fd77c4000d Ensure all calls to getaddrinfo are headed by a block_dns check.
If block_dns is set, call getaddrinfo with AI_NUMERICHOST set and
AI_CANONNAME clear.

Some paths may not have set AI_CANONNAME, but it's easier to audit
this way when the getaddrinfo prelude is uniform across call sites,
and the compiler can optimize it away.
2024-01-08 10:22:02 -06:00
Taylor R Campbell
2e3dada6fd krb5/krbhst.c: Constify plugin stuff. 2023-06-20 12:19:48 -05:00
Nicolas Williams
46df04dafb krb5: Fix leaks 2023-01-04 00:43:36 -06:00
Nicolas Williams
e5a8a6f972 krb5: Quiet static analyzer warning in krbhst 2023-01-04 00:43:36 -06:00
Luke Howard
917e16049a base: make heim_alloc deallocator use HEIM_CALLCONV 2022-01-28 17:24:57 -06:00
Nicolas Williams
fc42ff0212 krb5: Fix NULL-deref in send_to_kdc
Coverity thinks `handle` in lib/krb5/send_to_kdc.c:krb5_sendto_context()
at 1241 can be NULL, leading to a NULL derefence in `get_next()`.  This
is an attempt to fix this by having `get_next()` check handle for NULL.
2022-01-17 11:16:07 -06:00
Jeffrey Altman
f466b43975 lib/krb5: fallback_get_hosts free addrinfo if gTLD collision or error
If getaddrinfo() succeeds and returns the gTLD name collision
address the result is ignored but the allocated addrinfo was not
freed.

If allocation of the krb5_krbhst_info structure fails the addrinfo
would also be leaked.

Change-Id: I94111e081cba9548f57ad7b7e7cbea3faab7502c
2022-01-16 19:50:40 -05:00
Jeffrey Altman
8eaecdaa59 lib/krb5: srv_find_realm do not leak 'r' if unreachable
Change-Id: I6e16676c9cb820d6a25820523608cb9854fa2ce4
2022-01-16 17:04:04 -05:00
Nicolas Williams
fb553dde1d krb5: Fix warnings 2022-01-14 17:10:16 -06:00
Luke Howard
47282cae34 krb5: import Heimdal-597.121.1 AS/TGS client
Sync with most changes in AS/TGS client from Apple's Heimdal-597.121.1
(opensource.apple.com).

Changes include:

 - FAST support in TGS client
 - Refactored pre-auth client to be more easily extensible
 - Pin KDC host and AD site name in API calls

Note the completely refactored TGS client loop is not imported as that was
considered too intrusive.
2021-12-14 09:03:42 +11:00
Luke Howard
3ac48a8dfd krb5: KRB5_KRBHST_TKTBRIDGEAP
Add a new krbhst type, KRB5_KRBHST_TKTBRIDGEAP to krb5_krbhst_init_flags(),
that looks for the DNS SRV record kerberos-tkt-bridge. This is to support a new
PADL project.
2021-09-13 19:20:11 +10:00
Nicolas Williams
ea83f068e9 kadm5/kadmin: Add read-only mode
Now we can have read-only kadmind instances.
2020-09-08 00:25:40 -05:00
Nicolas Williams
0a0bf32935 krb5: Fix leak in gethostlist() 2020-09-07 22:04:59 -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
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
Andrew Bartlett
2ea34666d9 heimdal: Fix printing a short int into a string
The size of portstr is too small to print an integer.

Instead just let snprintf do the work.

This fixes building with GCC 7.1

Based on feedback by Jeffrey Altman

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

(Inspired by Samba commit abd74c3ba5e3ee3f5320bff6ed7dff4fbcb79373)

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2018-12-20 12:52:12 +11:00
Nicolas Williams
b2f6ba0fff Revert "lib: Fix printing a short into portstr"
This reverts commit ccb63bb0aa, which was
unnecessary and broke tests/kdc/check-kadmin (and other things).

host->port happens to be an unsigned short, so that promotion to an integer in
the snprintf() call is safe in that the promoted value will still be
non-negative, and no larger than an unsigned short's maximum value.  We're
still assuming that 7 bytes is sufficient to hold the text representation of
that maximum value, which indeed it is, assuming sizeof(unsigned short) == 2
and CHAR_BIT == 8, which are fair assumptions here.  A better patch, if we
needed it, would be to just make portstr[] an array of 11 char, or perhaps make
it a VLA (but we can't yet use VLAs, I don't think, because of older Windows
systems that must be supported still).
2017-10-05 10:43:42 -05:00
Andreas Schneider
ccb63bb0aa lib: Fix printing a short into portstr
The size of portstr is too small to print an integer and we should print
a short anyway.

This fixes building with GCC 7.1
2017-09-25 18:16:18 -05:00
Nicolas Williams
3ba12317a0 Misc fixes (coverity) 2016-11-28 15:09:55 -06:00
Nicolas Williams
616aaf95a8 Don't suppress DNS search list by appending '.'
The original motivation was to avoid extra timeouts when the network is
broken.  However this doesn't avoid one of the timeouts and adds
complexity and introduced bugs.

To really suppress search lists use ndots.
2016-11-10 13:17:19 -06:00
Nicolas Williams
13cb3b5646 Don't inhibit /etc/services matches 2016-11-09 22:49:03 -06:00
Nicolas Williams
6a68376a33 Don't inhibit /etc/hosts matches (fix #32)
Apending '.' to the hostname passed to `getaddrinfo()` is good for
avoiding extra timeouts when the search list is non-empty and the
network is broken, but searches in /etc/hosts are typically inhibited
then.  The fix is to try again without the trailing '.' if the first
lookup failed for any reason other than a timeout.
2016-11-09 22:49:03 -06:00
Jeffrey Altman
cc62c1a4ae lib/krb5: fix srv_find_realm invalid gTLD test
In srv_find_realm() the conditional for testing whether an entry
is the invalid gTLD response was inverted.  Refactor the conditional
into a helper function is_invalid_tld_srv_target().  Use the helper
to simplify the conditional making it easier to confirm that the
test is correct.

Change-Id: I3220753b5585ac535862c4617030377c7a1f4bbe
2016-04-13 18:52:55 -05:00
Jeffrey Altman
13568961ec krb5: DNS A record fallback test for invalid gTLD
As per
https://www.icann.org/en/system/files/files/name-collision-mitigation-01aug14-en.pdf
prior to a new top-level domain being put into service there is controlled
interuption service which will return explicit responses to DNS A, MX, SRV, and TXT
queries that can be used to detect private namespace collisions.

When performing fallback_get_hosts() check the AF_INET responses to ensure
that they are not the gTLD name collision address 127.0.53.53.  If so, add
an error message to the context and return KRB5_KDC_UNREACH.

Write a warning to the log (if any).

Change-Id: I2578f13948b8327cc3f06542c1e489f02410143a
2016-04-10 17:05:07 -05:00
Jeffrey Altman
4b45355162 krb5: DNS SRV records test for invalid gTLD
As per
https://www.icann.org/en/system/files/files/name-collision-mitigation-01aug14-en.pdf
prior to a new top-level domain being put into service there is a
controlled interuption service which will return explicit responses to DNS
A, MX, SRV, and TXT queries that can be used to detect private namespace collisions.

Modify SRV records lookups to detect the special hostname returned in the
SRV response, skip the response, and record an appropriate error if it is detected.

Write a warning to the log (if any).

Change-Id: I47e049b617e39e49939bc92d513a547de1d04624
2016-04-10 17:05:07 -05:00
Jeffrey Altman
5f138a16ef libkrb5: Add missing KRB5_LIB_FUNCTION/KRB5_LIB_CALL
KRB5_LIB_FUNCTION and KRB5_LIB_CALL are necessary even on private
functions that are exported.

Change-Id: Iccd0cfe87ff0a9d851e29890e9cb55b3ae517ce1
2013-06-22 21:17:32 -04:00
Roland C. Dowdeswell
f0f07ff408 Use krb5_enomem() more consistently in lib/krb5. 2013-02-13 16:15:00 +08:00
Love Hornquist Astrand
58ff480763 rewrite send to kdc to be more agressive, try kdcs in paralell and easier to configure behavior 2013-02-10 19:02:52 -08:00
Love Hornquist Astrand
dff11de56b use new plugin system for locate kdc plugins (30 as-req/s faster for kdc-tester on MacBookAir5,2) 2012-12-27 12:23:29 +01:00
Love Hornquist Astrand
0879b9831a remove trailing whitespace 2011-05-21 11:57:31 -07:00
Love Hornquist Astrand
1072afd6bf Andrew Bartlet pointed out that the patch was incomplete, update and write doxygen. 2010-09-30 00:44:35 -07:00
Love Hornquist Astrand
f454f45fbf If the hostname contains a dot, assumes it's a FQAN and don't use
search domains since that might be painfully slow when machine is
disconnected from that network.

Found by Tridge
2010-09-28 22:37:01 -07:00
Love Hornquist Astrand
788189805c catch error from as.*printf 2010-05-30 13:28:49 -07:00
Love Hornquist Astrand
687db64c56 Patch from Secure Endpoints/Asanka Herath for windows support 2009-12-21 08:45:28 +01:00
Love Hornquist Astrand
4c06438189 Add _krb5_krbhst_get_realm() to get what realm was used 2009-09-07 20:54:48 -07:00
Love Hornquist Astrand
6770fd45e1 Sprinkle _krb5_debug() for more info about what the framework is actually doing behind our back 2009-09-07 20:22:44 -07:00
Love Hornquist Astrand
ede8ad11ad Support IPv6 numeric style addresses, example [2001:10:300::1]:88 2009-08-14 04:34:10 +02:00
Love Hörnquist Åstrand
db149370e1 dns: switch to rk types
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24893 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-03-22 17:18:55 +00:00
Love Hörnquist Åstrand
bd5229d126 prefix dns_ symbols
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24883 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-03-22 17:17:02 +00:00
Love Hörnquist Åstrand
c2c1e95ccf dont increment nhost since its no longer used
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24852 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-02-27 03:29:58 +00:00
Love Hörnquist Åstrand
3767202e6e drop RCSID
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24359 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-01-25 00:31:10 +00:00
Love Hörnquist Åstrand
50d02c49b9 Only claime configuration exists if the plugin returned some useful data.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23816 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-09-13 09:43:32 +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
c808db85c0 N_()ify
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23786 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-09-07 21:27:47 +00:00
Love Hörnquist Åstrand
dbc55c9bec indent
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23447 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-07-27 12:09:05 +00:00