Skip to content

Commit 9503ed0

Browse files
committed
pam_ksu: Fix crash when no ticket is present
When building with MIT Kerberos, pam_ksu crashes if the user doesn't have a ticket because default_principal is never populated in get_su_principal(). Change the compatibility function to use krb5_build_principal_alloc_va instead, and make its interface compatible with the equivalent Heimdal function. Despite what the comment says, we do free the default principal later in get_su_principal() so this shouldn't cause any leaks. Reviewed by: des, philip, cy, jhb Differential Revision: https://reviews.freebsd.org/D51829
1 parent 62fd20b commit 9503ed0

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

lib/libpam/modules/pam_ksu/pam_ksu.c

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,13 @@ static int auth_krb5(pam_handle_t *, krb5_context, const char *,
5858
#define KRB5_DEFAULT_CCFILE_ROOT "/tmp/krb5cc_"
5959
#define KRB5_DEFAULT_CCROOT "FILE:" KRB5_DEFAULT_CCFILE_ROOT
6060

61-
/*
62-
* XXX We will replace krb5_build_principal_va() with
63-
* XXX krb5_build_principal_alloc_va() when Heimdal is finally
64-
* XXX removed.
65-
*/
66-
krb5_error_code KRB5_CALLCONV
67-
krb5_build_principal_va(krb5_context context,
68-
krb5_principal princ,
69-
unsigned int rlen,
70-
const char *realm,
71-
va_list ap);
7261
typedef char *heim_general_string;
7362
typedef heim_general_string Realm;
7463
typedef Realm krb5_realm;
7564
typedef const char *krb5_const_realm;
7665

7766
static krb5_error_code
78-
krb5_make_principal(krb5_context context, krb5_principal principal,
67+
krb5_make_principal(krb5_context context, krb5_principal *principal,
7968
krb5_const_realm realm, ...)
8069
{
8170
krb5_realm temp_realm = NULL;
@@ -88,15 +77,9 @@ krb5_make_principal(krb5_context context, krb5_principal principal,
8877
realm=temp_realm;
8978
}
9079
va_start(ap, realm);
91-
/*
92-
* XXX Ideally we should be using krb5_build_principal_alloc_va()
93-
* XXX here because krb5_build_principal_va() is deprecated. But,
94-
* XXX this would require changes elsewhere in the calling code
95-
* XXX to call krb5_free_principal() elsewhere to free the
96-
* XXX principal. We can do that after Heimdal is removed from
97-
* XXX our tree.
98-
*/
99-
rc = krb5_build_principal_va(context, principal, strlen(realm), realm, ap);
80+
81+
rc = krb5_build_principal_alloc_va(context, principal, strlen(realm),
82+
realm, ap);
10083
va_end(ap);
10184
if (temp_realm)
10285
free(temp_realm);
@@ -273,13 +256,7 @@ get_su_principal(krb5_context context, const char *target_user, const char *curr
273256
if (rv != 0)
274257
return (errno);
275258
if (default_principal == NULL) {
276-
#ifdef MK_MITKRB5
277-
/* For MIT KRB5. */
278-
rv = krb5_make_principal(context, default_principal, NULL, current_user, NULL);
279-
#else
280-
/* For Heimdal. */
281259
rv = krb5_make_principal(context, &default_principal, NULL, current_user, NULL);
282-
#endif
283260
if (rv != 0) {
284261
PAM_LOG("Could not determine default principal name.");
285262
return (rv);

0 commit comments

Comments
 (0)