From: John Kohl Date: Tue, 12 Feb 1991 14:11:08 +0000 (+0000) Subject: MAYBE_OPEN/MAYBE_CLOSE changes X-Git-Tag: krb5-1.0-alpha4~299 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e212144fada81b33f70f3128e818b1e339178322;p=krb5.git MAYBE_OPEN/MAYBE_CLOSE changes file format version number code git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1673 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/ccache/file/fcc_gennew.c b/src/lib/krb5/ccache/file/fcc_gennew.c index ca9eeb0d3..5860b8336 100644 --- a/src/lib/krb5/ccache/file/fcc_gennew.c +++ b/src/lib/krb5/ccache/file/fcc_gennew.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 * . @@ -72,12 +72,29 @@ krb5_fcc_generate_new (id) strcpy(((krb5_fcc_data *) lid->data)->filename, scratch); /* Make sure the file name is reserved */ - ret = open(((krb5_fcc_data *) lid->data)->filename, O_CREAT | O_EXCL, 0); + ret = open(((krb5_fcc_data *) lid->data)->filename, + O_CREAT | O_EXCL | O_WRONLY, 0); if (ret == -1) return krb5_fcc_interpret(errno); else { + krb5_int16 fcc_fvno = htons(KRB5_FCC_FVNO); + int errsave, cnt; + /* Ignore user's umask, set mode = 0600 */ fchmod(ret, S_IREAD | S_IWRITE); + if ((cnt = write(ret, (char *)&fcc_fvno, sizeof(fcc_fvno))) + != sizeof(fcc_fvno)) { + errsave = errno; + (void) close(ret); + (void) unlink(((krb5_fcc_data *) lid->data)->filename); + return (cnt == -1) ? krb5_fcc_interpret(errsave) : KRB5_CC_IO; + } + if (close(ret) == -1) { + errsave = errno; + (void) unlink(((krb5_fcc_data *) lid->data)->filename); + return krb5_fcc_interpret(errsave); + } + close(ret); *id = lid; return KRB5_OK; diff --git a/src/lib/krb5/ccache/file/fcc_sseq.c b/src/lib/krb5/ccache/file/fcc_sseq.c index c794e084f..589e62668 100644 --- a/src/lib/krb5/ccache/file/fcc_sseq.c +++ b/src/lib/krb5/ccache/file/fcc_sseq.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 * . @@ -37,29 +37,28 @@ krb5_fcc_start_seq_get(id, cursor) krb5_cc_cursor *cursor; { krb5_fcc_cursor *fcursor; - int ret; + int ret = KRB5_OK; fcursor = (krb5_fcc_cursor *) malloc(sizeof(krb5_fcc_cursor)); if (fcursor == NULL) return KRB5_CC_NOMEM; - - /* Make sure we start reading right after the primary principal */ 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; + ret = krb5_fcc_open_file(id, FCC_OPEN_RDONLY); + if (ret) { + free((char *)fcursor); + return ret; + } } else - lseek(((krb5_fcc_data *) id->data)->fd, 0, L_SET); + /* seek after the version number */ + lseek(((krb5_fcc_data *) id->data)->fd, sizeof(krb5_int16), L_SET); + + /* Make sure we start reading right after the primary principal */ krb5_fcc_skip_principal(id); fcursor->pos = tell(((krb5_fcc_data *) id->data)->fd); *cursor = (krb5_cc_cursor) fcursor; - 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; }