add krb5_cc_next_cred_match() and krb5_cc_copy_cred_match()

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@13786 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
2004-04-25 17:20:19 +00:00
parent b24e10c46b
commit 5eca4bbf39
2 changed files with 69 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997-2003 Kungliga Tekniska H<>gskolan * Copyright (c) 1997-2004 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden). * (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved. * All rights reserved.
* *
@@ -378,6 +378,27 @@ krb5_cc_next_cred (krb5_context context,
return id->ops->get_next(context, id, cursor, creds); return id->ops->get_next(context, id, cursor, creds);
} }
/* like krb5_cc_next_cred, but allow for selective retrieval */
krb5_error_code
krb5_cc_next_cred_match(krb5_context context,
const krb5_ccache id,
krb5_cc_cursor * cursor,
krb5_creds * creds,
krb5_flags whichfields,
const krb5_creds * mcreds)
{
krb5_error_code ret;
while (1) {
ret = krb5_cc_next_cred(context, id, cursor, creds);
if (ret)
return ret;
if (mcreds == NULL || krb5_compare_creds(context, whichfields, mcreds, creds))
return 0;
krb5_free_creds_contents(context, creds);
}
}
/* /*
* Destroy the cursor `cursor'. * Destroy the cursor `cursor'.
*/ */
@@ -426,9 +447,12 @@ krb5_cc_set_flags(krb5_context context,
*/ */
krb5_error_code krb5_error_code
krb5_cc_copy_cache(krb5_context context, krb5_cc_copy_cache_match(krb5_context context,
const krb5_ccache from, const krb5_ccache from,
krb5_ccache to) krb5_ccache to,
krb5_flags whichfields,
const krb5_creds * mcreds,
unsigned int *matched)
{ {
krb5_error_code ret; krb5_error_code ret;
krb5_cc_cursor cursor; krb5_cc_cursor cursor;
@@ -436,27 +460,41 @@ krb5_cc_copy_cache(krb5_context context,
krb5_principal princ; krb5_principal princ;
ret = krb5_cc_get_principal(context, from, &princ); ret = krb5_cc_get_principal(context, from, &princ);
if(ret) if (ret)
return ret; return ret;
ret = krb5_cc_initialize(context, to, princ); ret = krb5_cc_initialize(context, to, princ);
if(ret){ if (ret) {
krb5_free_principal(context, princ); krb5_free_principal(context, princ);
return ret; return ret;
} }
ret = krb5_cc_start_seq_get(context, from, &cursor); ret = krb5_cc_start_seq_get(context, from, &cursor);
if(ret){ if (ret) {
krb5_free_principal(context, princ); krb5_free_principal(context, princ);
return ret; return ret;
} }
while(ret == 0 && krb5_cc_next_cred(context, from, &cursor, &cred) == 0){ if (matched)
*matched = 0;
while (ret == 0 &&
krb5_cc_next_cred_match(context, from, &cursor, &cred,
whichfields, mcreds) == 0) {
if (matched)
(*matched)++;
ret = krb5_cc_store_cred(context, to, &cred); ret = krb5_cc_store_cred(context, to, &cred);
krb5_free_creds_contents (context, &cred); krb5_free_creds_contents(context, &cred);
} }
krb5_cc_end_seq_get(context, from, &cursor); krb5_cc_end_seq_get(context, from, &cursor);
krb5_free_principal(context, princ); krb5_free_principal(context, princ);
return ret; return ret;
} }
krb5_error_code
krb5_cc_copy_cache(krb5_context context,
const krb5_ccache from,
krb5_ccache to)
{
return krb5_cc_copy_cache_match(context, from, to, 0, NULL, NULL);
}
/* /*
* Return the version of `id'. * Return the version of `id'.
*/ */

View File

@@ -1,4 +1,4 @@
.\" Copyright (c) 2003 Kungliga Tekniska H<>gskolan .\" Copyright (c) 2003-2004 Kungliga Tekniska H<>gskolan
.\" (Royal Institute of Technology, Stockholm, Sweden). .\" (Royal Institute of Technology, Stockholm, Sweden).
.\" All rights reserved. .\" All rights reserved.
.\" .\"
@@ -55,7 +55,8 @@
.Nm krb5_cc_get_type , .Nm krb5_cc_get_type ,
.Nm krb5_cc_get_version , .Nm krb5_cc_get_version ,
.Nm krb5_cc_initialize , .Nm krb5_cc_initialize ,
.Nm krb5_cc_next_cred .Nm krb5_cc_next_cred ,
.Nm krb5_cc_next_cred_match ,
.Nm krb5_cc_register , .Nm krb5_cc_register ,
.Nm krb5_cc_remove_cred , .Nm krb5_cc_remove_cred ,
.Nm krb5_cc_resolve , .Nm krb5_cc_resolve ,
@@ -208,6 +209,15 @@ Kerberos 5 Library (libkrb5, -lkrb5)
.Fa "krb5_cc_cursor *cursor" .Fa "krb5_cc_cursor *cursor"
.Fa "krb5_creds *creds" .Fa "krb5_creds *creds"
.Fc .Fc
.Ft krb5_error_code
.Fo krb5_cc_next_cred_match
.Fa "krb5_context *context"
.Fa "const krb5_ccache id"
.Fa "krb5_cc_cursor *cursor"
.Fa "krb5_creds *creds"
.Fa "krb5_flags whichfields"
.Fa "const krb5_creds *mcreds"
.Fc
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Li krb5_ccache .Li krb5_ccache
@@ -377,6 +387,16 @@ and advance
.Fa cursor . .Fa cursor .
Return 0 or an error code. Return 0 or an error code.
.Pp .Pp
.Fn krb5_cc_next_cred_match
is similar to
.Fn krb5_cc_next_cred
except that it will only return creds matching
.Fa whichfields
and
.Fa mcreds
(as interpreted by
.Xr krb5_compare_creds 3 . )
.Pp
.Fn krb5_cc_end_seq_get .Fn krb5_cc_end_seq_get
Destroys the cursor Destroys the cursor
.Fa cursor . .Fa cursor .