Commit Graph

123 Commits

Author SHA1 Message Date
Daria Phoebe Brashear
133f517482 rewrite fallthrough to HEIM_FALLTHROUGH to deal with new Apple SDKs
Apple clang version 14.0.0 (clang-1400.0.17.3.1) fails the build
because stds.h defines `fallthrough` as a macro which is then
expanded when base.h evaluates

  # if __has_attribute(fallthrough) && __clang_major__ >= 5

The macOS SDK defines `DISPATCH_FALLTHROUGH` as the macro instead
of `fallthrough`.

This change replaces the use of `fallthrough` in the tree with
`HEIM_FALLTHROUGH` and updates the declaration in configure logic
to define `HEIM_FALLTHROUGH` based upon existing definitions
(if any) of `fallthrough` or `DISPATCH_FALLTHROUGH`.
2022-09-16 15:58:45 -04:00
Jeffrey Altman
543b94637f more dealloc functions require HEIM_CALLCONV
Change-Id: I68168a387c088b45e2572d5c982d33dfe0aa38a8
2022-01-29 00:15:59 -05:00
Luke Howard
917e16049a base: make heim_alloc deallocator use HEIM_CALLCONV 2022-01-28 17:24:57 -06:00
Jeffrey Altman
04527412e3 Follow the Linux kernel's lead on "fallthrough"
The pseudo keyword 'fallthrough' is defined such that case statement
blocks must end with any of these keywords:
 * break;
 * fallthrough;
 * continue;
 * goto <label>;
 * return [expression];
 *
 *  gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes

The macro is defined either as

  __attribute__((__fallthrough__))

or as

  do {} while (0)  /* fallthrough */

not including the semicolon.

This change implements the Linux kernel style and updates several locations
where "/*fallthrough*/ and /* FALLTHROUGH */ were not previously replaced.

Externally imported code such as libedit, libtommath and sqlite are
restored to their unaltered state.

Change-Id: I69db8167b0d5884f55d96d72de3059a0235a1ba3
2022-01-21 10:39:47 -05:00
Jeffrey Altman
5fa0b7b6ff lib/krb5: krb5_sento_context KRB5_SENDTO_DONE KRB5_SENDTO_FAILED
Let the KRB5_SENDTO_DONE and KRB5_SENDTO_FAILED action states be
handled by the provided switch blocks.   This ensures that the
'ret' value is set appropriately before exiting the loop.

