Commit Graph

30292 Commits

Author SHA1 Message Date
Nicolas Williams
a56382ce4d kcm: Treat default name as alias
Both MIT and Heimdal are unable to, in krb5_cc_default(), call to KCM
(or CCAPI, or LSA, or...) to get the user's default ccache name in their
collection.  Instead, the default ccache name is obtained in a static
way, and for KCM that's "%{UID}".  When we krb5_cc_switch(), we simply
maintain a pointer to the name of the ccache that was made the default,
but klist can't make use of this because krb5_cc_default() can't.

The solution here is to first try resolving the ccache name given by the
client, and if that fails but the name happens to be what would be the
library's default KCM ccache name for that user, then try resolving it
through the default ccache name pointer saved at switch time.
2022-01-25 01:17:04 -06:00
Nicolas Williams
727682ec41 krb5: Fix KCM/API ccache type name confusion
Wrap all KCM cc ops that need to call kcm_alloc() so that they pass in
the cc ops pointer that they're associated with so that kcm_alloc() can
use the correct ccache type name if needed.
2022-01-25 01:16:08 -06:00
Nicolas Williams
c44f94fa7e krb5: Use krb5_enomem() in KCM 2022-01-24 22:11:49 -06:00
Nicolas Williams
2a7095971a krb5: Fix cccol support in KCM 2022-01-24 22:11:35 -06:00
Nicolas Williams
2137f0c28e kcm: Do not clobber error from server 2022-01-24 18:27:35 -06:00
Nicolas Williams
f3517c0d01 ipc: Handle POLLIN/OUT even when ERR 2022-01-24 18:26:55 -06:00
Nicolas Williams
5bb5033f10 krb5: "KEYRING:" should work 2022-01-24 15:38:47 -06:00
Nicolas Williams
c4236f23bd krb5: Fix segfault in KCM ccache type 2022-01-24 13:52:36 -06:00
Nicolas Williams
f5180f6776 kimpersonate: Fix typo 2022-01-24 13:51:43 -06:00
Jeffrey Altman
eb08f2ecdd kdc: _kdc_find_etype if is_preauth must use long term keys
is_preauth (KFE_IS_PREAUTH is set) might require replying with
PA-ETYPE-INFO[2] which requires use of the long-term keys.
Without this change is_default_salt_p() can be called with 'key'
eq NULL.

Change-Id: I513fa768680225d4501d8b390e349a011666d90c
2022-01-24 10:41:51 -05:00
Jeffrey Altman
31d5c38976 lib/hcrypto: mpz2BN return NULL if mp_ubin_size(s) returns zero
If mp_ubin_size(s) returns zero then mp_to_ubin() will fail and
not return MP_OKAY.  If MP_OKAY is not returned, NULL is returned
to the caller of mpz2BN().

This change avoids the unnecessary memory allocation and function
calls.  It also removes a dereference after null warning from
coverity.

Change-Id: I52ff2c166964e41cb4eef1dac637904bf2bf13bf
2022-01-24 10:14:17 -05:00
Jeffrey Altman
d8dcb3f7a4 kuser: generate-requests read_words fix sizeof_mistmatch
Use 'sizeof(*w)' to compute the correct size passed to erealloc().
Although sizeof(char **) == sizeof(char *), it is not guaranteed.

Change-Id: I5f66fafe20343d7e736922038d24abcd48bab8bd
2022-01-24 10:02:26 -05:00
Jeffrey Altman
ee56cb33b2 lib/asn1: prevent wrong size argument warnings
190263bb7a
("assert non-NULL ptrs before calling mem funcs") introduced
two wrong size argument warnings.  These locations are not
errors since the allocation is simply to ensure that the
data pointer is non-NULL; length is zero.

Change-Id: I7b3b58247799a48da3653008c7b6d7fbbbf83e25
2022-01-24 00:31:27 -05:00
Jeffrey Altman
190263bb7a assert non-NULL ptrs before calling mem funcs
The definitions of memcpy(), memmove(), and memset() state that
the behaviour is undefined if any of the pointer arguments are
NULL, and some compilers are known to make use of this to
optimise away existing NULL checks in the source.

Change-Id: I489bc256e3eac7ff41d91becb0b43aba73dbb3f9
Link: https://www.imperialviolet.org/2016/06/26/nonnull.html
2022-01-24 00:07:51 -05:00
Jeffrey Altman
d35c9b2d67 lib/gssapi/ntlm: _gss_ntlm_inquire_cred dead code removal
do not check 'cred_handle' for GSS-C_NO_CREDENTIAL twice.

Change-Id: I3629aa49b2d20d3444c6ede46715d65b6072484f
2022-01-23 23:11:46 -05:00
Jeffrey Altman
ca4ff365f8 lib/gssapi/mech: gss_mech_switch do not leak 'm'
If there is a memory allocation failure after 'm'
is allocated, 'm' will be leaked; free it.

