Commit Graph

120 Commits

Author SHA1 Message Date
Jeffrey Altman
ef8e4da010 only perform dir separator normalization for file paths
Commit ad7e54d698 introduced the use
of _krb5_expand_path_tokens() to expand tokens (and on Windows convert
path delimiters) within credential cache names.  This is safe to do
for the path based credential cache types FILE, DIR and SCC but on
Windows is unsafe for the non-path types.

For example on Windows, the API credential cache names are often based
on the principal name and the principal name is parsed from the ccname.
This practice was introduced with the version v2 ccapi when there was
no method of enumerating the caches from the krb5 library.

This change adds a "filepath" boolean parameter to _krb5_expand_path_tokens()
which is set to TRUE (non-zero) when the input is a file path and FALSE
(zero) when the input is not a file path.  _krb5_expand_path_tokens() will
only perform directory separator normalization on Windows when the
"filepath" parameter is TRUE.

This change is not the preferred solution because it requires that the
library be aware of all credential cache types that use path based
residuals.  The preferred solution would require that the credential cache
implementation indicate whether or not it uses a path based residual.

This change has been implemented using a prefix test and not a change to
struct krb5_cc_ops because existing ccache plugins will not know how to
advertise their use of path based residuals and that path expansion is
safe.

Change-Id: I8135991e8ce69fc5273d381ea9c2078bc2bcd19a
2015-01-07 14:43:19 -05:00
Love Hörnquist Åstrand
d1cee9a14b now that use used up more then 16 flags and we have been using the right bit order for many years, lets stop dealing with broken bit fields from ticket flags 2014-08-23 18:48:34 -07:00
Nicolas Williams
c9f65fc942 env KRB5CCNAME=/tmp/foocc kinit ignores the env
The problem is that fcc_get_cache_next() is called in a context where
context->default_cc_name is not set.  We should call
krb5_cc_default_name(), and that fixes the problem.  There's a comment
warning that this can result in reentering krb5_cc_cache_match(), but
nothing in libkrb5 calls krb5_cc_cache_match(), so the comment is wrong,
at least in the github tree.

An alternative would be to call krb5_cc_set_default_name(NULL) in
kuser/kinit.c before calling krb5_cc_cache_match(), however, that seems
like an insufficiently general solution.  Also, the semantics of
krb5_cc_cache_match() would differ from MIT's -- it seems better to
match MIT's semantics.
2014-03-13 00:38:48 -05:00
Nicolas Williams
f10de508a6 Check fcache st_uid == geteuid(), not getuid()
Programs like sshd may create or access a ccache with
ruid != user's UID, euid == user's UID.

Set-uid-0 programs (ob reminder: they start life as ruid == user's UID,
euid == 0) shouldn't unintentionally access ccaches.  Therefore we
shouldn't check both of ruid and euid, just euid.
2013-10-04 18:24:38 -05:00
Nicolas Williams
be816fadd4 Minor refactoring in fcache of common open flags 2013-09-12 12:14:40 -05:00
Nicolas Williams
8feed14fd0 Only gate the st_uid fcache checks 2013-09-12 12:14:40 -05:00
Nicolas Williams
a9bd3c6e50 Fix racy file ccache corruption in cred_delete()
We *really* need a ccache instance ID tag.  In fact, we should probably
never krb5_cc_initialize() a ccache that doesn't have such a tag.  But
for now cred_delete() is now safe enough.
2013-09-12 12:14:39 -05:00
Nicolas Williams
e3eb1305f5 Make Refuses to open symlinks msg less spurious
If we're racing enough we could complain about symlinks where there were
none.  This was very surprising.  Make it surprise less.

We should really #ifndef O_NOFOLLOW that code chunk too, for the obvious
reason that we don't need to worry about symlinks if we have and use
O_NOFOLLOW.

Also, since all uses of fcc_open() use O_NOFOLLOW we should move that
into fcc_open().  Ditto O_BINARY and O_CLOEXEC.
2013-09-12 12:14:39 -05:00
Nicolas Williams
0866ee2615 Make fcc_remove_cred() better
Don't use a memory ccache go between, just copy all but the matching
credential(s).
2013-09-12 12:14:39 -05:00
Jeffrey Altman
235119c23f fcc_open: disable checks on Windows
st_dev and st_ino are not set in a consistent fashion by stat()
and fstat() so disable the symlink test.

disable the open group/other readable test because st_mode
cannot be used to perform such a test on Windows.

Change-Id: I1b68c672f882018def7e6d40d4bc7f7add58df36
2013-09-10 22:31:35 -04:00
Jeffrey Altman
72e6a0f383 fcache: correct build errors on Windows
Windows does not have getuid().

Change-Id: Ib92785716b056a69e42c32ec122d8a5f6f12ffbe

