From 5eca4bbf39522e12d9c2155fa9107524851c0eb2 Mon Sep 17 00:00:00 2001 From: Johan Danielsson Date: Sun, 25 Apr 2004 17:20:19 +0000 Subject: [PATCH] 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 --- lib/krb5/cache.c | 56 +++++++++++++++++++++++++++++++++++------- lib/krb5/krb5_ccache.3 | 24 ++++++++++++++++-- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/lib/krb5/cache.c b/lib/krb5/cache.c index 1e786e6a8..7c6ad0c11 100644 --- a/lib/krb5/cache.c +++ b/lib/krb5/cache.c @@ -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). * All rights reserved. * @@ -378,6 +378,27 @@ krb5_cc_next_cred (krb5_context context, 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'. */ @@ -426,9 +447,12 @@ krb5_cc_set_flags(krb5_context context, */ krb5_error_code -krb5_cc_copy_cache(krb5_context context, - const krb5_ccache from, - krb5_ccache to) +krb5_cc_copy_cache_match(krb5_context context, + const krb5_ccache from, + krb5_ccache to, + krb5_flags whichfields, + const krb5_creds * mcreds, + unsigned int *matched) { krb5_error_code ret; krb5_cc_cursor cursor; @@ -436,27 +460,41 @@ krb5_cc_copy_cache(krb5_context context, krb5_principal princ; ret = krb5_cc_get_principal(context, from, &princ); - if(ret) + if (ret) return ret; ret = krb5_cc_initialize(context, to, princ); - if(ret){ + if (ret) { krb5_free_principal(context, princ); return ret; } ret = krb5_cc_start_seq_get(context, from, &cursor); - if(ret){ + if (ret) { krb5_free_principal(context, princ); 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); - krb5_free_creds_contents (context, &cred); + krb5_free_creds_contents(context, &cred); } krb5_cc_end_seq_get(context, from, &cursor); krb5_free_principal(context, princ); 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'. */ diff --git a/lib/krb5/krb5_ccache.3 b/lib/krb5/krb5_ccache.3 index 5ededd8c0..fd78e4748 100644 --- a/lib/krb5/krb5_ccache.3 +++ b/lib/krb5/krb5_ccache.3 @@ -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). .\" All rights reserved. .\" @@ -55,7 +55,8 @@ .Nm krb5_cc_get_type , .Nm krb5_cc_get_version , .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_remove_cred , .Nm krb5_cc_resolve , @@ -208,6 +209,15 @@ Kerberos 5 Library (libkrb5, -lkrb5) .Fa "krb5_cc_cursor *cursor" .Fa "krb5_creds *creds" .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 The .Li krb5_ccache @@ -377,6 +387,16 @@ and advance .Fa cursor . Return 0 or an error code. .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 Destroys the cursor .Fa cursor .