From 91dc7b8c15704b0a875bc6272cef3478e1900f5f Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Wed, 4 Aug 2004 06:58:17 +0000 Subject: [PATCH] * rc-int.h (struct _krb5_rc_ops): Add new member, recover_or_init. * rc_dfl.c (krb5_rc_dfl_init_locked): New function, with most of the content of old krb5_rc_dfl_init. (krb5_rc_dfl_init): Call it. (krb5_rc_dfl_recover_or_init): New function. * rc_dfl.h (krb5_rc_dfl_recover_or_init): Declare. * rcdef.c (krb5_rc_dfl_ops): Initialize new field. * rc_none.c (krb5_rc_none_recover_or_init): New macro. (krb5_rc_none_ops): Initialize new field. * rcfns.c (krb5_rc_recover_or_initialize): New function. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16640 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/rcache/ChangeLog | 14 +++++++++++++ src/lib/krb5/rcache/rc-int.h | 2 ++ src/lib/krb5/rcache/rc_dfl.c | 38 ++++++++++++++++++++++++++++------- src/lib/krb5/rcache/rc_dfl.h | 2 ++ src/lib/krb5/rcache/rc_none.c | 2 ++ src/lib/krb5/rcache/rcdef.c | 1 + src/lib/krb5/rcache/rcfns.c | 7 +++++++ 7 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/lib/krb5/rcache/ChangeLog b/src/lib/krb5/rcache/ChangeLog index bf5c2f7b5..24b04b015 100644 --- a/src/lib/krb5/rcache/ChangeLog +++ b/src/lib/krb5/rcache/ChangeLog @@ -1,3 +1,17 @@ +2004-08-03 Ken Raeburn + + * rc-int.h (struct _krb5_rc_ops): Add new member, + recover_or_init. + * rc_dfl.c (krb5_rc_dfl_init_locked): New function, with most of + the content of old krb5_rc_dfl_init. + (krb5_rc_dfl_init): Call it. + (krb5_rc_dfl_recover_or_init): New function. + * rc_dfl.h (krb5_rc_dfl_recover_or_init): Declare. + * rcdef.c (krb5_rc_dfl_ops): Initialize new field. + * rc_none.c (krb5_rc_none_recover_or_init): New macro. + (krb5_rc_none_ops): Initialize new field. + * rcfns.c (krb5_rc_recover_or_initialize): New function. + 2004-07-30 Ken Raeburn * rc_none.c: New file. diff --git a/src/lib/krb5/rcache/rc-int.h b/src/lib/krb5/rcache/rc-int.h index 239f0c0a7..2f09d239a 100644 --- a/src/lib/krb5/rcache/rc-int.h +++ b/src/lib/krb5/rcache/rc-int.h @@ -49,6 +49,8 @@ struct _krb5_rc_ops { (krb5_context, krb5_rcache,krb5_deltat); /* create */ krb5_error_code (KRB5_CALLCONV *recover) (krb5_context, krb5_rcache); /* open */ + krb5_error_code (KRB5_CALLCONV *recover_or_init) + (krb5_context, krb5_rcache,krb5_deltat); krb5_error_code (KRB5_CALLCONV *destroy) (krb5_context, krb5_rcache); krb5_error_code (KRB5_CALLCONV *close) diff --git a/src/lib/krb5/rcache/rc_dfl.c b/src/lib/krb5/rcache/rc_dfl.c index c4f845178..586716a3d 100644 --- a/src/lib/krb5/rcache/rc_dfl.c +++ b/src/lib/krb5/rcache/rc_dfl.c @@ -192,32 +192,39 @@ krb5_rc_dfl_get_span(krb5_context context, krb5_rcache id, } krb5_error_code KRB5_CALLCONV -krb5_rc_dfl_init(krb5_context context, krb5_rcache id, krb5_deltat lifespan) +krb5_rc_dfl_init_locked(krb5_context context, krb5_rcache id, krb5_deltat lifespan) { struct dfl_data *t = (struct dfl_data *)id->data; krb5_error_code retval; - retval = k5_mutex_lock(&id->lock); - if (retval) - return retval; t->lifespan = lifespan ? lifespan : context->clockskew; /* default to clockskew from the context */ #ifndef NOIOSTUFF if ((retval = krb5_rc_io_creat(context, &t->d, &t->name))) { - k5_mutex_unlock(&id->lock); return retval; } if ((krb5_rc_io_write(context, &t->d, (krb5_pointer) &t->lifespan, sizeof(t->lifespan)) || krb5_rc_io_sync(context, &t->d))) { - k5_mutex_unlock(&id->lock); return KRB5_RC_IO; } #endif - k5_mutex_unlock(&id->lock); return 0; } +krb5_error_code KRB5_CALLCONV +krb5_rc_dfl_init(krb5_context context, krb5_rcache id, krb5_deltat lifespan) +{ + krb5_error_code retval; + + retval = k5_mutex_lock(&id->lock); + if (retval) + return retval; + retval = krb5_rc_dfl_init_locked(context, id, lifespan); + k5_mutex_unlock(&id->lock); + return retval; +} + /* Called with the mutex already locked. */ krb5_error_code krb5_rc_dfl_close_no_free(krb5_context context, krb5_rcache id) @@ -503,6 +510,23 @@ krb5_rc_dfl_recover(krb5_context context, krb5_rcache id) return ret; } +krb5_error_code KRB5_CALLCONV +krb5_rc_dfl_recover_or_init(krb5_context context, krb5_rcache id, + krb5_deltat lifespan) +{ + struct dfl_data *t = (struct dfl_data *)id->data; + krb5_error_code retval; + + retval = k5_mutex_lock(&id->lock); + if (retval) + return retval; + retval = krb5_rc_dfl_recover_locked(context, id); + if (retval) + retval = krb5_rc_dfl_init_locked(context, id, lifespan); + k5_mutex_unlock(&id->lock); + return retval; +} + static krb5_error_code krb5_rc_io_store(krb5_context context, struct dfl_data *t, krb5_donot_replay *rep) diff --git a/src/lib/krb5/rcache/rc_dfl.h b/src/lib/krb5/rcache/rc_dfl.h index e50ed753b..d5fdd1a69 100644 --- a/src/lib/krb5/rcache/rc_dfl.h +++ b/src/lib/krb5/rcache/rc_dfl.h @@ -20,6 +20,8 @@ krb5_error_code KRB5_CALLCONV krb5_rc_dfl_init krb5_error_code KRB5_CALLCONV krb5_rc_dfl_recover (krb5_context, krb5_rcache); +krb5_error_code KRB5_CALLCONV krb5_rc_dfl_recover_or_init + (krb5_context, krb5_rcache, krb5_deltat); krb5_error_code KRB5_CALLCONV krb5_rc_dfl_destroy (krb5_context, krb5_rcache); diff --git a/src/lib/krb5/rcache/rc_none.c b/src/lib/krb5/rcache/rc_none.c index 3ad45247b..a306f86fe 100644 --- a/src/lib/krb5/rcache/rc_none.c +++ b/src/lib/krb5/rcache/rc_none.c @@ -35,6 +35,7 @@ krb5_rc_none_init(krb5_context ctx, krb5_rcache rc, krb5_deltat d) { return 0; } +#define krb5_rc_none_recover_or_init krb5_rc_none_init static krb5_error_code KRB5_CALLCONV krb5_rc_none_noargs(krb5_context ctx, krb5_rcache rc) @@ -76,6 +77,7 @@ const krb5_rc_ops krb5_rc_none_ops = { "none", krb5_rc_none_init, krb5_rc_none_recover, + krb5_rc_none_recover_or_init, krb5_rc_none_destroy, krb5_rc_none_close, krb5_rc_none_store, diff --git a/src/lib/krb5/rcache/rcdef.c b/src/lib/krb5/rcache/rcdef.c index 73b2eb968..0aa334fa8 100644 --- a/src/lib/krb5/rcache/rcdef.c +++ b/src/lib/krb5/rcache/rcdef.c @@ -37,6 +37,7 @@ const krb5_rc_ops krb5_rc_dfl_ops = "dfl", krb5_rc_dfl_init, krb5_rc_dfl_recover, + krb5_rc_dfl_recover_or_init, krb5_rc_dfl_destroy, krb5_rc_dfl_close, krb5_rc_dfl_store, diff --git a/src/lib/krb5/rcache/rcfns.c b/src/lib/krb5/rcache/rcfns.c index d37b4f6ec..bcbcaf4be 100644 --- a/src/lib/krb5/rcache/rcfns.c +++ b/src/lib/krb5/rcache/rcfns.c @@ -37,6 +37,13 @@ krb5_rc_initialize (krb5_context context, krb5_rcache id, krb5_deltat span) return krb5_x(id->ops->init,(context, id, span)); } +krb5_error_code KRB5_CALLCONV +krb5_rc_recover_or_initialize (krb5_context context, krb5_rcache id, + krb5_deltat span) +{ + return krb5_x(id->ops->recover_or_init,(context, id, span)); +} + krb5_error_code KRB5_CALLCONV krb5_rc_recover (krb5_context context, krb5_rcache id) { -- 2.26.2