Change-Id: I56f4cea83efd86203a9a7a36cf48c80f632cf779
2022-01-17 23:02:01 -05:00
Nicolas Williams
c607135a03 Use fallthrough statement attribute (moar) 2022-01-14 16:53:34 -06:00
Nicolas Williams
ddc6113610 Use fallthrough statement attribute 2022-01-14 16:32:58 -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
Nicolas Williams
7d50445d1b Generic: Fix warnings (fallthrough mosty) 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
Jeffrey Altman
a1276c54aa krb5_sendto_kdc: Windows no KDC reachable error
The combination of 8740528b24
("Windows-compatible sentinel socket type and value") and
d497d7e4a7 ("krb5_sendto_kdc:
failover for multiple AAAA/A RRs on one domain") broke
all the send to kdc loop on Windows.  rk_socket_t is
a HANDLE and rk_INVALID_SOCKET is the max value.  Therefore,
no valid socket will be larger and all communications
will fail.

Change-Id: I3464f78d67b19f14050ad7a01738fb32bac99385
2019-05-16 12:09:59 -04:00
Viktor Dukhovni
8740528b24 Windows-compatible sentinel socket type and value 2019-05-14 15:52:01 -04:00
Roland C. Dowdeswell
d497d7e4a7 krb5_sendto_kdc: failover for multiple AAAA/A RRs on one domain
We found that the libraries behaviour when dealing with domains with
more than one entry in them is slightly suboptimal.  The situation
was

kdc1		IN	A	1.2.3.4
kdc1		IN	AAAA	ff02::1

I.e. a single hostmame with both IPv6 and IPv4 addresses.  When we
run krb5_sendto_kdc on a box with only IPv4 addresses, there is a
3s delay before it fails back to the IPv4 address.  This is because
the library sets the 2nd address on each hostname to be 3s in the
future and each additional one another 3s.

We change wait_response() s.t. if one is able to make progress, we
iterate over the list of hosts and move them all 1s forward.  We
also modify submit_request() to skip hosts if host_connect() fails.
2019-05-14 15:52:01 -04:00
Luke Howard
1bc2eb33f9 krb5: fix spelling error in debug log 2019-05-14 15:16:19 -04: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
Jeffrey Altman
3a52ba6ed0 lib/krb5: send_to_kdc KRB5KDC_ERR_SVC_UNAVAILABLE infinite loop #346
Prior to this change a KDC response of KRB5KDC_ERR_SVC_UNAVAILABLE
would result in the client looping forever.  Setting the action to
KRB5_SENTO_CONTINUE repeats the current loop without altering the
current state.  Hence the infinite loop.

As of this change, the action is set to KRB5_SENDTO_RESET which
forces the current kdc's response to be cleared and then to retry.
If KRB5KDC_ERR_SVC_UNAVAILABLE continues to be returned, the retry
limit will be reached and the loop will end.

This bug was filed by multiple sources including Samba and ScottUrban
on github.

Change-Id: If1611be0ada3422cefae89541ed3b3df1f6efe29
2018-12-26 17:04:26 -05:00
Viktor Dukhovni
766e6cda8a Avoid potential memory leak in krb5_sendto_set_hostname
If the hostname was already set, a typo in a test meant we were not
freeing it.  While we're at it, handle the unlikely possibility that
the existing pointer is passed as the new value.
2017-08-23 15:10:38 -05:00
Nicolas Williams
9609397874 Misc 64-bit time support (debug message)
Originally by Christos Zoulas.  Originally used %jd and casts to
intmax_t, however, we can't use those on Windows yet.
2017-03-13 18:39:41 -04:00
Nicolas Williams
6a0f45c4d7 Use __attribute__ ((__name__)) form
Protect against macros named noreturn and so on.
2017-03-13 18:39:41 -04:00
Nicolas Williams
3ba12317a0 Misc fixes (coverity) 2016-11-28 15:09:55 -06:00
Nicolas Williams
f38089257b Misc fixes (coverity) 2016-11-20 17:43:51 -06:00
Nicolas Williams
8cdd54c997 coverity 1164162 2015-04-19 15:04:16 -05:00
Viktor Dukhovni
93af13ca12 Undo ntohs htons nesting to avoid variable shadowing 2015-04-14 23:02:58 +00:00
Love Hörnquist Åstrand
37afa01be3 rename roken base64, fixes #107 2014-08-22 20:57:24 -07:00
Andrew Bartlett
9f392c134f heimdal: rename send and recv pointers to avoid conflict with socket wrapper 2014-03-24 23:07:52 -05:00
Jeffrey Altman
6ae305e7a4 Fix send_to_kdc for Windows sockets
Patchset 58ff480763 calls write() and read()
on rk_socket_t objects which on Windows are SOCKETs not C RTL file
descriptors.  This patchset uses krb5_net_write() and krb5_net_read()
in place of the direct write() and read() operations.

Change-Id: I3f7d4756357d432e4e62910f9a36824eb188b6e4
2013-09-12 12:36:39 -04:00
Jeffrey Altman
649a1f8ff3 krb5_sendto_context potentially uninitialized ret
Change-Id: Ia1f54f90900f78f25bb6e0573f707b4d2a7f6055
2013-09-11 01:42:16 -04: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
Love Hornquist Astrand
6850c9ac5d type casting to avoid printf warning 2013-04-24 16:45:24 -07:00
Nicolas Williams
f490acc526 Winsock connect returns WSAEWOULDBLOCK...
...instead of EINPROGRESS.  And we get to call WSAGetLasteError() too boot :(
2013-03-18 23:15:29 -05:00
Nicolas Williams
2c4c6101f4 Fix master (lib/krb5 warnings) 2013-03-05 21:47:20 -06:00
Roland C. Dowdeswell
f0f07ff408 Use krb5_enomem() more consistently in lib/krb5. 2013-02-13 16:15:00 +08:00
Love Hornquist Astrand
6020e6c5b4 make http parser not exit out early 2013-02-10 23:20:37 -08:00
Love Hornquist Astrand
9a5de87ca1 store response in right place 2013-02-10 22:50:10 -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
Roland C. Dowdeswell
3a30f3b0d1 Windows doesn't support poll(2) or fcntl(2) so #ifdef it out in send_to_kdc.c. 2012-08-14 22:50:33 +01:00
Roland C. Dowdeswell
842ca62336 Ensure that timeouts apply to TCP socket connexions.
Currently the Heimdal code calls connect(2) on TCP connexions to
the KDC without setting O_NONBLOCK.  This code implements a
timed_connect() function which will in the case of SOCK_STREAM
sockets put the socket into non-blocking mode prior to calling
connect and use select(2) to apply the configured timeout to connect
completion.  This does not entirely solve the problem of potential
timeouts in the code as it is still possible to block while writing
to the socket.  A proper implementation would also likely start
new connexions after a short interval before timing out existing
connexions and return the results from the first KDC which successfully
responds but we did not do that yet.

This patch is from heimdal-1-5-branch patches:

	5b55e4429caed27b32aac4bc5930f2672a43f273
	6b66321b271ee4672e70ad349ec796dd755cf897
	2e12c7f3e8dca7e1696ebd92199617ce413565e7

Squashed together along with a quick shadowed variable warning fix
to allow it to compile with --enable-developer.
2012-07-12 01:00:23 +01:00
Roland C. Dowdeswell
abdde6a608 Additional changes to make -Wshadow build on Ubuntu 10.04.
Looks like they defined basename() in string.h and ntohs/htonl are
implemented in terms of __bswap16() which is a macro with tmp
variables and so one cannot embed one call to ntohs/htons in another.
Not good but we workaround this limitation in glibc.
2012-06-07 16:59:01 +01: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
Asanka Herath
5dcc605f6b Fix calling conventions for Windows 2010-08-20 13:14:10 -04:00
Love Hornquist Astrand
077357c848 catch error from as.*printf 2010-05-30 13:37:07 -07:00
Love Hornquist Astrand
deee0bbad9 put SOCK_CLOEXEC in the right argument, from Harald Barth 2010-01-25 23:01:09 -08:00
Love Hornquist Astrand
4182a61eba rename closesocket to rk_closesocket 2009-12-22 09:03:05 +01:00
Love Hornquist Astrand
d1d0de730d refix socket wrappers with rk_ 2009-12-21 08:50:46 +01: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
9120d17eb0 Tell some what servers we tried to talk to 2009-09-07 20:55:05 -07:00
Love Hörnquist Åstrand
942a821fab remove RCSID
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25171 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-05-04 06:17:40 +00:00
Love Hörnquist Åstrand
03e7b2d3a5 add timeout to krb5_send_to_kdc_func, from metze
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24969 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-03-27 15:01:47 +00:00
Love Hörnquist Åstrand
f9e2c569f9 make _krb5_copy_send_to_kdc_func handle no set functions
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23927 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-10-18 21:16:03 +00:00