Fix unlikely memory error in krb5_rd_cred

If an error occurs in the for loop in krb5_rd_cred_basic (which should
only happen on an ENOMEM), do not leave the caller with a dangling
reference to the freed credential array.

ticket: 7908 (new)
target_version: 1.12.2
Allow GSS mechs to force mechlistMIC in SPNEGO

During a SPNEGO negotiation, if the NTLMSSP mechanism is used and a
MIC is produced within the final initiator mechanism token, Microsoft
servers require a mechlistMIC even if NTLMSSP was the most preferred
mechanism.

In spnego_mech.c, add a helper function mech_requires_mechlistMIC
which queries the mechanism to determine whether we might need to
produce a mechlistMIC for interoperability.  Call it after each call
to the mechanism's gss_init_sec_context and set sc->mic_reqd if it
returns true.  Although only the second call to NTLMSSP will actually
ever return true, the first call makes the mechanism aware that the
SPNEGO implementation supports this feature.

[ghudson@mit.edu: clarified commit message and code]

ticket: 7907 (new)
Add k5_buf_get_space

Add a new k5_buf method to make room in the buffer for the caller to
fill in.
Add k5-input.h

Add a header containing a declaration for struct k5input and static
inline functions to use it.  A k5input structure can be used to safely
extract bytes and integers from a fixed-sized input buffer without
overrunning the buffer.  It supports deferred error checking (similar
to k5buf) by returning dummy values and storing a status value in the
input structure.
Add cred marshalling functions

Add a new file ccmarshal.c containing functions to marshal and
unmarshal credentials in file formats version 1-4.  These will replace
the functions in cc_file.c and cc_keyring.c, and can be used for KCM
in the future.
Add ccache marshalling tests

Add a new ccache test program t_marshal.c which verifies the new
marshalling functions and also the FILE ccache type against the
expected representations of the ccache header, default principal, and
credentials.
Modernize cc_file.c and cc_keyring.c

Rename functions not to use the krb5_ prefix, and to use the fcc_ or
krcc_ prefixes only for ccache method implementations.  Use shorter
function comments and add missing comments in some cases.  Remove
forward declarations where they aren't needed.  Use native types
(uint16_t, void *, etc.) in preference to Kerberos type wrappers.  Use
"ret" as the variable name for krb5_error_code return values.  Use 0
instead of KRB5_OK.  Make whitespace conform to current practice.
Remove old #if 0 blocks.  Don't cast to and from void * or between
integer types when C guarantees an implicit cast.  Use literal 2 and 4
for the size of fixed-width 16-bit and 32-bit types.

In cc_file.c, rewrite the header comment to fully specify the file
format and update it to include all of the changes in versions 2-4.
Also add a helper function to return the cache version as an integer
from 1 to 4, allowing more concise version checks.
Use cred marshalling functions in cc_file.c

Replace the cc_file.c credential and principal marshalling and
unmarshalling functions with calls to the ccmarshal.c functions.  For
unmarshalling, we still need code to read the appropriate amount of
data into a memory buffer.  Because there is no outer length header
for principals and credentials, this code needs to understand the
credential and principal representations, but is much simpler than the
old code as it only needs to store the data it reads, not assemble a
data structure.
Use cred marshalling functions in cc_keyring.c

Replace the cc_keyring.c credential and principal marshalling
functions with calls to the ccmarshal.c functions.  Simplify the
remaining parsing functions (for the index and time offsets) and fold
the resulting code into the calling functions where appropriate.