|
|
905b4d |
From 663c5a61e6ab5aeee901684b8b43176711d5554e Mon Sep 17 00:00:00 2001
|
|
|
905b4d |
From: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
905b4d |
Date: Sat, 18 Oct 2014 22:03:13 +0200
|
|
|
905b4d |
Subject: [PATCH 87/92] KRB5: Move all ccache operations to krb5_child.c
|
|
|
905b4d |
MIME-Version: 1.0
|
|
|
905b4d |
Content-Type: text/plain; charset=UTF-8
|
|
|
905b4d |
Content-Transfer-Encoding: 8bit
|
|
|
905b4d |
|
|
|
905b4d |
The credential cache operations must be now performed by the krb5_child
|
|
|
905b4d |
completely, because the sssd_be process might be running as the sssd
|
|
|
905b4d |
user who doesn't have access to the ccaches.
|
|
|
905b4d |
|
|
|
905b4d |
src/providers/krb5/krb5_ccache.c is still linked against libsss_krb5
|
|
|
905b4d |
until we fix Kerberos ticket renewal as non-root.
|
|
|
905b4d |
|
|
|
905b4d |
Also includes a new error code that indicates that the back end should
|
|
|
905b4d |
remove the old ccache attribute -- the child can't do that if it's
|
|
|
905b4d |
running as the user.
|
|
|
905b4d |
|
|
|
905b4d |
Related:
|
|
|
905b4d |
https://fedorahosted.org/sssd/ticket/2370
|
|
|
905b4d |
|
|
|
905b4d |
Reviewed-by: Sumit Bose <sbose@redhat.com>
|
|
|
905b4d |
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
|
|
|
905b4d |
---
|
|
|
905b4d |
Makefile.am | 13 +-
|
|
|
905b4d |
src/providers/krb5/krb5_auth.c | 223 ++++----------------------------
|
|
|
905b4d |
src/providers/krb5/krb5_ccache.c | 62 ++++-----
|
|
|
905b4d |
src/providers/krb5/krb5_ccache.h | 5 +-
|
|
|
905b4d |
src/providers/krb5/krb5_child.c | 208 +++++++++++++++++++++++++++--
|
|
|
905b4d |
src/providers/krb5/krb5_child_handler.c | 13 ++
|
|
|
905b4d |
src/tests/krb5_child-test.c | 3 +-
|
|
|
905b4d |
src/util/util_errors.c | 1 +
|
|
|
905b4d |
src/util/util_errors.h | 1 +
|
|
|
905b4d |
9 files changed, 281 insertions(+), 248 deletions(-)
|
|
|
905b4d |
|
|
|
905b4d |
diff --git a/Makefile.am b/Makefile.am
|
|
|
905b4d |
index 4a69ecb0cfe48e20bde958c9351c2a5ece5ffffa..5325d51e7240ae39a546e68b2a2aea202b3dfdfa 100644
|
|
|
905b4d |
--- a/Makefile.am
|
|
|
905b4d |
+++ b/Makefile.am
|
|
|
905b4d |
@@ -2496,27 +2496,36 @@ libsss_ad_la_LDFLAGS = \
|
|
|
905b4d |
|
|
|
905b4d |
krb5_child_SOURCES = \
|
|
|
905b4d |
src/providers/krb5/krb5_child.c \
|
|
|
905b4d |
+ src/providers/krb5/krb5_ccache.c \
|
|
|
905b4d |
src/providers/dp_pam_data_util.c \
|
|
|
905b4d |
src/util/user_info_msg.c \
|
|
|
905b4d |
src/util/sss_krb5.c \
|
|
|
905b4d |
+ src/util/find_uid.c \
|
|
|
905b4d |
src/util/atomic_io.c \
|
|
|
905b4d |
src/util/authtok.c \
|
|
|
905b4d |
src/util/util.c \
|
|
|
905b4d |
src/util/signal.c \
|
|
|
905b4d |
+ src/util/strtonum.c \
|
|
|
905b4d |
src/util/become_user.c \
|
|
|
905b4d |
src/sss_client/common.c \
|
|
|
905b4d |
$(NULL)
|
|
|
905b4d |
krb5_child_CFLAGS = \
|
|
|
905b4d |
$(AM_CFLAGS) \
|
|
|
905b4d |
$(POPT_CFLAGS) \
|
|
|
905b4d |
- $(KRB5_CFLAGS)
|
|
|
905b4d |
+ $(KRB5_CFLAGS) \
|
|
|
905b4d |
+ $(PCRE_CFLAGS) \
|
|
|
905b4d |
+ $(SYSTEMD_LOGIN_CFLAGS) \
|
|
|
905b4d |
+ $(NULL)
|
|
|
905b4d |
krb5_child_LDADD = \
|
|
|
905b4d |
libsss_debug.la \
|
|
|
905b4d |
$(TALLOC_LIBS) \
|
|
|
905b4d |
$(POPT_LIBS) \
|
|
|
905b4d |
$(DHASH_LIBS) \
|
|
|
905b4d |
$(KRB5_LIBS) \
|
|
|
905b4d |
- $(CLIENT_LIBS)
|
|
|
905b4d |
+ $(CLIENT_LIBS) \
|
|
|
905b4d |
+ $(PCRE_LIBS) \
|
|
|
905b4d |
+ $(SYSTEMD_LOGIN_LIBS) \
|
|
|
905b4d |
+ $(NULL)
|
|
|
905b4d |
|
|
|
905b4d |
ldap_child_SOURCES = \
|
|
|
905b4d |
src/providers/ldap/ldap_child.c \
|
|
|
905b4d |
diff --git a/src/providers/krb5/krb5_auth.c b/src/providers/krb5/krb5_auth.c
|
|
|
905b4d |
index 5ed561601ac80e53ee795b458c5bf0ca410951bc..e791aee1c2d83f84ba617db1d5d93948c0e4e2a1 100644
|
|
|
905b4d |
--- a/src/providers/krb5/krb5_auth.c
|
|
|
905b4d |
+++ b/src/providers/krb5/krb5_auth.c
|
|
|
905b4d |
@@ -41,45 +41,6 @@
|
|
|
905b4d |
#include "providers/krb5/krb5_utils.h"
|
|
|
905b4d |
#include "providers/krb5/krb5_ccache.h"
|
|
|
905b4d |
|
|
|
905b4d |
-static errno_t
|
|
|
905b4d |
-check_old_ccache(const char *old_ccache, struct krb5child_req *kr,
|
|
|
905b4d |
- const char *realm, bool *active, bool *valid)
|
|
|
905b4d |
-{
|
|
|
905b4d |
- errno_t ret;
|
|
|
905b4d |
-
|
|
|
905b4d |
- *active = false;
|
|
|
905b4d |
- *valid = false;
|
|
|
905b4d |
-
|
|
|
905b4d |
- ret = sss_krb5_cc_verify_ccache(old_ccache,
|
|
|
905b4d |
- kr->uid, kr->gid,
|
|
|
905b4d |
- realm, kr->upn);
|
|
|
905b4d |
- switch (ret) {
|
|
|
905b4d |
- case ERR_NOT_FOUND:
|
|
|
905b4d |
- case ENOENT:
|
|
|
905b4d |
- DEBUG(SSSDBG_TRACE_FUNC,
|
|
|
905b4d |
- "Saved ccache %s doesn't exist.\n", old_ccache);
|
|
|
905b4d |
- return ENOENT;
|
|
|
905b4d |
- case EINVAL:
|
|
|
905b4d |
- /* cache found but no tgt or expired */
|
|
|
905b4d |
- case EOK:
|
|
|
905b4d |
- *valid = true;
|
|
|
905b4d |
- break;
|
|
|
905b4d |
- default:
|
|
|
905b4d |
- DEBUG(SSSDBG_OP_FAILURE,
|
|
|
905b4d |
- "Cannot check if saved ccache %s is valid\n",
|
|
|
905b4d |
- old_ccache);
|
|
|
905b4d |
- return ret;
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- ret = check_if_uid_is_active(kr->uid, active);
|
|
|
905b4d |
- if (ret != EOK) {
|
|
|
905b4d |
- DEBUG(SSSDBG_OP_FAILURE, "check_if_uid_is_active failed.\n");
|
|
|
905b4d |
- return ret;
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- return EOK;
|
|
|
905b4d |
-}
|
|
|
905b4d |
-
|
|
|
905b4d |
static int krb5_mod_ccname(TALLOC_CTX *mem_ctx,
|
|
|
905b4d |
struct sysdb_ctx *sysdb,
|
|
|
905b4d |
struct sss_domain_info *domain,
|
|
|
905b4d |
@@ -225,7 +186,6 @@ errno_t krb5_setup(TALLOC_CTX *mem_ctx, struct pam_data *pd,
|
|
|
905b4d |
return ENOMEM;
|
|
|
905b4d |
}
|
|
|
905b4d |
kr->is_offline = false;
|
|
|
905b4d |
- kr->active_ccache = true;
|
|
|
905b4d |
kr->run_as_user = true;
|
|
|
905b4d |
talloc_set_destructor((TALLOC_CTX *) kr, krb5_cleanup);
|
|
|
905b4d |
|
|
|
905b4d |
@@ -276,47 +236,26 @@ static void krb5_auth_cache_creds(struct krb5_ctx *krb5_ctx,
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
static errno_t krb5_auth_prepare_ccache_name(struct krb5child_req *kr,
|
|
|
905b4d |
+ struct ldb_message *user_msg,
|
|
|
905b4d |
struct be_ctx *be_ctx)
|
|
|
905b4d |
{
|
|
|
905b4d |
const char *ccname_template;
|
|
|
905b4d |
- errno_t ret;
|
|
|
905b4d |
|
|
|
905b4d |
- if (!kr->is_offline) {
|
|
|
905b4d |
- kr->is_offline = be_is_offline(be_ctx);
|
|
|
905b4d |
+ ccname_template = dp_opt_get_cstring(kr->krb5_ctx->opts, KRB5_CCNAME_TMPL);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ kr->ccname = expand_ccname_template(kr, kr, ccname_template,
|
|
|
905b4d |
+ kr->krb5_ctx->illegal_path_re, true,
|
|
|
905b4d |
+ be_ctx->domain->case_sensitive);
|
|
|
905b4d |
+ if (kr->ccname == NULL) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_CRIT_FAILURE, "expand_ccname_template failed.\n");
|
|
|
905b4d |
+ return ENOMEM;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
- /* The ccache file should be (re)created if one of the following conditions
|
|
|
905b4d |
- * is true:
|
|
|
905b4d |
- * - it doesn't exist (kr->ccname == NULL)
|
|
|
905b4d |
- * - the backend is online and the current ccache file is not used, i.e
|
|
|
905b4d |
- * the related user is currently not logged in and it is not a renewal
|
|
|
905b4d |
- * request
|
|
|
905b4d |
- * (!kr->is_offline && !kr->active_ccache && kr->pd->cmd != SSS_CMD_RENEW)
|
|
|
905b4d |
- * - the backend is offline and the current cache file not used and
|
|
|
905b4d |
- * it does not contain a valid tgt
|
|
|
905b4d |
- * (kr->is_offline && !kr->active_ccache && !kr->valid_tgt)
|
|
|
905b4d |
- */
|
|
|
905b4d |
- if (kr->ccname == NULL ||
|
|
|
905b4d |
- (kr->is_offline && !kr->active_ccache && !kr->valid_tgt) ||
|
|
|
905b4d |
- (!kr->is_offline && !kr->active_ccache && kr->pd->cmd != SSS_CMD_RENEW)) {
|
|
|
905b4d |
- DEBUG(SSSDBG_TRACE_ALL, "Recreating ccache file.\n");
|
|
|
905b4d |
- ccname_template = dp_opt_get_cstring(kr->krb5_ctx->opts,
|
|
|
905b4d |
- KRB5_CCNAME_TMPL);
|
|
|
905b4d |
- kr->ccname = expand_ccname_template(kr, kr, ccname_template,
|
|
|
905b4d |
- kr->krb5_ctx->illegal_path_re,
|
|
|
905b4d |
- true,
|
|
|
905b4d |
- be_ctx->domain->case_sensitive);
|
|
|
905b4d |
- if (kr->ccname == NULL) {
|
|
|
905b4d |
- DEBUG(SSSDBG_CRIT_FAILURE, "expand_ccname_template failed.\n");
|
|
|
905b4d |
- return ENOMEM;
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- ret = sss_krb5_precreate_ccache(kr->ccname,
|
|
|
905b4d |
- kr->uid, kr->gid);
|
|
|
905b4d |
- if (ret != EOK) {
|
|
|
905b4d |
- DEBUG(SSSDBG_OP_FAILURE, "ccache creation failed.\n");
|
|
|
905b4d |
- return ret;
|
|
|
905b4d |
- }
|
|
|
905b4d |
+ kr->old_ccname = ldb_msg_find_attr_as_string(user_msg,
|
|
|
905b4d |
+ SYSDB_CCACHE_FILE, NULL);
|
|
|
905b4d |
+ if (kr->old_ccname == NULL) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_TRACE_LIBS,
|
|
|
905b4d |
+ "No ccache file for user [%s] found.\n", kr->pd->user);
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
return EOK;
|
|
|
905b4d |
@@ -402,7 +341,6 @@ struct tevent_req *krb5_auth_send(TALLOC_CTX *mem_ctx,
|
|
|
905b4d |
struct krb5_auth_state *state;
|
|
|
905b4d |
struct ldb_result *res;
|
|
|
905b4d |
struct krb5child_req *kr = NULL;
|
|
|
905b4d |
- const char *ccache_file = NULL;
|
|
|
905b4d |
const char *realm;
|
|
|
905b4d |
struct tevent_req *req;
|
|
|
905b4d |
struct tevent_req *subreq;
|
|
|
905b4d |
@@ -588,45 +526,10 @@ struct tevent_req *krb5_auth_send(TALLOC_CTX *mem_ctx,
|
|
|
905b4d |
goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
- ccache_file = ldb_msg_find_attr_as_string(res->msgs[0],
|
|
|
905b4d |
- SYSDB_CCACHE_FILE,
|
|
|
905b4d |
- NULL);
|
|
|
905b4d |
- if (ccache_file != NULL) {
|
|
|
905b4d |
- ret = check_old_ccache(ccache_file, kr, realm,
|
|
|
905b4d |
- &kr->active_ccache,
|
|
|
905b4d |
- &kr->valid_tgt);
|
|
|
905b4d |
- if (ret == ENOENT) {
|
|
|
905b4d |
- DEBUG(SSSDBG_FUNC_DATA,
|
|
|
905b4d |
- "Ignoring ccache attribute [%s], because it doesn't"
|
|
|
905b4d |
- "exist.\n", ccache_file);
|
|
|
905b4d |
- ccache_file = NULL;
|
|
|
905b4d |
- } else if (ret != EOK) {
|
|
|
905b4d |
- DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
905b4d |
- "check_if_ccache_file_is_used failed.\n");
|
|
|
905b4d |
- ccache_file = NULL;
|
|
|
905b4d |
- }
|
|
|
905b4d |
- } else {
|
|
|
905b4d |
- kr->active_ccache = false;
|
|
|
905b4d |
- kr->valid_tgt = false;
|
|
|
905b4d |
- DEBUG(SSSDBG_CONF_SETTINGS,
|
|
|
905b4d |
- "No ccache file for user [%s] found.\n", pd->user);
|
|
|
905b4d |
- }
|
|
|
905b4d |
- DEBUG(SSSDBG_TRACE_ALL,
|
|
|
905b4d |
- "Ccache_file is [%s] and is %s active and TGT is %s valid.\n",
|
|
|
905b4d |
- ccache_file ? ccache_file : "not set",
|
|
|
905b4d |
- kr->active_ccache ? "" : "not",
|
|
|
905b4d |
- kr->valid_tgt ? "" : "not");
|
|
|
905b4d |
- if (ccache_file != NULL) {
|
|
|
905b4d |
- kr->ccname = ccache_file;
|
|
|
905b4d |
- kr->old_ccname = talloc_strdup(kr, ccache_file);
|
|
|
905b4d |
- if (kr->old_ccname == NULL) {
|
|
|
905b4d |
- DEBUG(SSSDBG_CRIT_FAILURE, "talloc_strdup failed.\n");
|
|
|
905b4d |
- ret = ENOMEM;
|
|
|
905b4d |
- goto done;
|
|
|
905b4d |
- }
|
|
|
905b4d |
- } else {
|
|
|
905b4d |
- kr->ccname = NULL;
|
|
|
905b4d |
- kr->old_ccname = NULL;
|
|
|
905b4d |
+ ret = krb5_auth_prepare_ccache_name(kr, res->msgs[0], state->be_ctx);
|
|
|
905b4d |
+ if (ret != EOK) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Cannot prepare ccache names!\n");
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
break;
|
|
|
905b4d |
|
|
|
905b4d |
@@ -669,7 +572,6 @@ static void krb5_auth_resolve_done(struct tevent_req *subreq)
|
|
|
905b4d |
struct tevent_req *req = tevent_req_callback_data(subreq, struct tevent_req);
|
|
|
905b4d |
struct krb5_auth_state *state = tevent_req_data(req, struct krb5_auth_state);
|
|
|
905b4d |
struct krb5child_req *kr = state->kr;
|
|
|
905b4d |
- char *msg;
|
|
|
905b4d |
int ret;
|
|
|
905b4d |
|
|
|
905b4d |
if (!state->search_kpasswd) {
|
|
|
905b4d |
@@ -728,45 +630,8 @@ static void krb5_auth_resolve_done(struct tevent_req *subreq)
|
|
|
905b4d |
}
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
- ret = krb5_auth_prepare_ccache_name(kr, state->be_ctx);
|
|
|
905b4d |
- if (ret) {
|
|
|
905b4d |
- goto done;
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- if (kr->is_offline) {
|
|
|
905b4d |
- DEBUG(SSSDBG_TRACE_ALL, "Preparing for offline operation.\n");
|
|
|
905b4d |
-
|
|
|
905b4d |
- if (kr->valid_tgt || kr->active_ccache) {
|
|
|
905b4d |
- DEBUG(SSSDBG_TRACE_ALL, "Valid TGT available or "
|
|
|
905b4d |
- "ccache file is already in use.\n");
|
|
|
905b4d |
- kr->ccname = kr->old_ccname;
|
|
|
905b4d |
- msg = talloc_asprintf(kr->pd,
|
|
|
905b4d |
- "%s=%s", CCACHE_ENV_NAME, kr->ccname);
|
|
|
905b4d |
- if (msg == NULL) {
|
|
|
905b4d |
- DEBUG(SSSDBG_CRIT_FAILURE, "talloc_asprintf failed.\n");
|
|
|
905b4d |
- } else {
|
|
|
905b4d |
- ret = pam_add_response(kr->pd, SSS_PAM_ENV_ITEM,
|
|
|
905b4d |
- strlen(msg) + 1, (uint8_t *) msg);
|
|
|
905b4d |
- if (ret != EOK) {
|
|
|
905b4d |
- DEBUG(SSSDBG_CRIT_FAILURE, "pam_add_response failed.\n");
|
|
|
905b4d |
- }
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- if (dp_opt_get_bool(kr->krb5_ctx->opts,
|
|
|
905b4d |
- KRB5_STORE_PASSWORD_IF_OFFLINE)) {
|
|
|
905b4d |
- krb5_auth_cache_creds(state->kr->krb5_ctx,
|
|
|
905b4d |
- state->domain,
|
|
|
905b4d |
- state->be_ctx->cdb,
|
|
|
905b4d |
- kr->pd, kr->uid,
|
|
|
905b4d |
- &state->pam_status, &state->dp_err);
|
|
|
905b4d |
- } else {
|
|
|
905b4d |
- state->pam_status = PAM_AUTHINFO_UNAVAIL;
|
|
|
905b4d |
- state->dp_err = DP_ERR_OFFLINE;
|
|
|
905b4d |
- }
|
|
|
905b4d |
- ret = EOK;
|
|
|
905b4d |
- goto done;
|
|
|
905b4d |
-
|
|
|
905b4d |
- }
|
|
|
905b4d |
+ if (!kr->is_offline) {
|
|
|
905b4d |
+ kr->is_offline = be_is_offline(state->be_ctx);
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
/* We need to keep the root privileges to read the keytab file if
|
|
|
905b4d |
@@ -814,7 +679,6 @@ static void krb5_auth_done(struct tevent_req *subreq)
|
|
|
905b4d |
char *renew_interval_str;
|
|
|
905b4d |
time_t renew_interval_time = 0;
|
|
|
905b4d |
bool use_enterprise_principal;
|
|
|
905b4d |
- uint32_t user_info_type;
|
|
|
905b4d |
|
|
|
905b4d |
ret = handle_child_recv(subreq, pd, &buf, &len;;
|
|
|
905b4d |
talloc_zfree(subreq);
|
|
|
905b4d |
@@ -974,6 +838,14 @@ static void krb5_auth_done(struct tevent_req *subreq)
|
|
|
905b4d |
}
|
|
|
905b4d |
break;
|
|
|
905b4d |
|
|
|
905b4d |
+ case ERR_CREDS_EXPIRED_CCACHE:
|
|
|
905b4d |
+ ret = krb5_delete_ccname(state, state->sysdb, state->domain,
|
|
|
905b4d |
+ pd->user, kr->old_ccname);
|
|
|
905b4d |
+ if (ret != EOK) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_CRIT_FAILURE, "krb5_delete_ccname failed.\n");
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+ /* FALLTHROUGH */
|
|
|
905b4d |
+
|
|
|
905b4d |
case ERR_CREDS_EXPIRED:
|
|
|
905b4d |
/* If the password is expired we can safely remove the ccache from the
|
|
|
905b4d |
* cache and disk if it is not actively used anymore. This will allow
|
|
|
905b4d |
@@ -981,14 +853,6 @@ static void krb5_auth_done(struct tevent_req *subreq)
|
|
|
905b4d |
* used. */
|
|
|
905b4d |
if (pd->cmd == SSS_PAM_AUTHENTICATE && !kr->active_ccache) {
|
|
|
905b4d |
if (kr->old_ccname != NULL) {
|
|
|
905b4d |
- ret = safe_remove_old_ccache_file(kr->old_ccname, NULL,
|
|
|
905b4d |
- kr->uid, kr->gid);
|
|
|
905b4d |
- if (ret != EOK) {
|
|
|
905b4d |
- DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
905b4d |
- "Failed to remove old ccache file [%s], "
|
|
|
905b4d |
- "please remove it manually.\n", kr->old_ccname);
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
ret = krb5_delete_ccname(state, state->sysdb, state->domain,
|
|
|
905b4d |
pd->user, kr->old_ccname);
|
|
|
905b4d |
if (ret != EOK) {
|
|
|
905b4d |
@@ -1062,37 +926,6 @@ static void krb5_auth_done(struct tevent_req *subreq)
|
|
|
905b4d |
goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
- ret = sss_krb5_check_ccache_princ(kr->uid, kr->gid, kr->ccname, kr->upn);
|
|
|
905b4d |
- if (ret) {
|
|
|
905b4d |
- if (res->otp == true && pd->cmd == SSS_PAM_CHAUTHTOK) {
|
|
|
905b4d |
- DEBUG(SSSDBG_IMPORTANT_INFO,
|
|
|
905b4d |
- "Password change succeeded but currently "
|
|
|
905b4d |
- "post-chpass kinit is not implemented\n");
|
|
|
905b4d |
-
|
|
|
905b4d |
- user_info_type = SSS_PAM_USER_INFO_OTP_CHPASS;
|
|
|
905b4d |
- ret = pam_add_response(pd, SSS_PAM_USER_INFO, sizeof(uint32_t),
|
|
|
905b4d |
- (const uint8_t *) &user_info_type);
|
|
|
905b4d |
- if (ret != EOK) {
|
|
|
905b4d |
- DEBUG(SSSDBG_CRIT_FAILURE, "pam_add_response failed.\n");
|
|
|
905b4d |
- /* Not fatal */
|
|
|
905b4d |
- }
|
|
|
905b4d |
- } else {
|
|
|
905b4d |
- DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
905b4d |
- "No ccache for %s in %s?\n", kr->upn, kr->ccname);
|
|
|
905b4d |
- goto done;
|
|
|
905b4d |
- }
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- if (kr->old_ccname) {
|
|
|
905b4d |
- ret = safe_remove_old_ccache_file(kr->old_ccname, kr->ccname,
|
|
|
905b4d |
- kr->uid, kr->gid);
|
|
|
905b4d |
- if (ret != EOK) {
|
|
|
905b4d |
- DEBUG(SSSDBG_MINOR_FAILURE,
|
|
|
905b4d |
- "Failed to remove old ccache file [%s], "
|
|
|
905b4d |
- "please remove it manually.\n", kr->old_ccname);
|
|
|
905b4d |
- }
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
ret = krb5_save_ccname(state, state->sysdb, state->domain,
|
|
|
905b4d |
pd->user, kr->ccname);
|
|
|
905b4d |
if (ret) {
|
|
|
905b4d |
diff --git a/src/providers/krb5/krb5_ccache.c b/src/providers/krb5/krb5_ccache.c
|
|
|
905b4d |
index c0f5b7b8ced3fd2d6d8cbbf4e3339caba60888ff..7aa36b744ddcf7e46edcc26405a5101645b8b546 100644
|
|
|
905b4d |
--- a/src/providers/krb5/krb5_ccache.c
|
|
|
905b4d |
+++ b/src/providers/krb5/krb5_ccache.c
|
|
|
905b4d |
@@ -374,49 +374,32 @@ done:
|
|
|
905b4d |
|
|
|
905b4d |
/* This function is called only as a way to validate that we have the
|
|
|
905b4d |
* right cache */
|
|
|
905b4d |
-errno_t sss_krb5_check_ccache_princ(uid_t uid, gid_t gid,
|
|
|
905b4d |
- const char *ccname, const char *principal)
|
|
|
905b4d |
+errno_t sss_krb5_check_ccache_princ(krb5_context kctx,
|
|
|
905b4d |
+ const char *ccname,
|
|
|
905b4d |
+ krb5_principal user_princ)
|
|
|
905b4d |
{
|
|
|
905b4d |
- struct sss_krb5_ccache *cc = NULL;
|
|
|
905b4d |
+ krb5_ccache kcc = NULL;
|
|
|
905b4d |
krb5_principal ccprinc = NULL;
|
|
|
905b4d |
- krb5_principal kprinc = NULL;
|
|
|
905b4d |
krb5_error_code kerr;
|
|
|
905b4d |
const char *cc_type;
|
|
|
905b4d |
- TALLOC_CTX *tmp_ctx;
|
|
|
905b4d |
errno_t ret;
|
|
|
905b4d |
|
|
|
905b4d |
- tmp_ctx = talloc_new(NULL);
|
|
|
905b4d |
- if (tmp_ctx == NULL) {
|
|
|
905b4d |
- DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
|
|
|
905b4d |
- return ENOMEM;
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- ret = sss_open_ccache_as_user(tmp_ctx, ccname, uid, gid, &cc);
|
|
|
905b4d |
- if (ret) {
|
|
|
905b4d |
- goto done;
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- cc_type = krb5_cc_get_type(cc->context, cc->ccache);
|
|
|
905b4d |
-
|
|
|
905b4d |
- DEBUG(SSSDBG_TRACE_INTERNAL,
|
|
|
905b4d |
- "Searching for [%s] in cache of type [%s]\n", principal, cc_type);
|
|
|
905b4d |
-
|
|
|
905b4d |
- kerr = krb5_parse_name(cc->context, principal, &kprinc);
|
|
|
905b4d |
- if (kerr != 0) {
|
|
|
905b4d |
- KRB5_DEBUG(SSSDBG_OP_FAILURE, cc->context, kerr);
|
|
|
905b4d |
- DEBUG(SSSDBG_CRIT_FAILURE, "krb5_parse_name failed.\n");
|
|
|
905b4d |
+ kerr = krb5_cc_resolve(kctx, ccname, &kcc;;
|
|
|
905b4d |
+ if (kerr) {
|
|
|
905b4d |
ret = ERR_INTERNAL;
|
|
|
905b4d |
goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
- kerr = krb5_cc_get_principal(cc->context, cc->ccache, &ccprinc);
|
|
|
905b4d |
+ cc_type = krb5_cc_get_type(kctx, kcc);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ kerr = krb5_cc_get_principal(kctx, kcc, &ccprinc);
|
|
|
905b4d |
if (kerr != 0) {
|
|
|
905b4d |
- KRB5_DEBUG(SSSDBG_OP_FAILURE, cc->context, kerr);
|
|
|
905b4d |
+ KRB5_DEBUG(SSSDBG_OP_FAILURE, kctx, kerr);
|
|
|
905b4d |
DEBUG(SSSDBG_CRIT_FAILURE, "krb5_cc_get_principal failed.\n");
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
if (ccprinc) {
|
|
|
905b4d |
- if (krb5_principal_compare(cc->context, kprinc, ccprinc) == TRUE) {
|
|
|
905b4d |
+ if (krb5_principal_compare(kctx, user_princ, ccprinc) == TRUE) {
|
|
|
905b4d |
/* found in the primary ccache */
|
|
|
905b4d |
ret = EOK;
|
|
|
905b4d |
goto done;
|
|
|
905b4d |
@@ -425,23 +408,23 @@ errno_t sss_krb5_check_ccache_princ(uid_t uid, gid_t gid,
|
|
|
905b4d |
|
|
|
905b4d |
#ifdef HAVE_KRB5_CC_COLLECTION
|
|
|
905b4d |
|
|
|
905b4d |
- if (krb5_cc_support_switch(cc->context, cc_type)) {
|
|
|
905b4d |
+ if (krb5_cc_support_switch(kctx, cc_type)) {
|
|
|
905b4d |
|
|
|
905b4d |
- krb5_cc_close(cc->context, cc->ccache);
|
|
|
905b4d |
- cc->ccache = NULL;
|
|
|
905b4d |
+ krb5_cc_close(kctx, kcc);
|
|
|
905b4d |
+ kcc = NULL;
|
|
|
905b4d |
|
|
|
905b4d |
- kerr = krb5_cc_set_default_name(cc->context, ccname);
|
|
|
905b4d |
+ kerr = krb5_cc_set_default_name(kctx, ccname);
|
|
|
905b4d |
if (kerr != 0) {
|
|
|
905b4d |
- KRB5_DEBUG(SSSDBG_MINOR_FAILURE, cc->context, kerr);
|
|
|
905b4d |
+ KRB5_DEBUG(SSSDBG_MINOR_FAILURE, kctx, kerr);
|
|
|
905b4d |
/* try to continue despite failure */
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
- kerr = krb5_cc_cache_match(cc->context, kprinc, &cc->ccache);
|
|
|
905b4d |
+ kerr = krb5_cc_cache_match(kctx, user_princ, &kcc;;
|
|
|
905b4d |
if (kerr == 0) {
|
|
|
905b4d |
ret = EOK;
|
|
|
905b4d |
goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
- KRB5_DEBUG(SSSDBG_TRACE_INTERNAL, cc->context, kerr);
|
|
|
905b4d |
+ KRB5_DEBUG(SSSDBG_TRACE_INTERNAL, kctx, kerr);
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
#endif /* HAVE_KRB5_CC_COLLECTION */
|
|
|
905b4d |
@@ -449,11 +432,12 @@ errno_t sss_krb5_check_ccache_princ(uid_t uid, gid_t gid,
|
|
|
905b4d |
ret = ERR_NOT_FOUND;
|
|
|
905b4d |
|
|
|
905b4d |
done:
|
|
|
905b4d |
- if (cc) {
|
|
|
905b4d |
- krb5_free_principal(cc->context, ccprinc);
|
|
|
905b4d |
- krb5_free_principal(cc->context, kprinc);
|
|
|
905b4d |
+ if (ccprinc) {
|
|
|
905b4d |
+ krb5_free_principal(kctx, ccprinc);
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+ if (kcc) {
|
|
|
905b4d |
+ krb5_cc_close(kctx, kcc);
|
|
|
905b4d |
}
|
|
|
905b4d |
- talloc_free(tmp_ctx);
|
|
|
905b4d |
return ret;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
diff --git a/src/providers/krb5/krb5_ccache.h b/src/providers/krb5/krb5_ccache.h
|
|
|
905b4d |
index e39f96cad6f46c4003103dce4eadf007bc0f8920..e47df3665e3f325cc56d34767b416662577cc048 100644
|
|
|
905b4d |
--- a/src/providers/krb5/krb5_ccache.h
|
|
|
905b4d |
+++ b/src/providers/krb5/krb5_ccache.h
|
|
|
905b4d |
@@ -39,8 +39,9 @@ errno_t sss_krb5_precreate_ccache(const char *ccname, uid_t uid, gid_t gid);
|
|
|
905b4d |
|
|
|
905b4d |
errno_t sss_krb5_cc_destroy(const char *ccname, uid_t uid, gid_t gid);
|
|
|
905b4d |
|
|
|
905b4d |
-errno_t sss_krb5_check_ccache_princ(uid_t uid, gid_t gid,
|
|
|
905b4d |
- const char *ccname, const char *principal);
|
|
|
905b4d |
+errno_t sss_krb5_check_ccache_princ(krb5_context kctx,
|
|
|
905b4d |
+ const char *ccname,
|
|
|
905b4d |
+ krb5_principal user_princ);
|
|
|
905b4d |
|
|
|
905b4d |
errno_t sss_krb5_cc_verify_ccache(const char *ccname, uid_t uid, gid_t gid,
|
|
|
905b4d |
const char *realm, const char *principal);
|
|
|
905b4d |
diff --git a/src/providers/krb5/krb5_child.c b/src/providers/krb5/krb5_child.c
|
|
|
905b4d |
index 7fa5f0c344a4afe110afa08f479f283aefce8d23..94cd34e433cf6a197860d233fbf9ca30cd3eb535 100644
|
|
|
905b4d |
--- a/src/providers/krb5/krb5_child.c
|
|
|
905b4d |
+++ b/src/providers/krb5/krb5_child.c
|
|
|
905b4d |
@@ -33,6 +33,7 @@
|
|
|
905b4d |
#include "util/sss_krb5.h"
|
|
|
905b4d |
#include "util/user_info_msg.h"
|
|
|
905b4d |
#include "util/child_common.h"
|
|
|
905b4d |
+#include "util/find_uid.h"
|
|
|
905b4d |
#include "providers/dp_backend.h"
|
|
|
905b4d |
#include "providers/krb5/krb5_auth.h"
|
|
|
905b4d |
#include "providers/krb5/krb5_utils.h"
|
|
|
905b4d |
@@ -61,6 +62,10 @@ struct krb5_req {
|
|
|
905b4d |
const char *upn;
|
|
|
905b4d |
uid_t uid;
|
|
|
905b4d |
gid_t gid;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ char *old_ccname;
|
|
|
905b4d |
+ bool old_cc_valid;
|
|
|
905b4d |
+ bool old_cc_active;
|
|
|
905b4d |
};
|
|
|
905b4d |
|
|
|
905b4d |
static krb5_context krb5_error_ctx;
|
|
|
905b4d |
@@ -1021,6 +1026,24 @@ static krb5_error_code get_and_save_tgt(struct krb5_req *kr,
|
|
|
905b4d |
goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
+ /* Successfull authentication! Check if ccache contains the
|
|
|
905b4d |
+ * right principal...
|
|
|
905b4d |
+ */
|
|
|
905b4d |
+ kerr = sss_krb5_check_ccache_princ(kr->ctx, kr->ccname, kr->creds->client);
|
|
|
905b4d |
+ if (kerr) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
905b4d |
+ "No ccache for %s in %s?\n", kr->upn, kr->ccname);
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ kerr = safe_remove_old_ccache_file(kr->old_ccname, kr->ccname,
|
|
|
905b4d |
+ kr->uid, kr->gid);
|
|
|
905b4d |
+ if (kerr != EOK) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_MINOR_FAILURE,
|
|
|
905b4d |
+ "Failed to remove old ccache file [%s], "
|
|
|
905b4d |
+ "please remove it manually.\n", kr->old_ccname);
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
kerr = add_ticket_times_and_upn_to_response(kr);
|
|
|
905b4d |
if (kerr != 0) {
|
|
|
905b4d |
DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
905b4d |
@@ -1094,6 +1117,7 @@ static errno_t changepw_child(struct krb5_req *kr, bool prelim)
|
|
|
905b4d |
int realm_length;
|
|
|
905b4d |
size_t msg_len;
|
|
|
905b4d |
uint8_t *msg;
|
|
|
905b4d |
+ uint32_t user_info_type;
|
|
|
905b4d |
|
|
|
905b4d |
DEBUG(SSSDBG_TRACE_LIBS, "Password change operation\n");
|
|
|
905b4d |
|
|
|
905b4d |
@@ -1222,6 +1246,14 @@ static errno_t changepw_child(struct krb5_req *kr, bool prelim)
|
|
|
905b4d |
krb5_free_cred_contents(kr->ctx, kr->creds);
|
|
|
905b4d |
|
|
|
905b4d |
if (kr->otp == true) {
|
|
|
905b4d |
+ user_info_type = SSS_PAM_USER_INFO_OTP_CHPASS;
|
|
|
905b4d |
+ ret = pam_add_response(kr->pd, SSS_PAM_USER_INFO, sizeof(uint32_t),
|
|
|
905b4d |
+ (const uint8_t *) &user_info_type);
|
|
|
905b4d |
+ if (ret != EOK) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_CRIT_FAILURE, "pam_add_response failed.\n");
|
|
|
905b4d |
+ /* Not fatal */
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
sss_authtok_set_empty(kr->pd->newauthtok);
|
|
|
905b4d |
return map_krb5_error(kerr);
|
|
|
905b4d |
}
|
|
|
905b4d |
@@ -1298,6 +1330,21 @@ static errno_t tgt_req_child(struct krb5_req *kr)
|
|
|
905b4d |
krb5_free_cred_contents(kr->ctx, kr->creds);
|
|
|
905b4d |
if (kerr == 0) {
|
|
|
905b4d |
ret = ERR_CREDS_EXPIRED;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ /* If the password is expired we can safely remove the ccache from the
|
|
|
905b4d |
+ * cache and disk if it is not actively used anymore. This will allow
|
|
|
905b4d |
+ * to create a new random ccache if sshd with privilege separation is
|
|
|
905b4d |
+ * used. */
|
|
|
905b4d |
+ if (kr->old_cc_active == false && kr->old_ccname) {
|
|
|
905b4d |
+ ret = safe_remove_old_ccache_file(kr->old_ccname, NULL,
|
|
|
905b4d |
+ kr->uid, kr->gid);
|
|
|
905b4d |
+ if (ret != EOK) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
905b4d |
+ "Failed to remove old ccache file [%s], "
|
|
|
905b4d |
+ "please remove it manually.\n", kr->old_ccname);
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+ ret = ERR_CREDS_EXPIRED_CCACHE;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
} else {
|
|
|
905b4d |
ret = map_krb5_error(kerr);
|
|
|
905b4d |
}
|
|
|
905b4d |
@@ -1423,12 +1470,17 @@ static errno_t create_empty_ccache(struct krb5_req *kr)
|
|
|
905b4d |
krb5_creds *creds = NULL;
|
|
|
905b4d |
krb5_error_code kerr;
|
|
|
905b4d |
|
|
|
905b4d |
- DEBUG(SSSDBG_TRACE_LIBS, "Creating empty ccache\n");
|
|
|
905b4d |
-
|
|
|
905b4d |
- kerr = create_empty_cred(kr->ctx, kr->princ, &creds);
|
|
|
905b4d |
- if (kerr == 0) {
|
|
|
905b4d |
- kerr = create_ccache(kr->ccname, creds);
|
|
|
905b4d |
+ if (kr->old_cc_valid == false) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_TRACE_LIBS, "Creating empty ccache\n");
|
|
|
905b4d |
+ kerr = create_empty_cred(kr->ctx, kr->princ, &creds);
|
|
|
905b4d |
+ if (kerr == 0) {
|
|
|
905b4d |
+ kerr = create_ccache(kr->ccname, creds);
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+ } else {
|
|
|
905b4d |
+ DEBUG(SSSDBG_TRACE_LIBS, "Existing ccache still valid, reusing\n");
|
|
|
905b4d |
+ kerr = 0;
|
|
|
905b4d |
}
|
|
|
905b4d |
+
|
|
|
905b4d |
if (kerr != 0) {
|
|
|
905b4d |
KRB5_CHILD_DEBUG(SSSDBG_CRIT_FAILURE, kerr);
|
|
|
905b4d |
} else {
|
|
|
905b4d |
@@ -1529,6 +1581,17 @@ static errno_t unpack_buffer(uint8_t *buf, size_t size,
|
|
|
905b4d |
|
|
|
905b4d |
SAFEALIGN_COPY_UINT32_CHECK(&len, buf + p, size, &p);
|
|
|
905b4d |
if ((p + len ) > size) return EINVAL;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ if (len > 0) {
|
|
|
905b4d |
+ kr->old_ccname = talloc_strndup(pd, (char *)(buf + p), len);
|
|
|
905b4d |
+ if (kr->old_ccname == NULL) return ENOMEM;
|
|
|
905b4d |
+ p += len;
|
|
|
905b4d |
+ } else {
|
|
|
905b4d |
+ DEBUG(SSSDBG_TRACE_INTERNAL, "No old ccache\n");
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ SAFEALIGN_COPY_UINT32_CHECK(&len, buf + p, size, &p);
|
|
|
905b4d |
+ if ((p + len ) > size) return EINVAL;
|
|
|
905b4d |
kr->keytab = talloc_strndup(pd, (char *)(buf + p), len);
|
|
|
905b4d |
if (kr->keytab == NULL) return ENOMEM;
|
|
|
905b4d |
p += len;
|
|
|
905b4d |
@@ -1538,10 +1601,14 @@ static errno_t unpack_buffer(uint8_t *buf, size_t size,
|
|
|
905b4d |
return ret;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
- DEBUG(SSSDBG_CONF_SETTINGS, "ccname: [%s] keytab: [%s]\n",
|
|
|
905b4d |
- kr->ccname, kr->keytab);
|
|
|
905b4d |
+ DEBUG(SSSDBG_CONF_SETTINGS,
|
|
|
905b4d |
+ "ccname: [%s] old_ccname: [%s] keytab: [%s]\n",
|
|
|
905b4d |
+ kr->ccname,
|
|
|
905b4d |
+ kr->old_ccname ? kr->old_ccname : "not set",
|
|
|
905b4d |
+ kr->keytab);
|
|
|
905b4d |
} else {
|
|
|
905b4d |
kr->ccname = NULL;
|
|
|
905b4d |
+ kr->old_ccname = NULL;
|
|
|
905b4d |
kr->keytab = NULL;
|
|
|
905b4d |
sss_authtok_set_empty(pd->authtok);
|
|
|
905b4d |
}
|
|
|
905b4d |
@@ -1870,6 +1937,126 @@ static errno_t check_use_fast(enum k5c_fast_opt *_fast_val)
|
|
|
905b4d |
return EOK;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
+static errno_t old_ccache_valid(struct krb5_req *kr, bool *_valid)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ errno_t ret;
|
|
|
905b4d |
+ bool valid;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ valid = false;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sss_krb5_cc_verify_ccache(kr->old_ccname,
|
|
|
905b4d |
+ kr->uid, kr->gid,
|
|
|
905b4d |
+ kr->realm, kr->upn);
|
|
|
905b4d |
+ switch (ret) {
|
|
|
905b4d |
+ case ERR_NOT_FOUND:
|
|
|
905b4d |
+ case ENOENT:
|
|
|
905b4d |
+ DEBUG(SSSDBG_TRACE_FUNC,
|
|
|
905b4d |
+ "Saved ccache %s doesn't exist, ignoring\n", kr->old_ccname);
|
|
|
905b4d |
+ break;
|
|
|
905b4d |
+ case EINVAL:
|
|
|
905b4d |
+ /* cache found but no tgt or expired */
|
|
|
905b4d |
+ case EOK:
|
|
|
905b4d |
+ valid = true;
|
|
|
905b4d |
+ break;
|
|
|
905b4d |
+ default:
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE,
|
|
|
905b4d |
+ "Cannot check if saved ccache %s is valid\n",
|
|
|
905b4d |
+ kr->old_ccname);
|
|
|
905b4d |
+ return ret;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ *_valid = valid;
|
|
|
905b4d |
+ return EOK;
|
|
|
905b4d |
+}
|
|
|
905b4d |
+
|
|
|
905b4d |
+static int k5c_check_old_ccache(struct krb5_req *kr)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ errno_t ret;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ if (kr->old_ccname) {
|
|
|
905b4d |
+ ret = old_ccache_valid(kr, &kr->old_cc_valid);
|
|
|
905b4d |
+ if (ret != EOK) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "old_ccache_valid failed.\n");
|
|
|
905b4d |
+ return ret;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = check_if_uid_is_active(kr->uid, &kr->old_cc_active);
|
|
|
905b4d |
+ if (ret != EOK) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "check_if_uid_is_active failed.\n");
|
|
|
905b4d |
+ return ret;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ DEBUG(SSSDBG_TRACE_ALL,
|
|
|
905b4d |
+ "Ccache_file is [%s] and is %s active and TGT is %s valid.\n",
|
|
|
905b4d |
+ kr->old_ccname ? kr->old_ccname : "not set",
|
|
|
905b4d |
+ kr->old_cc_active ? "" : "not",
|
|
|
905b4d |
+ kr->old_cc_valid ? "" : "not");
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ return EOK;
|
|
|
905b4d |
+}
|
|
|
905b4d |
+
|
|
|
905b4d |
+static int k5c_precreate_ccache(struct krb5_req *kr, uint32_t offline)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ errno_t ret;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ /* The ccache file should be (re)created if one of the following conditions
|
|
|
905b4d |
+ * is true:
|
|
|
905b4d |
+ * - it doesn't exist (kr->old_ccname == NULL)
|
|
|
905b4d |
+ * - the backend is online and the current ccache file is not used, i.e
|
|
|
905b4d |
+ * the related user is currently not logged in and it is not a renewal
|
|
|
905b4d |
+ * request
|
|
|
905b4d |
+ * (offline && !kr->old_cc_active && kr->pd->cmd != SSS_CMD_RENEW)
|
|
|
905b4d |
+ * - the backend is offline and the current cache file not used and
|
|
|
905b4d |
+ * it does not contain a valid tgt
|
|
|
905b4d |
+ * (offline && !kr->old_cc_active && !kr->valid_tgt)
|
|
|
905b4d |
+ */
|
|
|
905b4d |
+ if (kr->old_ccname == NULL ||
|
|
|
905b4d |
+ (offline && !kr->old_cc_active && !kr->old_cc_valid) ||
|
|
|
905b4d |
+ (!offline && !kr->old_cc_active && kr->pd->cmd != SSS_CMD_RENEW)) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_TRACE_ALL, "Recreating ccache\n");
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sss_krb5_precreate_ccache(kr->ccname, kr->uid, kr->gid);
|
|
|
905b4d |
+ if (ret != EOK) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "ccache creation failed.\n");
|
|
|
905b4d |
+ return ret;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+ } else {
|
|
|
905b4d |
+ /* We can reuse the old ccache */
|
|
|
905b4d |
+ kr->ccname = kr->old_ccname;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ return EOK;
|
|
|
905b4d |
+}
|
|
|
905b4d |
+
|
|
|
905b4d |
+static int k5c_ccache_setup(struct krb5_req *kr, uint32_t offline)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ errno_t ret;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ if (kr->pd->cmd == SSS_PAM_ACCT_MGMT) {
|
|
|
905b4d |
+ return EOK;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = k5c_check_old_ccache(kr);
|
|
|
905b4d |
+ if (ret != 0) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "Cannot check old ccache\n");
|
|
|
905b4d |
+ return ret;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ /* Pre-creating the ccache must be done as root, otherwise we can't mkdir
|
|
|
905b4d |
+ * some of the DIR: cache components. One example is /run/user/$UID because
|
|
|
905b4d |
+ * logind doesn't create the directory until the session phase, whereas
|
|
|
905b4d |
+ * we need the directory during the auth phase already
|
|
|
905b4d |
+ */
|
|
|
905b4d |
+ ret = k5c_precreate_ccache(kr, offline);
|
|
|
905b4d |
+ if (ret != 0) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "Cannot precreate ccache\n");
|
|
|
905b4d |
+ return ret;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ return EOK;
|
|
|
905b4d |
+}
|
|
|
905b4d |
+
|
|
|
905b4d |
static int k5c_setup(struct krb5_req *kr, uint32_t offline)
|
|
|
905b4d |
{
|
|
|
905b4d |
krb5_error_code kerr;
|
|
|
905b4d |
@@ -1881,6 +2068,11 @@ static int k5c_setup(struct krb5_req *kr, uint32_t offline)
|
|
|
905b4d |
return kerr;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
+ kerr = k5c_ccache_setup(kr, offline);
|
|
|
905b4d |
+ if (kerr != EOK) {
|
|
|
905b4d |
+ return kerr;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
if (offline || (fast_val == K5C_FAST_NEVER && kr->validate == false)) {
|
|
|
905b4d |
/* If krb5_child was started as setuid, but we don't need to
|
|
|
905b4d |
* perform either validation or FAST, just drop privileges to
|
|
|
905b4d |
@@ -1974,7 +2166,7 @@ static int k5c_setup(struct krb5_req *kr, uint32_t offline)
|
|
|
905b4d |
|
|
|
905b4d |
kerr = set_lifetime_options(kr->options);
|
|
|
905b4d |
if (kerr != 0) {
|
|
|
905b4d |
- DEBUG(SSSDBG_OP_FAILURE, ("set_lifetime_options failed.\n"));
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "set_lifetime_options failed.\n");
|
|
|
905b4d |
return kerr;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
diff --git a/src/providers/krb5/krb5_child_handler.c b/src/providers/krb5/krb5_child_handler.c
|
|
|
905b4d |
index 71c7f9c9f662e16b94afda0c8c0ae24666f0ba15..93961172c7a3a5d8f2a4fb320370037f188b5909 100644
|
|
|
905b4d |
--- a/src/providers/krb5/krb5_child_handler.c
|
|
|
905b4d |
+++ b/src/providers/krb5/krb5_child_handler.c
|
|
|
905b4d |
@@ -144,6 +144,11 @@ static errno_t create_send_buffer(struct krb5child_req *kr,
|
|
|
905b4d |
kr->pd->cmd == SSS_PAM_CHAUTHTOK) {
|
|
|
905b4d |
buf->size += 4*sizeof(uint32_t) + strlen(kr->ccname) + strlen(keytab) +
|
|
|
905b4d |
sss_authtok_get_size(kr->pd->authtok);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ buf->size += sizeof(uint32_t);
|
|
|
905b4d |
+ if (kr->old_ccname) {
|
|
|
905b4d |
+ buf->size += strlen(kr->old_ccname);
|
|
|
905b4d |
+ }
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
if (kr->pd->cmd == SSS_PAM_CHAUTHTOK) {
|
|
|
905b4d |
@@ -182,6 +187,14 @@ static errno_t create_send_buffer(struct krb5child_req *kr,
|
|
|
905b4d |
SAFEALIGN_SET_UINT32(&buf->data[rp], strlen(kr->ccname), &rp);
|
|
|
905b4d |
safealign_memcpy(&buf->data[rp], kr->ccname, strlen(kr->ccname), &rp);
|
|
|
905b4d |
|
|
|
905b4d |
+ if (kr->old_ccname) {
|
|
|
905b4d |
+ SAFEALIGN_SET_UINT32(&buf->data[rp], strlen(kr->old_ccname), &rp);
|
|
|
905b4d |
+ safealign_memcpy(&buf->data[rp], kr->old_ccname,
|
|
|
905b4d |
+ strlen(kr->old_ccname), &rp);
|
|
|
905b4d |
+ } else {
|
|
|
905b4d |
+ SAFEALIGN_SET_UINT32(&buf->data[rp], 0, &rp);
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
SAFEALIGN_SET_UINT32(&buf->data[rp], strlen(keytab), &rp);
|
|
|
905b4d |
safealign_memcpy(&buf->data[rp], keytab, strlen(keytab), &rp);
|
|
|
905b4d |
|
|
|
905b4d |
diff --git a/src/tests/krb5_child-test.c b/src/tests/krb5_child-test.c
|
|
|
905b4d |
index 8826a28ed5ea064317c62682003dc0e9a6df01b6..a59863b4d8aa8bdcc241c87befd672a5e5c876a3 100644
|
|
|
905b4d |
--- a/src/tests/krb5_child-test.c
|
|
|
905b4d |
+++ b/src/tests/krb5_child-test.c
|
|
|
905b4d |
@@ -239,8 +239,7 @@ create_dummy_req(TALLOC_CTX *mem_ctx, const char *user,
|
|
|
905b4d |
kr->ccname = expand_ccname_template(kr, kr,
|
|
|
905b4d |
dp_opt_get_cstring(kr->krb5_ctx->opts,
|
|
|
905b4d |
KRB5_CCNAME_TMPL),
|
|
|
905b4d |
- kr->krb5_ctx->illegal_path_re,
|
|
|
905b4d |
- true, true);
|
|
|
905b4d |
+ kr->krb5_ctx->illegal_path_re, true, true);
|
|
|
905b4d |
if (!kr->ccname) goto fail;
|
|
|
905b4d |
|
|
|
905b4d |
DEBUG(SSSDBG_FUNC_DATA, "ccname [%s] uid [%llu] gid [%llu]\n",
|
|
|
905b4d |
diff --git a/src/util/util_errors.c b/src/util/util_errors.c
|
|
|
905b4d |
index d5da64622eebe7f779816c7f2090da5b9a9b13f0..c1ed0fb634c447904b63335d1cd161b7e7914a08 100644
|
|
|
905b4d |
--- a/src/util/util_errors.c
|
|
|
905b4d |
+++ b/src/util/util_errors.c
|
|
|
905b4d |
@@ -31,6 +31,7 @@ struct err_string error_to_str[] = {
|
|
|
905b4d |
{ "Invalid credential type" }, /* ERR_INVALID_CRED_TYPE */
|
|
|
905b4d |
{ "No credentials available" }, /* ERR_NO_CREDS */
|
|
|
905b4d |
{ "Credentials are expired" }, /* ERR_CREDS_EXPIRED */
|
|
|
905b4d |
+ { "Credentials are expired, old ccache was removed" }, /* ERR_CREDS_EXPIRED_CCACHE */
|
|
|
905b4d |
{ "Failure setting user credentials"}, /* ERR_CREDS_INVALID */
|
|
|
905b4d |
{ "No cached credentials available" }, /* ERR_NO_CACHED_CREDS */
|
|
|
905b4d |
{ "Cached credentials are expired" }, /* ERR_CACHED_CREDS_EXPIRED */
|
|
|
905b4d |
diff --git a/src/util/util_errors.h b/src/util/util_errors.h
|
|
|
905b4d |
index 2bc576605e613d674d38b54aae1604c0b044635f..f71ede8d0fa000627a1bd994ec8bd94a632b35b2 100644
|
|
|
905b4d |
--- a/src/util/util_errors.h
|
|
|
905b4d |
+++ b/src/util/util_errors.h
|
|
|
905b4d |
@@ -56,6 +56,7 @@ enum sssd_errors {
|
|
|
905b4d |
ERR_CREDS_INVALID,
|
|
|
905b4d |
ERR_NO_CACHED_CREDS,
|
|
|
905b4d |
ERR_CACHED_CREDS_EXPIRED,
|
|
|
905b4d |
+ ERR_CREDS_EXPIRED_CCACHE,
|
|
|
905b4d |
ERR_AUTH_DENIED,
|
|
|
905b4d |
ERR_AUTH_FAILED,
|
|
|
905b4d |
ERR_CHPASS_DENIED,
|
|
|
905b4d |
--
|
|
|
905b4d |
1.9.3
|
|
|
905b4d |
|