Always stat profile files after reopening them

Some applications write a profile file and then immediately use it via
a krb5_context.  If we have a cached copy of the profile we wrote,
make sure to update it by forcing a stat when we reuse an existing
prf_data_t object.

[ghudson@mit.edu: commit message]

ticket: 7884
Don't check kpasswd reply address

Don't check the address of the kpasswd server when parsing the reply
we received from it.  If the server's address was modified by a proxy
or other network element, the user will be incorrectly warned that the
password change failed when it succeeded.  The check is unnecessary as
the kpasswd protocol is not subject to a reflection attack.

[ghudson@mit.edu: edit commit message]

ticket: 7886 (new)
Make use of strtoul() unconditional in locate_kdc

When parsing port numbers, we previously attempted to conditionalize use
of strtoul() on whether or not it was available, falling back to atoi()
instead, but we did so in a way that would always fall back to using
atoi().  We also call strtoul() from elsewhere without that condition,
so we don't gain anything by trying to be careful about it here.
Fix a harmless DNS glue macro bug

The definition of SAFE_GETUINT16 mistakenly uses "p" instead its ptr
parameter in three places, which happens to work because all current
invocations of the macro use "p" as the ptr argument.  Fix it to
correctly use the ptr parameter.

[ghudson@mit.edu: commit message]

ticket: 6845
Stop shadowing id-pkcs7-data OID

pkinit_crypto_openssl.c currently creates a shadow entry for
id-pkcs7-data so that OpenSSL will expect to see the corresponding
octet string in d.other instead than d.data.  This shadowing is very
unfriendly to other uses of OpenSSL and we should stop.  Eliminate the
shadowing and rewrite create_contentinfo so that it sets up the PKCS7
object correctly if the OID is id-pkcs7-data.

ticket: 7889
Use anonymous OIDs in pkinit_crypto_openssl.c

Stop adding OIDs to the global OpenSSL table.  It isn't thread-safe
(even with locking callbacks registered), and calling OBJ_cleanup
could break other uses of OpenSSL.  Instead, use anonymous OIDs
created with OBJ_txt2oid.  Anonymous OIDs need to be managed more
careful to avoid double-freeing, so create a copy before calling
PKCS7_add_signed_attribute, and don't free the result of
pkinit_pkcs7type2oid in cms_contentinfo_create.

ticket: 7889
Modernize default_state.c

Use alloc_data() and empty_data() where appropriate.  Keep mainline
logic to the left where possible.  Name the output parameter of
krb5int_des_init_state with an _out suffix.  Use a professional tone
in comments.  Partly based on a patch from Alok Menghrajani.
Fix minor typo in options2configure.rst

--with-crypto=openssl is incorrect; it's --with-crypto-impl=openssl.

[ghudson@mit.edu: wrap source line at 70 columns; improve grammar of
the next sentence]
Update example kadmin getprinc enctype display

In kadmin_local.rst, update the example to reflect the new way we
display enctypes after #5014.

ticket: 7890 (new)
target_version: 1.12.2
tags: pullup
Improve salt type display in kadmin getprinc

In krb5_salttype_to_string, output the salt type name we would
recognize as input.

In the output of getprinc, display the enctype and salt type in a form
we would accept--either enctype:salttype if the salt type is not the
default, or just the enctype if it is.

Update t_mkey.py and t_salt.py to expect the new output format.
Update documentation examples to show the new format.

ticket: 5958
Don't free cred handle used in kadm5 server handle

At the end of setup_gss(), gss_client_creds is released, but an alias
to the credential handle is saved in kadm5_server_handle_t in
handle->clnt->cl_auth->(struct rpc_gss_data *)ah_private->sec.cred.
Accessing these credentials (by authgss_refresh) can result in use
after free.

This fix stores credential reference in server handle and releases
the credentials in kadm5_destroy.

[ghudson@mit.edu: initialize handle->cred to correct constant; get rid
of gss_client_creds variable; clarify commit message slightly]

ticket: 7891 (new)
Fix t_seqstate build with Solaris compiler

The Solaris native compiler (as of version 5.9) outputs code for
static inline functions even if they are not used.  So the
k5buf_to_gss helper in gssapiP_generic.h causes t_seqstate to have a
dependency on libkrb5support.

ticket: 7872
Get getopt from unistd.h (not getopt.h) in tests

POSIX defines getopt to be declared in unistd.h, and HP-UX (as of
version 11.31) does not appear to have getopt.h.  In test programs
which currently include getopt.h and aren't currently built on
Windows, include unistd.h or just assume we will get it via k5-int.h.

ticket: 7894 (new)
target_version: 1.12.2
tags: pullup
Refactor cm functions in sendto_kdc.c

Move get_curtime_ms and the cm functions near the top of the file
right after structure definitions.  Except for cm_select_or_poll,
define each cm function separately for poll and for select, since the
implementations don't share much in common.  Instead of
cm_unset_write, define cm_read and cm_write functions to put an fd in
read-only or write-only state.  Remove the ssflags argument from
cm_add_fd and just expect the caller to make a subsequent call to
cm_read or cm_write.  Always select for exceptions when using select.
(Polling for exceptions is implicit with poll).

With these changes, we no longer select/poll for reading on a TCP
connection until we are done writing to it.  So in service_tcp_fd,
remove the check for unexpected read events.
Fix leak in kadm5_flush with LDAP KDB

Due to an inverted test in adb_policy_init, kadm5_flush calls
krb5_db_open twice.  With the DB2 KDB module, the second open is a
no-op, but with the LDAP module, a new DB handle is allocated and the
old one is leaked.

[ghudson@mit.edu: rewrote commit message]

ticket: 7897 (new)
target_version: 1.12.2
tags: pullup
Remove adb_policy_init and adb_policy_close

Since f72c3ffa the policy is initialized as part of database.
adb_policy_close is now a no-op, and adb_policy_init just makes sure
the database is initialized.  adb_policy_init is only called from
kadm5_flush, and only if database initialization was successful
beforehand, rendering this call redundant.

Remove adb_policy_init and adb_policy_close and all their references
in the code and documentation.
Fix sendto_kdc.c on OS X after cm refactoring

Treat POLLHUP without POLLIN or POLLOUT as an exception in the poll
version of cm_get_ssflags, to correctly handle TCP connection errors
on OS X.
Call OpenSSL initialization functions once only

Using library initializers to prevent multiple threads, that run
PKINIT plugin initialization code, from concurently initializing
OpenSSL functions. For cases where MT-safety is not assured by
registering OpenSSL locking callbacks, this significantly lowers the
odds of crashes caused by races in OpenSSL initialization. (If
OpenSSL initialization functions are called by some other thread
directly, crashes are still possible.)

The finilizer code is intentionally not freeing OpenSSL resources in
case PKINIT plugin was being unloaded but OpenSSL lib was not. In
certain cases this can leak memory, but on systems where OpenSSL lib
never gets unloaded it is not an issue.