Change-Id: I625273634af207fac7c489df166cebde4d467cbc
2022-01-23 23:07:36 -05:00
Jeffrey Altman
693191b23d lib/kadm5: kadm5_c_randkey_principal check store_int return
do not ignore failures to krb5_store_int() ks_salttype.

Change-Id: I4144376f24ac00f45073daec4fa5835706b1ad09
2022-01-23 22:49:57 -05:00
Jeffrey Altman
d80a1b9556 kdc: hprop propagate_database do not leak 'server'
Change-Id: I0b2b6343134603ecffb6cd827d0828463378cff4
2022-01-23 22:25:43 -05:00
Jeffrey Altman
a3f4a0bf0b kdc: hprop check return code if local realm
If 'local_realm' is true, must protect against failure
of krb5_get_default_realm() and krb5_principal_set_realm().
Otherwise, the wrong realm might be used.

Change-Id: Ib7a92559da1ac062c71228c5530106a13d836d53
2022-01-23 21:59:13 -05:00
Jeffrey Altman
0a17a0b3b7 lib/asn1: der_put_length test 'size' is non-NULL
Change-Id: I1ffbf1998485fdca7cf151c24c440fb0b35e77e4
2022-01-23 21:47:58 -05: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
Jeffrey Altman
38536d7313 lib/asn1: set *size output to zero at start of der funcs
Assign zero to the output size parameter at the start so that
callers that use the value when an error occurs do not see
garbage that might be misinterpreted.

Change-Id: Iccfcf4f6944b1bf72789c83919901d9b9d6f9153
2022-01-23 00:10:14 -05:00
Roland C. Dowdeswell
8dcd05ed4d _gss_ntlm_init_sec_context() mem leaks 2022-01-22 21:54:20 -05:00
Roland C. Dowdeswell
e87fca8091 _gss_ntlm_delete_sec_context() mem leaks 2022-01-22 21:54:20 -05:00
Roland C. Dowdeswell
8526b4c627 fix memory leak near NTLM type2 response 2022-01-22 21:54:20 -05:00
Nicolas Williams
d64076dfd9 asn1: Update commentary on grammar 2022-01-22 03:48:27 -06:00
Nicolas Williams
dfc26ae8c1 asn1: Fix last remaining shift/reduce conflict 2022-01-22 03:48:27 -06:00
Nicolas Williams
563964ce96 hx509: Use %left for ! instead of %precedence 2022-01-21 23:34:40 -06:00
Nicolas Williams
88e31d2da8 sl: Add missing sel-gram.h target 2022-01-21 23:15:21 -06:00
Nicolas Williams
cb9b1842ea sl: Fix bison/byacc invocation 2022-01-21 23:01:44 -06:00
Nicolas Williams
20497ed2d4 com_err: Fix bison/byacc invocation 2022-01-21 23:01:44 -06:00
Nicolas Williams
664b749399 hx509: Fix sel-gram.y shift/reduce conflicts
AND and OR are now binary operators, left-associative, with AND having
higher precedence than OR.

The not operator is now higher-precedence than the AND and OR operators.
2022-01-21 22:58:22 -06:00
Nicolas Williams
e1fa08a4d6 asn1: Fix 5 shift/reduce conflicts
There remains one tough shift/reduce conflict, the warning for which is
quieted with an `%expect 1` directive.

The remaining conflict has to do with whether a constraint attaches to
the inner type that some other outer type is a SET OF or SEQUENCE OF or
tagged-type of, or whether it attaches to the outer type.  The two are
really the same thing.  The latter is the reduce side, so it's not used,
but if it were we could grab the constraint in the action and attach it
to the inner type anyways.
2022-01-21 22:37:05 -06:00
Nicolas Williams
f0f6bb03f4 hdb: Lower-case HDB_DB_FORMAT to make it valid ASN.1
In order to resolve some shift/reduce conflicts in the ASn.1 compiler's
grammar we need to be strict about value names starting with lower case
and type names starting with upper-case.
2022-01-21 22:37:05 -06:00
Nicolas Williams
37f10aaf85 cf: Restore AC_KRB_PROG_YACC to life
Using `AC_PROG_YACC` means accepting that `bison` gets invoked in yacc
compatibility mode (i.e., with the `-y` command-line option).  In recent
versions Bison has started to warn about use of Bison extensions when in
yacc compatibility mode -- even for things yacc itself accepts but which
it doesn't document.

I've confirmed that `bison -d` and `byacc -d` both work for the ASN.1
compiler.
2022-01-21 22:37:04 -06:00
Luke Howard
366878c230 kdc: kdc_request_add_pac_buffer() make pactype unsigned
The pactype argument to kdc_request_add_pac_buffer() should be unsigned,
matching krb5_pac_add_buffer(). Reindent.
2022-01-22 11:43:38 +11:00
Jeffrey Altman
dafbfa666f kadmin: add_one_principal avoid shadow warning
8dcc5e617b
("kadmin: add_one_principal refactor") made 'princ_name' a
top-level variable.  This precludes the need to declare
subsequent block-level variables with the same name.

