From 9a8a50776c627eebc56111094be9205580d01491 Mon Sep 17 00:00:00 2001 From: John Kohl Date: Tue, 1 May 1990 17:07:11 +0000 Subject: [PATCH] fix openclose stuff git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@650 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/ccache/file/fcc_init.c | 7 ++++--- src/lib/krb5/ccache/file/fcc_nseq.c | 5 +++-- src/lib/krb5/ccache/file/fcc_sflags.c | 25 ++++++++++++++++++++++--- src/lib/krb5/ccache/file/fcc_sseq.c | 5 +++-- src/lib/krb5/ccache/file/fcc_store.c | 11 ++++++----- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/lib/krb5/ccache/file/fcc_init.c b/src/lib/krb5/ccache/file/fcc_init.c index a135378d5..71ee8cea2 100644 --- a/src/lib/krb5/ccache/file/fcc_init.c +++ b/src/lib/krb5/ccache/file/fcc_init.c @@ -11,7 +11,7 @@ */ #if !defined(lint) && !defined(SABER) -static char fcc_resolve_c[] = "$Id$"; +static char fcc_init_c[] = "$Id$"; #endif /* !lint && !SABER */ #include @@ -49,9 +49,10 @@ krb5_fcc_initialize(id, princ) krb5_fcc_store_principal(id, princ); - if (OPENCLOSE(id)) + if (OPENCLOSE(id)) { close(((krb5_fcc_data *) id->data)->fd); - + ((krb5_fcc_data *) id->data)->fd = -1; + } return KRB5_OK; } diff --git a/src/lib/krb5/ccache/file/fcc_nseq.c b/src/lib/krb5/ccache/file/fcc_nseq.c index 4ed792d4d..a6dc1b7f4 100644 --- a/src/lib/krb5/ccache/file/fcc_nseq.c +++ b/src/lib/krb5/ccache/file/fcc_nseq.c @@ -84,9 +84,10 @@ krb5_fcc_next_cred(id, cursor, creds) fcursor->pos = tell(((krb5_fcc_data *) id->data)->fd); cursor = (krb5_cc_cursor *) fcursor; - if (OPENCLOSE(id)) + if (OPENCLOSE(id)) { close(((krb5_fcc_data *) id->data)->fd); - + ((krb5_fcc_data *) id->data)->fd = -1; + } lose: return kret; diff --git a/src/lib/krb5/ccache/file/fcc_sflags.c b/src/lib/krb5/ccache/file/fcc_sflags.c index 3fea711c9..f27d7b9a5 100644 --- a/src/lib/krb5/ccache/file/fcc_sflags.c +++ b/src/lib/krb5/ccache/file/fcc_sflags.c @@ -34,8 +34,27 @@ krb5_fcc_set_flags(id, flags) krb5_ccache id; krb5_flags flags; { - /* XXX This should check for illegal combinations, if any.. */ - ((krb5_fcc_data *) id->data)->flags = flags; - return KRB5_OK; + krb5_error_code ret; + + /* XXX This should check for illegal combinations, if any.. */ + if (flags & KRB5_TC_OPENCLOSE) { + /* asking to turn on OPENCLOSE mode */ + if (!OPENCLOSE(id)) { + (void) close(((krb5_fcc_data *) id->data)->fd); + ((krb5_fcc_data *) id->data)->fd = -1; + } + } else { + /* asking to turn off OPENCLOSE mode, meaning it must be + left open. We open if it's not yet open */ + if (OPENCLOSE(id)) { + ret = open(((krb5_fcc_data *) id->data)->filename, O_RDONLY, 0); + if (ret < 0) + return errno; + ((krb5_fcc_data *) id->data)->fd = ret; + } + } + + ((krb5_fcc_data *) id->data)->flags = flags; + return KRB5_OK; } diff --git a/src/lib/krb5/ccache/file/fcc_sseq.c b/src/lib/krb5/ccache/file/fcc_sseq.c index 1fd1d0498..e0850596c 100644 --- a/src/lib/krb5/ccache/file/fcc_sseq.c +++ b/src/lib/krb5/ccache/file/fcc_sseq.c @@ -57,8 +57,9 @@ krb5_fcc_start_seq_get(id, cursor) fcursor->pos = tell(((krb5_fcc_data *) id->data)->fd); *cursor = (krb5_cc_cursor) fcursor; - if (OPENCLOSE(id)) + if (OPENCLOSE(id)) { close(((krb5_fcc_data *) id->data)->fd); - + ((krb5_fcc_data *) id->data)->fd = -1; + } return KRB5_OK; } diff --git a/src/lib/krb5/ccache/file/fcc_store.c b/src/lib/krb5/ccache/file/fcc_store.c index a98a3f9ed..6562b543b 100644 --- a/src/lib/krb5/ccache/file/fcc_store.c +++ b/src/lib/krb5/ccache/file/fcc_store.c @@ -41,11 +41,11 @@ krb5_fcc_store(id, creds) /* Make sure we are writing to the end of the file */ if (OPENCLOSE(id)) { - ((krb5_fcc_data *) id->data)->fd = open(((krb5_fcc_data *) id->data) - ->filename, - O_RDWR | O_APPEND, 0); + ret = open(((krb5_fcc_data *) id->data)->filename, + O_RDWR | O_APPEND, 0); if (((krb5_fcc_data *) id->data)->fd < 0) return errno; + ((krb5_fcc_data *) id->data)->fd = ret; } ret = lseek(((krb5_fcc_data *) id->data)->fd, 0, L_XTND); @@ -71,9 +71,10 @@ krb5_fcc_store(id, creds) lose: - if (OPENCLOSE(id)) + if (OPENCLOSE(id)) { close(((krb5_fcc_data *) id->data)->fd); - + ((krb5_fcc_data *) id->data)->fd = -1; + } return ret; #undef TCHECK } -- 2.26.2