Skip to content

Commit 1e56bc9

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 735fe23 commit 1e56bc9

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/providers/krb5/krb5_child.c

Lines changed: 28 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)
@@ -877,6 +878,12 @@ static errno_t krb5_req_update(struct krb5_req *dest, struct krb5_req *src)
877878
talloc_free(dest->pd);
878879
dest->pd = talloc_steal(dest, src->pd);
879880

881+
/* Update settings that may change between commands */
882+
dest->use_enterprise_princ = src->use_enterprise_princ;
883+
dest->validate = src->validate;
884+
dest->posix_domain = src->posix_domain;
885+
dest->send_pac = src->send_pac;
886+
880887
return EOK;
881888
}
882889

@@ -944,6 +951,13 @@ static krb5_error_code k5c_send_and_recv(struct krb5_req *kr)
944951
goto done;
945952
}
946953

954+
ret = k5c_setup(kr, offline);
955+
if (ret != EOK) {
956+
DEBUG(SSSDBG_CRIT_FAILURE, "k5c_setup failed during keep-alive [%d]: %s\n",
957+
ret, sss_strerror(ret));
958+
goto done;
959+
}
960+
947961
done:
948962
talloc_free(tmpkr);
949963
return ret;
@@ -3957,22 +3971,32 @@ static int k5c_setup(struct krb5_req *kr, uint32_t offline)
39573971
return kerr;
39583972
}
39593973

3974+
if (kr->princ_orig != NULL) {
3975+
krb5_free_principal(kr->ctx, kr->princ_orig);
3976+
kr->princ_orig = NULL;
3977+
}
39603978
kerr = krb5_parse_name(kr->ctx, kr->upn, &kr->princ_orig);
39613979
if (kerr != 0) {
39623980
KRB5_CHILD_DEBUG(SSSDBG_CRIT_FAILURE, kerr);
39633981
return kerr;
39643982
}
39653983

3984+
sss_krb5_free_unparsed_name(kr->ctx, kr->name);
3985+
kr->name = NULL;
39663986
kerr = krb5_unparse_name(kr->ctx, kr->princ, &kr->name);
39673987
if (kerr != 0) {
39683988
KRB5_CHILD_DEBUG(SSSDBG_CRIT_FAILURE, kerr);
39693989
return kerr;
39703990
}
39713991

3972-
kr->creds = calloc(1, sizeof(krb5_creds));
3973-
if (kr->creds == NULL) {
3974-
DEBUG(SSSDBG_CRIT_FAILURE, "calloc failed.\n");
3975-
return ENOMEM;
3992+
if (kr->creds != NULL) {
3993+
krb5_free_cred_contents(kr->ctx, kr->creds);
3994+
} else {
3995+
kr->creds = calloc(1, sizeof(krb5_creds));
3996+
if (kr->creds == NULL) {
3997+
DEBUG(SSSDBG_CRIT_FAILURE, "calloc failed.\n");
3998+
return ENOMEM;
3999+
}
39764000
}
39774001

39784002
#ifdef HAVE_KRB5_GET_INIT_CREDS_OPT_SET_RESPONDER

src/util/sss_krb5.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@ 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 && *principal != NULL) {
459+
krb5_free_principal(context, *principal);
460+
*principal = NULL;
461+
}
458462
#ifdef HAVE_KRB5_PARSE_NAME_FLAGS
459463
return krb5_parse_name_flags(context, name, flags, principal);
460464
#else

0 commit comments

Comments
 (0)