krb5_child.c revision 429d51ec39193dd1681cef2c8eafd74595142a48
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Kerberos 5 Backend Module -- tgt_req and changepw child
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Sumit Bose <sbose@redhat.com>
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Copyright (C) 2009-2010 Red Hat
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech This program is free software; you can redistribute it and/or modify
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech it under the terms of the GNU General Public License as published by
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech the Free Software Foundation; either version 3 of the License, or
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech (at your option) any later version.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech This program is distributed in the hope that it will be useful,
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech but WITHOUT ANY WARRANTY; without even the implied warranty of
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech GNU General Public License for more details.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech You should have received a copy of the GNU General Public License
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech along with this program. If not, see <http://www.gnu.org/licenses/>.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech#define SSSD_KRB5_CHANGEPW_PRINCIPAL "kadmin/changepw"
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech const char *upn;
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech#define KRB5_CHILD_DEBUG(level, error) KRB5_DEBUG(level, krb5_error_ctx, error)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechstatic krb5_error_code set_lifetime_options(krb5_get_init_creds_opt *options)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech lifetime_str = getenv(SSSD_KRB5_RENEWABLE_LIFETIME);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech DEBUG(SSSDBG_CONF_SETTINGS, "Cannot read [%s] from environment.\n",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* Unset option flag to make sure defaults from krb5.conf are used. */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech options->flags &= ~(KRB5_GET_INIT_CREDS_OPT_RENEW_LIFE);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech kerr = krb5_string_to_deltat(lifetime_str, &lifetime);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech "krb5_string_to_deltat failed for [%s].\n",
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek DEBUG(SSSDBG_CONF_SETTINGS, "%s is set to [%s]\n",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech krb5_get_init_creds_opt_set_renew_life(options, lifetime);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech DEBUG(SSSDBG_CONF_SETTINGS, "Cannot read [%s] from environment.\n",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* Unset option flag to make sure defaults from krb5.conf are used. */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech options->flags &= ~(KRB5_GET_INIT_CREDS_OPT_TKT_LIFE);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech kerr = krb5_string_to_deltat(lifetime_str, &lifetime);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech "krb5_string_to_deltat failed for [%s].\n",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech "%s is set to [%s]\n", SSSD_KRB5_LIFETIME, lifetime_str);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech krb5_get_init_creds_opt_set_tkt_life(options, lifetime);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechstatic void set_canonicalize_option(krb5_get_init_creds_opt *opts)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if (tmp_str != NULL && strcasecmp(tmp_str, "true") == 0) {
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech DEBUG(SSSDBG_CONF_SETTINGS, "%s is set to [%s]\n",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech SSSD_KRB5_CANONICALIZE, tmp_str ? tmp_str : "not set");
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech sss_krb5_get_init_creds_opt_set_canonicalize(opts, canonicalize);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechstatic void set_changepw_options(krb5_get_init_creds_opt *options)
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek sss_krb5_get_init_creds_opt_set_canonicalize(options, 0);
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek krb5_get_init_creds_opt_set_forwardable(options, 0);
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek krb5_get_init_creds_opt_set_proxiable(options, 0);
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek krb5_get_init_creds_opt_set_renew_life(options, 0);
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek krb5_get_init_creds_opt_set_tkt_life(options, 5*60);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechstatic void revert_changepw_options(krb5_get_init_creds_opt *options)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* Currently we do not set forwardable and proxiable explicitly, the flags
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech * must be removed so that libkrb5 can take the defaults from krb5.conf */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech options->flags &= ~(KRB5_GET_INIT_CREDS_OPT_FORWARDABLE);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech options->flags &= ~(KRB5_GET_INIT_CREDS_OPT_PROXIABLE);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech DEBUG(SSSDBG_OP_FAILURE, ("set_lifetime_options failed.\n"));
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechstatic errno_t sss_send_pac(krb5_authdata **pac_authdata)
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek ret = sss_pac_make_request(SSS_PAC_ADD_PAC_USER, &sss_data,
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech DEBUG(SSSDBG_OP_FAILURE, "sss_pac_make_request failed [%d][%d].\n",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechstatic void sss_krb5_expire_callback_func(krb5_context context, void *data,
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech struct krb5_req *kr = talloc_get_type(data, struct krb5_req);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech DEBUG(SSSDBG_CRIT_FAILURE, "Time to expire out of range.\n");
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech DEBUG(SSSDBG_TRACE_INTERNAL, "exp_time: [%ld]\n", exp_time);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech DEBUG(SSSDBG_CRIT_FAILURE, "talloc_size failed.\n");
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ret = pam_add_response(kr->pd, SSS_PAM_USER_INFO, 2 * sizeof(uint32_t),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech DEBUG(SSSDBG_CRIT_FAILURE, "pam_add_response failed.\n");
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech * TODO: These features generally would requires a significant refactoring
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech * of SSSD and MIT krb5 doesn't support them anyway. They are listed here
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech * simply as a reminder of things that might become future feature potential.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech * 1. tokeninfo selection
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech * 2. challenge
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech * 3. discreet token/pin prompting
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech * 4. interactive otp format correction
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech * 5. nextOTP
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechtypedef int (*checker)(int c);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechstatic krb5_error_code tokeninfo_matches(TALLOC_CTX *mem_ctx,
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if (ti->flags & KRB5_RESPONDER_OTP_FLAGS_NEXTOTP) {
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* This is a non-sensical value. */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if (ti->flags & KRB5_RESPONDER_OTP_FLAGS_COLLECT_TOKEN) {
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* ASSUMPTION: authtok has one of the following formats:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech * 1. TokenValue
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech * 2. PIN+TokenValue
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech talloc_set_destructor(token, token_pin_destructor);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if (ti->flags & KRB5_RESPONDER_OTP_FLAGS_COLLECT_PIN) {
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* If the server desires a separate pin, we will split it.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech * ASSUMPTION: Format of authtok is PIN+TokenValue. */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if (ti->flags & KRB5_RESPONDER_OTP_FLAGS_SEPARATE_PIN) {
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* Copy the PIN from the front of the value. */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech pin = talloc_strndup(NULL, pwd, len - ti->length);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* Remove the PIN from the front of the token value. */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech memmove(token, token + len - ti->length, ti->length + 1);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* If check is set, we need to verify the contents of the token. */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech for (i = 0; check != NULL && token[i] != '\0'; i++) {
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechstatic krb5_error_code answer_otp(krb5_context ctx,
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ret = krb5_responder_otp_get_challenge(ctx, rctx, &chl);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* Either an error, or nothing to do. */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if (chl->tokeninfo == NULL || chl->tokeninfo[0] == NULL) {
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* No tokeninfos? Absurd! */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* Validate our assumptions about the contents of authtok. */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ret = sss_authtok_get_password(kr->pd->authtok, &pwd, &len);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* Find the first supported tokeninfo which matches our authtoken. */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ret = tokeninfo_matches(kr, chl->tokeninfo[i], pwd, len, &token, &pin);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech "No tokeninfos found which match our credentials.\n");
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if (chl->tokeninfo[i]->flags & KRB5_RESPONDER_OTP_FLAGS_COLLECT_TOKEN) {
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* Don't let SSSD cache the OTP authtok since it is single-use. */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech DEBUG(SSSDBG_CRIT_FAILURE, "pam_add_response failed.\n");
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech /* Respond with the appropriate answer. */
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ret = krb5_responder_otp_set_answer(ctx, rctx, i, token, pin);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech krb5_responder_otp_challenge_free(ctx, rctx, chl);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechstatic krb5_error_code sss_krb5_responder(krb5_context ctx,
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech struct krb5_req *kr = talloc_get_type(data, struct krb5_req);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechstatic krb5_error_code sss_krb5_prompter(krb5_context context, void *data,
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech struct krb5_req *kr = talloc_get_type(data, struct krb5_req);
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech DEBUG(SSSDBG_CRIT_FAILURE, "Cannot handle password prompts.\n");
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech "Prompter called with empty banner, nothing to do.\n");
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech DEBUG(SSSDBG_FUNC_DATA, "Prompter called with [%s].\n", banner);
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek ret = pam_add_response(kr->pd, SSS_PAM_TEXT_MSG, strlen(banner)+1,
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "pam_add_response failed.\n");
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozekstatic krb5_error_code create_empty_cred(krb5_context ctx, krb5_principal princ,
return ENOMEM;
if (kerr != 0) {
goto done;
if (kerr != 0) {
goto done;
done:
if (kerr != 0) {
return kerr;
int ret;
int fd;
return EOK;
return ret;
return EOK;
const char *type;
#ifdef HAVE_KRB5_CC_COLLECTION
bool switch_to_cc = false;
if (kerr) {
return ERR_INTERNAL;
if (kerr) {
goto done;
if (kerr) {
goto done;
#ifdef HAVE_KRB5_CC_COLLECTION
if (kerr) {
goto done;
switch_to_cc = true;
if (kerr) {
goto done;
if (kerr) {
goto done;
if (kerr) {
goto done;
#ifdef HAVE_KRB5_CC_COLLECTION
if (switch_to_cc) {
if (kerr) {
goto done;
done:
if (kcc) {
return kerr;
size_t p = 0;
if (!buf) {
return ENOMEM;
*_len = p;
return EOK;
int ret;
return ERR_INTERNAL;
return ENOMEM;
return ret;
int ret;
return ret;
errno = 0;
return ret;
return EOK;
return EOK;
int ret;
unsigned int upn_len = 0;
goto done;
if (kerr != 0) {
goto done;
goto done;
done:
return ret;
bool realm_entry_found = false;
if (kerr != 0) {
return kerr;
if (kerr != 0) {
return kerr;
if (kerr != 0) {
goto done;
if (kerr != 0) {
realm_entry_found = true;
if (!realm_entry_found) {
if (kerr != 0) {
goto done;
goto done;
if (kerr != 0) {
goto done;
if (kerr == 0) {
goto done;
if (kerr != 0) {
kerr = 0;
goto done;
if (kerr != 0) {
kerr = 0;
done:
return kerr;
char *ccname)
&options);
if (kerr != 0) {
return kerr;
if (kerr != 0) {
goto done;
kerr = 0;
done:
return kerr;
const char *password)
const char *realm_name;
int realm_length;
char *cc_name;
kr);
if (kerr != 0) {
if (realm_length == 0) {
return KRB5KRB_ERR_GENERIC;
if (kerr != 0) {
return kerr;
if (kerr != 0) {
return kerr;
if (kerr != 0) {
goto done;
if (kerr) {
goto done;
if (kerr != 0) {
kerr = 0;
done:
return kerr;
if (kerr != 0) {
switch (kerr) {
return ERR_OK;
case KRB5_LIBOS_CANTREADPWD:
return ERR_NO_CREDS;
case KRB5_KDCREP_SKEW:
case KRB5KRB_AP_ERR_SKEW:
case KRB5_KDC_UNREACH:
case KRB5_REALM_CANT_RESOLVE:
return ERR_NETWORK_IO;
return ERR_ACCOUNT_EXPIRED;
case KRB5KDC_ERR_KEY_EXP:
return ERR_CREDS_EXPIRED;
return ERR_AUTH_FAILED;
case KRB5_PROG_ETYPE_NOSUPP:
case KRB5_PREAUTH_FAILED:
return ERR_CREDS_INVALID;
case KRB5KRB_ERR_GENERIC:
return ERR_INTERNAL;
int ret;
const char *realm_name;
int realm_length;
return ERR_NO_CREDS;
if (!prelim) {
if (realm_length == 0) {
return ERR_INTERNAL;
if (kerr != 0) {
msg);
return kerr;
if (prelim) {
return EOK;
return ERR_NO_CREDS;
return ERR_NETWORK_IO;
if (kerr != 0) {
return ERR_CHPASS_FAILED;
if (kerr == 0) {
int ret;
switch (ret) {
case EOK:
case EACCES:
return ERR_INVALID_CRED_TYPE;
return ERR_NO_CREDS;
if (kerr == 0) {
goto done;
if (kerr != 0) {
if (kerr == 0) {
done:
return ret;
if (kerr != 0) {
if (access_allowed) {
return EOK;
return ERR_AUTH_DENIED;
const char *ccname;
int ret;
return ERR_INVALID_CRED_TYPE;
if (kerr != 0) {
goto done;
if (kerr != 0) {
goto done;
if (kerr != 0) {
goto done;
if (kerr != 0) {
goto done;
if (kerr != 0) {
goto done;
if (kerr != 0) {
done:
if (kerr == 0) {
kerr = 0;
if (kerr == 0) {
return EINVAL;
switch (auth_token_type) {
case SSS_AUTHTOK_TYPE_EMPTY:
case SSS_AUTHTOK_TYPE_CCFILE:
return EINVAL;
*p += auth_token_length;
return ret;
size_t p = 0;
return ENOMEM;
p += len;
p += len;
if (len > 0) {
p += len;
p += len;
if (ret) {
return ret;
if (ret) {
return ret;
p += len;
return EOK;
return EOK;
if (krberr != 0) {
goto done;
} else if (krberr != 0) {
krberr = 0;
goto done;
krberr = 0;
done:
return krberr;
const char *primary,
const char *realm,
const char *keytab_name,
char **fast_ccname)
char *ccname;
char *server_name;
int status;
return ENOMEM;
goto done;
if (kerr) {
goto done;
if (kerr != 0) {
goto done;
goto done;
if (kerr != 0) {
goto done;
if (kerr == 0) {
goto done;
switch (fchild_pid) {
goto done;
if (kerr != 0) {
if (kerr != 0) {
exit(0);
errno = 0;
if (kerr > 0) {
if (kerr != 0) {
if (kerr != 0) {
goto done;
goto done;
done:
if (kerr == 0) {
return kerr;
errno = 0;
return ret;
return ret;
char *fast_principal_realm;
char *fast_principal;
char *tmp_str;
char *new_ccname;
if (tmp_str) {
if (kerr) {
return kerr;
&tmp_str);
if (kerr) {
return kerr;
if (!fast_principal) {
return KRB5KRB_ERR_GENERIC;
if (!fast_principal_realm) {
return ENOMEM;
if (kerr != 0) {
return kerr;
if (kerr != 0) {
return kerr;
if (kerr != 0) {
return kerr;
if (demand) {
if (kerr != 0) {
return kerr;
return EOK;
char *use_fast_str;
return EINVAL;
return EOK;
bool valid;
valid = false;
switch (ret) {
case ERR_NOT_FOUND:
case ENOENT:
case EINVAL:
case EOK:
valid = true;
return ret;
return EOK;
return ret;
return ret;
return EOK;
return ret;
return EOK;
return EOK;
if (ret != 0) {
if (ret != 0) {
return ret;
return EOK;
int parse_flags;
if (kerr != 0) {
return kerr;
if (kerr != 0) {
return EIO;
* missing in krb5.conf or to allow SSSD to work with multiple unconnected
if (kerr != 0) {
if (kerr != 0) {
return kerr;
if (kerr != 0) {
return kerr;
return ENOMEM;
if (kerr != 0) {
return kerr;
if (kerr != 0) {
return kerr;
if (!offline) {
return kerr;
int ret;
char *mem_keytab;
if (kerr != 0) {
return kerr;
if (kerr != 0) {
return kerr;
return ret;;
return ret;
if (!(offline ||
NULL);
if (kerr != 0) {
return kerr;
return kerr;
int opt;
&debug_to_stderr, 0,
switch(opt) {
if (!debug_prg_name) {
goto done;
goto done;
goto done;
if (kerr != 0) {
goto done;
if (kerr != 0) {
goto done;
goto done;
case SSS_PAM_AUTHENTICATE:
if (offline) {
case SSS_PAM_CHAUTHTOK:
case SSS_PAM_CHAUTHTOK_PRELIM:
case SSS_PAM_ACCT_MGMT:
case SSS_CMD_RENEW:
if (offline) {
goto done;
goto done;
done:
ret = 0;