Skip to content

Commit

Permalink
Simplify password storage in krb5_gss_cred_id_rec
Browse files Browse the repository at this point in the history
The password is always zero-terminated, so we can store it as a char *
instead of a krb5_data.
  • Loading branch information
greghudson committed Jun 27, 2012
1 parent b192edd commit 5bff5c5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/lib/gssapi/krb5/acquire_cred.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ prep_ccache(krb5_context context, krb5_gss_cred_id_rec *cred,
{
krb5_error_code code;
krb5_principal ccache_princ;
krb5_data password_data = make_data(password->value, password->length);
krb5_data pwdata = make_data(password->value, password->length), pwcopy;
krb5_boolean eq;
const char *cctype;
krb5_ccache newcache = NULL;
Expand Down Expand Up @@ -353,10 +353,10 @@ prep_ccache(krb5_context context, krb5_gss_cred_id_rec *cred,
}

/* Stash the password for later. */
code = krb5int_copy_data_contents_add0(context, &password_data,
&cred->password);
code = krb5int_copy_data_contents_add0(context, &pwdata, &pwcopy);
if (code)
return code;
cred->password = pwcopy.data;

if (newcache) {
krb5_cc_close(context, ccache);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/gssapi/krb5/gssapiP_krb5.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ typedef struct _krb5_gss_cred_id_rec {
krb5_ccache ccache;
krb5_timestamp tgt_expire;
krb5_enctype *req_enctypes; /* limit negotiated enctypes to this list */
krb5_data password;
char *password;
} krb5_gss_cred_id_rec, *krb5_gss_cred_id_t;

typedef struct _krb5_gss_ctx_ext_rec {
Expand Down
7 changes: 3 additions & 4 deletions src/lib/gssapi/krb5/iakerb.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ iakerb_init_creds_ctx(iakerb_ctx_id_t ctx,
{
krb5_error_code code;

if (cred->iakerb_mech == 0 || cred->password.data == NULL) {
if (cred->iakerb_mech == 0 || cred->password == NULL) {
code = EINVAL;
goto cleanup;
}
Expand Down Expand Up @@ -444,8 +444,7 @@ iakerb_init_creds_ctx(iakerb_ctx_id_t ctx,
if (code != 0)
goto cleanup;

code = krb5_init_creds_set_password(ctx->k5c, ctx->icc,
cred->password.data);
code = krb5_init_creds_set_password(ctx->k5c, ctx->icc, cred->password);
if (code != 0)
goto cleanup;

Expand Down Expand Up @@ -678,7 +677,7 @@ iakerb_get_initial_state(iakerb_ctx_id_t ctx,
code = krb5_get_credentials(ctx->k5c, KRB5_GC_CACHED,
cred->ccache,
&in_creds, &out_creds);
if (code == KRB5_CC_NOTFOUND && cred->password.data != NULL) {
if (code == KRB5_CC_NOTFOUND && cred->password != NULL) {
*state = IAKERB_AS_REQ;
code = 0;
} else if (code == 0) {
Expand Down
8 changes: 3 additions & 5 deletions src/lib/gssapi/krb5/init_sec_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,16 @@ static krb5_error_code get_credentials(context, cred, server, now,

code = krb5_get_credentials(context, flags, cred->ccache,
&in_creds, &result_creds);
if (code == KRB5_CC_NOTFOUND && cred->password.data != NULL &&
if (code == KRB5_CC_NOTFOUND && cred->password != NULL &&
!cred->iakerb_mech) {
krb5_creds tgt_creds;

memset(&tgt_creds, 0, sizeof(tgt_creds));

/* No TGT in the ccache, but we can get one with the password. */
code = krb5_get_init_creds_password(context, &tgt_creds,
in_creds.client,
cred->password.data,
NULL, NULL,
0, NULL, NULL);
in_creds.client, cred->password,
NULL, NULL, 0, NULL, NULL);
if (code)
goto cleanup;

Expand Down
6 changes: 2 additions & 4 deletions src/lib/gssapi/krb5/rel_cred.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ krb5_gss_release_cred(minor_status, cred_handle)
if (cred->req_enctypes)
free(cred->req_enctypes);

if (cred->password.data) {
zap(cred->password.data, cred->password.length);
krb5_free_data_contents(context, &cred->password);
}
if (cred->password != NULL)
zapfree(cred->password, strlen(cred->password));

xfree(cred);

Expand Down

0 comments on commit 5bff5c5

Please sign in to comment.