Signed-off-by: Love Hornquist Astrand <lha@h5l.org>
2013-07-16 12:44:36 +02:00
Love Hornquist Astrand
884b007938 Check owner too 2013-07-12 17:20:41 +02:00
Love Hornquist Astrand
f396f66523 add [libdefaults]fcache_strict_checking to gate the strict checking, defaults to on 2013-07-11 21:17:49 +02:00
Love Hornquist Astrand
2a565482f4 More strict fcache rules
- use O_NOFOLLOW
- be more strict not to follow symlinks
- require cache files to be owned by the user
- have sane permissions (not group/other readable)
2013-07-11 19:29:04 +02:00
Love Hornquist Astrand
403f599dbd better error reporting 2013-07-10 21:50:23 +02: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
Nicolas Williams
ad7e54d698 Generalize token expansion to allow for context-specific tokens 2011-12-08 13:33:37 -06:00
Nicolas Williams
6aec02f979 Make krb5_kuserok() pluggable and add features (including MIT config compat) 2011-12-08 13:33:36 -06:00
Love Hornquist Astrand
0879b9831a remove trailing whitespace 2011-05-21 11:57:31 -07:00
Love Hornquist Astrand
492492e42a use new function krb5_einval instead of returning EINVAL directly 2011-05-18 21:59:23 -07:00
Jeffrey Altman
18b76b6236 fcache: prevent null pointer dereference
Validate krb5_ccache and krb5_cc_cursor inputs
before use.  Avoid null pointer dereference which
can occur if an application fails to properly check
return codes.

Change-Id: I8023808936e60cc7b8e57a062106cfcdc51ee7d7
2011-05-18 10:20:09 -04: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
4b36b36e0b Add roken/rename.c to fix non-standard rename()
roken/rename.c is for platforms where the native rename()
implementation does not replace the target if it already exists.  This
implementation isn't atomic, but should be close enough for most
purposes.

For correct behavior, rk_rename() should be used instead of rename().
rk_rename() is #defined to be rename() on platforms where this fix is
not necessary.
2010-09-14 08:03:34 -04:00
Asanka Herath
bd795255aa Fix fcc_remove_cred() on platforms with non-standard rename() 2010-09-14 08:03:31 -04:00
Asanka Herath
5dcc605f6b Fix calling conventions for Windows 2010-08-20 13:14:10 -04:00
Love Hornquist Astrand
0b2b9d9834 catch error from as.*printf 2010-05-30 14:12:39 -07:00
Love Hornquist Astrand
886914f8f9 always use _krb5_expand_path_tokens 2010-05-27 12:25:47 -05:00
Asanka Herath
b9567cb158 Don't attempt to release unallocated resource in fcc_move() 2010-05-26 10:38:43 -04: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
75aa4b44fa switch to rk_strerror_r 2009-12-13 11:42:12 -08:00
Ted Percival
bfcdeda3b4 Fix memory leak in fcc_move
This usually occurs when re-initializing a file credential
cache over the top of an existing one.

This was meant to be fixed in commit 48cb3aa by calling
fcc_destroy(), but that only unlinks the "from" file
(which was already renamed or unlinked) but still doesn't
free the in-memory credentials. Using fcc_close() instead of
fcc_destroy() frees the leaked in-memory credentials.

Signed-off-by: Love Hornquist Astrand <lha@h5l.org>
2009-12-10 23:35:44 +01:00
Love Hornquist Astrand
b3e86a1cb6 track kdc offset better 2009-11-22 12:25:15 -08:00
Love Hornquist Astrand
f5e2873be2 Use strerror_r 2009-10-12 09:34:37 -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
9c18bf414c use constants for cache types
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25063 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-04-03 04:08:09 +00:00
Love Hörnquist Åstrand
a7e136a5d7 use krb5_cc_new_unique, use constants for cache types
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25058 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-04-03 04:07:17 +00:00
Love Hörnquist Åstrand
53dcd1bdd3 test leak and make behavie sanely.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25025 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-04-03 04:00:51 +00:00
Love Hörnquist Åstrand
48cb3aa538 plugs leaks
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25021 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-04-03 03:59:54 +00:00
Love Hörnquist Åstrand
5e4d827e61 Patch from Riverbed (Derrick Pallas) under the license of the files they are in:
Fix resource leak in heimdal/krb5/fcache/fcc_remove_cred
	In fcache, fcc_remove_cred generates a ccache called
	"newfile," which is not cleaned up if the final call
	(krb5_cc_move) fails.

Free of uninitialized value in fcache/fcc_move(...)
	If init_fcc fails to acquire a file handle, sp will be
	uninitialized. If this is the case, the call to
	krb5_storage_free will dereference this uninitialized value,
	which causes undefined behaviour.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24944 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-03-25 15:37:21 +00:00
Love Hörnquist Åstrand
d9a3a6a070 export _krb5_erase_file
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24450 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-01-25 00:46:06 +00:00
Love Hörnquist Åstrand
06e31e6376 handle krb5_cc_default_name() returning NULL in a diffrent way.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24029 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-11-12 04:18:50 +00:00
Love Hörnquist Åstrand
f9d5a05854 krb5_cc_default_name() can fail if the configuration file is strange.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24025 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-11-12 04:18:04 +00:00
Love Hörnquist Åstrand
9aa9efb279 make get_default_name have a better name
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23959 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-10-26 18:21:11 +00:00
Love Hörnquist Åstrand
7811db9c1f add lastmodified
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23923 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-10-18 21:14:54 +00:00
Love Hörnquist Åstrand
03babea1e3 switch to krb5_clear_error_message
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23911 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-10-14 02:55:39 +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
29047d38f3 strings should be i18n
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23769 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-09-07 21:21:18 +00:00
Love Hörnquist Åstrand
7b5981996c sprinle O_CLOEXEC, from Andrew Bartlett
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23474 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-07-28 08:49:43 +00:00