Change-Id: I4bf9e54b49a0e366ed4cd39920d3fe58439beb33
2022-01-21 10:39:57 -05: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
02bd267fbd kadmin: kadmind_dispatch fix broken commit
124b8d0f78 ("kadmin: kadmind_dispatch
do not write NULL 'rsp' to 'out'") was committed with an
unintentional source code removal.

Change-Id: I3de21e3624d713a9b5a1e89d147a5db5f1f55ab1
2022-01-21 09:24:34 -05:00
Jeffrey Altman
124b8d0f78 kadmin: kadmind_dispatch do not write NULL 'rsp' to 'out'
1b213c1082 ("kadmind: Add missing
error checks") altered the behavior of kadmin_dispatch() such that
it unconditionally called

      krb5_storage_to_data(rsp, out);

This change was unsafe because krb5_unparse_name_fixed() failure
would skip the allocation of the 'rsp' and 'sp' krb5_storage
objects.

This change allocates the krb5_storage objects prior to performing
any work.  If either of them fail, kadmin_dispatch() immediately
returns ENOMEM.

Change-Id: I14fd96afe029a4e74bb769605286ca0e17d25043
2022-01-21 09:16:35 -05:00
Jeffrey Altman
251cbf05c2 Revert "kadmin: kadmind_dispatch do not write to 'out' on error"
This reverts commit fb52fd1c53.

The change caused tests/kdc/check-kadmin to fail.
2022-01-21 09:04:31 -05:00
Jeffrey Altman
cd91a3a03e appl/afsutil: expand_cell_name return NULL if not found
In function ‘afslog_cell.isra’:
  afslog.c:144:13: warning: ‘%s’ directive argument is null [-Wformat-overflow=]
  144 |            warnx("No cell matching \"%s\" found.", cell);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

caused by expand_cell_name() returning the input pointer.
Alter the behavior of expand_cell_name() to match its usage.

Change-Id: I3b15c4b3e59b597af5351e5e62f5d7751be50feb
2022-01-21 08:51:28 -05:00
Jeffrey Altman
8dcc5e617b kadmin: add_one_principal refactor
If rand_password is true, allocate princ_name early to prevent
memory allocation errors after the principal was added.

Use memset_s to clear the 'password' so that it will not be
optimized away.

Change-Id: I80d11546166d2350e6a79c5a376cb9e8cb191fa3
2022-01-21 00:44:10 -05:00
Jeffrey Altman
912b20c4d7 kadmin: refactor set_random_password
Obtain the unparsed principal name early so that there is no
risk of memory allocation failure after kadm5_chpass_principal_3()
succeeds.

Change-Id: I389281004826da5752081c2f26127d55e3dc3989
2022-01-21 00:31:56 -05:00
Jeffrey Altman
fb52fd1c53 kadmin: kadmind_dispatch do not write to 'out' on error
1b213c1082 ("kadmind: Add missing
error checks") altered the behavior of kadmin_dispatch() such that
it unconditionally called

  krb5_storage_to_data(rsp, out);

Previously kadmin_dispatch() only wrote to 'out' on success.
Doing so is important because 'rsp' might be NULL on error.

Change-Id: I2688a5c47db0f94d955971e785037c578d3f3fa4
2022-01-21 00:25:15 -05:00
Jeffrey Altman
4ffd190b08 kadmin: kadmind_dispatch fix handling of HEIM_ERR_EOF error
1b213c1082 ("kadmind: Add missing
error checks") altered the scope of the

   if (ret == HEIM_ERR_EOF)
      ret = 0;

treatment of HEIM_ERR_EOF as a success code.  Prior to that
commit HEIM_ERR_EOF meant success only when reading the 'keepold'
value.  It indicated a premature failure if returned when reading
'princ' or 'n_key_data'.

This change corrects the scope of HEIM_ERR_EOF indicating success.

Change-Id: If5463b47dc3eabee6fa2f8e717147f02adc1586c
2022-01-20 23:43:06 -05:00
Jeffrey Altman
81f3a0b804 lib/hdb: ndbm correct asprintf error handling
asprintf() return code must be checked because in case of failure
the value of the output buffer variable is undefined.

Change-Id: I75e06fffe2330ec10dbe4f678479ded479ab5931
2022-01-20 23:33:11 -05:00
Jeffrey Altman
2e54dc7aae lib/hcrypto: DES_cfb64_encrypt init buffer in decrypt path 2022-01-20 21:29:11 -05:00
Luke Howard
8946f0de9d gss_preauth: remove dead code
The intent was to map KRB5KRB_AP_ERR_BAD_INTEGRITY and HNTLM_ERR_AUTH to
KRB5KRB_AP_ERR_BAD_INTEGRITY, but this code was never reached.
2022-01-21 10:09:44 +11:00
Luke Howard
fce4d19953 kdc: declare calling/linkage conventions for accessors
Decorate generated accessors with KDC_LIB_FUNCTION/KDC_LIB_CALL for correct
linkage on Windows.
2022-01-21 08:22:07 +11:00