Skip to content

Commit 979c7af

Browse files
committed
krb5_child: fix enterprise principal parsing in keep-alive sessions
When keep-alive sessions transition between command types (e.g., from SSS_PAM_PREAUTH to SSS_PAM_AUTHENTICATE), enterprise principal settings were not being updated, causing parsing inconsistencies in complex AD environments. This change ensures that when the backend sends updated enterprise principal settings for different command types, the principals are correctly re-parsed with the appropriate flags, fixing UPN handling in multi-domain AD environments. Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
1 parent 72a42d5 commit 979c7af

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/providers/krb5/krb5_child.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ static errno_t k5c_attach_passkey_msg(struct krb5_req *kr, struct sss_passkey_ch
149149
static errno_t k5c_attach_keep_alive_msg(struct krb5_req *kr);
150150
static errno_t k5c_recv_data(struct krb5_req *kr, int fd, uint32_t *offline);
151151
static errno_t k5c_send_data(struct krb5_req *kr, int fd, errno_t error);
152+
static int k5c_setup(struct krb5_req *kr, uint32_t offline);
152153

153154
static krb5_error_code set_lifetime_options(struct cli_opts *cli_opts,
154155
krb5_get_init_creds_opt *options)
@@ -874,6 +875,12 @@ static errno_t krb5_req_update(struct krb5_req *dest, struct krb5_req *src)
874875
talloc_free(dest->pd);
875876
dest->pd = talloc_steal(dest, src->pd);
876877

878+
/* Update settings that may change between commands */
879+
dest->use_enterprise_princ = src->use_enterprise_princ;
880+
dest->validate = src->validate;
881+
dest->posix_domain = src->posix_domain;
882+
dest->send_pac = src->send_pac;
883+
877884
return EOK;
878885
}
879886

@@ -941,6 +948,13 @@ static krb5_error_code k5c_send_and_recv(struct krb5_req *kr)
941948
goto done;
942949
}
943950

951+
ret = k5c_setup(kr, offline);
952+
if (ret != EOK) {
953+
DEBUG(SSSDBG_CRIT_FAILURE, "k5c_setup failed during keep-alive [%d]: %s\n",
954+
ret, sss_strerror(ret));
955+
goto done;
956+
}
957+
944958
done:
945959
talloc_free(tmpkr);
946960
return ret;
@@ -3989,22 +4003,30 @@ static int k5c_setup(struct krb5_req *kr, uint32_t offline)
39894003
return kerr;
39904004
}
39914005

4006+
if (kr->princ_orig != NULL) {
4007+
krb5_free_principal(kr->ctx, kr->princ_orig);
4008+
}
39924009
kerr = krb5_parse_name(kr->ctx, kr->upn, &kr->princ_orig);
39934010
if (kerr != 0) {
39944011
KRB5_CHILD_DEBUG(SSSDBG_CRIT_FAILURE, kerr);
39954012
return kerr;
39964013
}
39974014

4015+
sss_krb5_free_unparsed_name(kr->ctx, kr->name);
39984016
kerr = krb5_unparse_name(kr->ctx, kr->princ, &kr->name);
39994017
if (kerr != 0) {
40004018
KRB5_CHILD_DEBUG(SSSDBG_CRIT_FAILURE, kerr);
40014019
return kerr;
40024020
}
40034021

4004-
kr->creds = calloc(1, sizeof(krb5_creds));
4005-
if (kr->creds == NULL) {
4006-
DEBUG(SSSDBG_CRIT_FAILURE, "calloc failed.\n");
4007-
return ENOMEM;
4022+
if (kr->creds != NULL) {
4023+
krb5_free_cred_contents(kr->ctx, kr->creds);
4024+
} else {
4025+
kr->creds = calloc(1, sizeof(krb5_creds));
4026+
if (kr->creds == NULL) {
4027+
DEBUG(SSSDBG_CRIT_FAILURE, "calloc failed.\n");
4028+
return ENOMEM;
4029+
}
40084030
}
40094031

40104032
#ifdef HAVE_KRB5_GET_INIT_CREDS_OPT_SET_RESPONDER

src/util/sss_krb5.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ krb5_error_code
455455
sss_krb5_parse_name_flags(krb5_context context, const char *name, int flags,
456456
krb5_principal *principal)
457457
{
458+
if (principal != NULL) {
459+
krb5_free_principal(context, *principal);
460+
}
458461
#ifdef HAVE_KRB5_PARSE_NAME_FLAGS
459462
return krb5_parse_name_flags(context, name, flags, principal);
460463
#else

0 commit comments

Comments
 (0)