From: John Kohl Date: Tue, 12 Feb 1991 14:11:26 +0000 (+0000) Subject: MAYBE_OPEN/MAYBE_CLOSE changes X-Git-Tag: krb5-1.0-alpha4~298 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=500ed404b42717345defa974eab170a677872ab9;p=krb5.git MAYBE_OPEN/MAYBE_CLOSE changes git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1674 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/ccache/file/fcc_close.c b/src/lib/krb5/ccache/file/fcc_close.c index eadab4ad3..dd3bc1c82 100644 --- a/src/lib/krb5/ccache/file/fcc_close.c +++ b/src/lib/krb5/ccache/file/fcc_close.c @@ -2,7 +2,7 @@ * $Source$ * $Author$ * - * Copyright 1990 by the Massachusetts Institute of Technology. + * Copyright 1990,1991 by the Massachusetts Institute of Technology. * * For copying and distribution information, please see the file * . @@ -32,15 +32,8 @@ krb5_fcc_close(id) { register int closeval = KRB5_OK; - if (OPENCLOSE(id)) { - closeval = close(((krb5_fcc_data *) id->data)->fd); - ((krb5_fcc_data *) id->data)->fd = -1; - if (closeval == -1) { - closeval = krb5_fcc_interpret(errno); - } else - closeval = KRB5_OK; - - } + MAYBE_CLOSE(id, closeval); + xfree(((krb5_fcc_data *) id->data)->filename); xfree(((krb5_fcc_data *) id->data)); xfree(id); diff --git a/src/lib/krb5/ccache/file/fcc_eseq.c b/src/lib/krb5/ccache/file/fcc_eseq.c index b65ed25ff..700d21d72 100644 --- a/src/lib/krb5/ccache/file/fcc_eseq.c +++ b/src/lib/krb5/ccache/file/fcc_eseq.c @@ -2,7 +2,7 @@ * $Source$ * $Author$ * - * Copyright 1990 by the Massachusetts Institute of Technology. + * Copyright 1990,1991 by the Massachusetts Institute of Technology. * * For copying and distribution information, please see the file * . @@ -35,14 +35,15 @@ krb5_fcc_end_seq_get(id, cursor) krb5_ccache id; krb5_cc_cursor *cursor; { - if (OPENCLOSE(id)) { - close(((krb5_fcc_data *) id->data)->fd); - ((krb5_fcc_data *) id->data)->fd = -1; - } - + int kret = KRB5_OK; + + /* don't close; it may be left open by the caller, + and if not, fcc_start_seq_get and/or fcc_next_cred will do the + MAYBE_CLOSE. + MAYBE_CLOSE(id, kret); */ xfree((krb5_fcc_cursor *) *cursor); - return KRB5_OK; + return kret; } diff --git a/src/lib/krb5/ccache/file/fcc_gprin.c b/src/lib/krb5/ccache/file/fcc_gprin.c index 209dad157..5d0334cee 100644 --- a/src/lib/krb5/ccache/file/fcc_gprin.c +++ b/src/lib/krb5/ccache/file/fcc_gprin.c @@ -2,7 +2,7 @@ * $Source$ * $Author$ * - * Copyright 1990 by the Massachusetts Institute of Technology. + * Copyright 1990,1991 by the Massachusetts Institute of Technology. * * For copying and distribution information, please see the file * . @@ -35,23 +35,15 @@ krb5_fcc_get_principal(id, princ) krb5_ccache id; krb5_principal *princ; { - krb5_error_code kret; + krb5_error_code kret = KRB5_OK; - if (OPENCLOSE(id)) { - kret = open(((krb5_fcc_data *) id->data)->filename, O_RDONLY, 0); - if (kret < 0) - return krb5_fcc_interpret(errno); - ((krb5_fcc_data *) id->data)->fd = kret; - } - else - lseek(((krb5_fcc_data *) id->data)->fd, 0, L_SET); + MAYBE_OPEN(id, FCC_OPEN_RDONLY); + /* make sure we're beyond the vno */ + lseek(((krb5_fcc_data *) id->data)->fd, sizeof(krb5_int16), L_SET); kret = krb5_fcc_read_principal(id, princ); - if (OPENCLOSE(id)) { - close(((krb5_fcc_data *) id->data)->fd); - ((krb5_fcc_data *) id->data)->fd = -1; - } + MAYBE_CLOSE(id, kret); return kret; } diff --git a/src/lib/krb5/ccache/file/fcc_init.c b/src/lib/krb5/ccache/file/fcc_init.c index 6fd6e07f1..640165e97 100644 --- a/src/lib/krb5/ccache/file/fcc_init.c +++ b/src/lib/krb5/ccache/file/fcc_init.c @@ -2,7 +2,7 @@ * $Source$ * $Author$ * - * Copyright 1990 by the Massachusetts Institute of Technology. + * Copyright 1990,1991 by the Massachusetts Institute of Technology. * * For copying and distribution information, please see the file * . @@ -35,30 +35,20 @@ krb5_fcc_initialize(id, princ) krb5_ccache id; krb5_principal princ; { - int ret; + int ret = KRB5_OK; - ret = open(((krb5_fcc_data *) id->data)->filename, O_CREAT | O_TRUNC | - O_RDWR, 0); - if (ret < 0) - return krb5_fcc_interpret(errno); - ((krb5_fcc_data *) id->data)->fd = ret; + MAYBE_OPEN(id, FCC_OPEN_AND_ERASE); ret = fchmod(((krb5_fcc_data *) id->data)->fd, S_IREAD | S_IWRITE); if (ret == -1) { ret = krb5_fcc_interpret(errno); - if (OPENCLOSE(id)) { - close(((krb5_fcc_data *)id->data)->fd); - ((krb5_fcc_data *) id->data)->fd = -1; - } + MAYBE_CLOSE(id, ret); return ret; } krb5_fcc_store_principal(id, princ); - if (OPENCLOSE(id)) { - close(((krb5_fcc_data *) id->data)->fd); - ((krb5_fcc_data *) id->data)->fd = -1; - } - return KRB5_OK; + MAYBE_CLOSE(id, ret); + return ret; } diff --git a/src/lib/krb5/ccache/file/fcc_nseq.c b/src/lib/krb5/ccache/file/fcc_nseq.c index 920870119..d743961c8 100644 --- a/src/lib/krb5/ccache/file/fcc_nseq.c +++ b/src/lib/krb5/ccache/file/fcc_nseq.c @@ -2,7 +2,7 @@ * $Source$ * $Author$ * - * Copyright 1990 by the Massachusetts Institute of Technology. + * Copyright 1990,1991 by the Massachusetts Institute of Technology. * * For copying and distribution information, please see the file * . @@ -53,22 +53,14 @@ krb5_fcc_next_cred(id, cursor, creds) memset((char *)creds, 0, sizeof(*creds)); - if (OPENCLOSE(id)) { - ret = open(((krb5_fcc_data *) id->data)->filename, O_RDONLY, 0); - if (ret < 0) - return krb5_fcc_interpret(errno); - ((krb5_fcc_data *) id->data)->fd = ret; - } + MAYBE_OPEN(id, FCC_OPEN_RDONLY); fcursor = (krb5_fcc_cursor *) *cursor; ret = lseek(((krb5_fcc_data *) id->data)->fd, fcursor->pos, L_SET); if (ret < 0) { ret = krb5_fcc_interpret(errno); - if (OPENCLOSE(id)) { - (void) close(((krb5_fcc_data *)id->data)->fd); - ((krb5_fcc_data *)id->data)->fd = -1; - } + MAYBE_CLOSE(id, ret); return ret; } @@ -97,10 +89,8 @@ krb5_fcc_next_cred(id, cursor, creds) cursor = (krb5_cc_cursor *) fcursor; lose: - if (OPENCLOSE(id)) { - close(((krb5_fcc_data *) id->data)->fd); - ((krb5_fcc_data *) id->data)->fd = -1; - } + MAYBE_CLOSE(id, kret); /* won't overwrite kret + if already set */ if (kret != KRB5_OK) { if (creds->client) krb5_free_principal(creds->client); diff --git a/src/lib/krb5/ccache/file/fcc_sflags.c b/src/lib/krb5/ccache/file/fcc_sflags.c index 2b04eaddf..20b594a96 100644 --- a/src/lib/krb5/ccache/file/fcc_sflags.c +++ b/src/lib/krb5/ccache/file/fcc_sflags.c @@ -2,7 +2,7 @@ * $Source$ * $Author$ * - * Copyright 1990 by the Massachusetts Institute of Technology. + * Copyright 1990,1991 by the Massachusetts Institute of Technology. * * For copying and distribution information, please see the file * . @@ -34,24 +34,16 @@ krb5_fcc_set_flags(id, flags) krb5_ccache id; krb5_flags flags; { - 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; + (void) krb5_fcc_close_file (id); } } 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 krb5_fcc_interpret(errno); - ((krb5_fcc_data *) id->data)->fd = ret; - } + MAYBE_OPEN(id, FCC_OPEN_RDONLY); } ((krb5_fcc_data *) id->data)->flags = flags; diff --git a/src/lib/krb5/ccache/file/fcc_store.c b/src/lib/krb5/ccache/file/fcc_store.c index 7f31a30e6..336946281 100644 --- a/src/lib/krb5/ccache/file/fcc_store.c +++ b/src/lib/krb5/ccache/file/fcc_store.c @@ -2,7 +2,7 @@ * $Source$ * $Author$ * - * Copyright 1990 by the Massachusetts Institute of Technology. + * Copyright 1990,1991 by the Massachusetts Institute of Technology. * * For copying and distribution information, please see the file * . @@ -39,18 +39,14 @@ krb5_fcc_store(id, creds) #define TCHECK(ret) if (ret != KRB5_OK) goto lose; krb5_error_code ret; - /* Make sure we are writing to the end of the file */ - if (OPENCLOSE(id)) { - ret = open(((krb5_fcc_data *) id->data)->filename, - O_RDWR | O_APPEND, 0); - if (ret < 0) - return krb5_fcc_interpret(errno); - ((krb5_fcc_data *) id->data)->fd = ret; - } + MAYBE_OPEN(id, FCC_OPEN_RDWR); + /* Make sure we are writing to the end of the file */ ret = lseek(((krb5_fcc_data *) id->data)->fd, 0, L_XTND); - if (ret < 0) + if (ret < 0) { + MAYBE_CLOSE_IGNORE(id); return krb5_fcc_interpret(errno); + } ret = krb5_fcc_store_principal(id, creds->client); TCHECK(ret); @@ -74,11 +70,7 @@ krb5_fcc_store(id, creds) TCHECK(ret); lose: - - if (OPENCLOSE(id)) { - close(((krb5_fcc_data *) id->data)->fd); - ((krb5_fcc_data *) id->data)->fd = -1; - } + MAYBE_CLOSE(id, ret); return ret; #undef TCHECK }