summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Kohl <jtkohl@mit.edu>1991-02-12 14:11:26 +0000
committerJohn Kohl <jtkohl@mit.edu>1991-02-12 14:11:26 +0000
commit500ed404b42717345defa974eab170a677872ab9 (patch)
treec016f5a919d0ca64f7572aa583bd0144b16b986e
parente212144fada81b33f70f3128e818b1e339178322 (diff)
downloadkrb5-500ed404b42717345defa974eab170a677872ab9.tar.gz
krb5-500ed404b42717345defa974eab170a677872ab9.tar.xz
krb5-500ed404b42717345defa974eab170a677872ab9.zip
MAYBE_OPEN/MAYBE_CLOSE changes
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1674 dc483132-0cff-0310-8789-dd5450dbe970
-rw-r--r--src/lib/krb5/ccache/file/fcc_close.c13
-rw-r--r--src/lib/krb5/ccache/file/fcc_eseq.c15
-rw-r--r--src/lib/krb5/ccache/file/fcc_gprin.c20
-rw-r--r--src/lib/krb5/ccache/file/fcc_init.c22
-rw-r--r--src/lib/krb5/ccache/file/fcc_nseq.c20
-rw-r--r--src/lib/krb5/ccache/file/fcc_sflags.c14
-rw-r--r--src/lib/krb5/ccache/file/fcc_store.c22
7 files changed, 38 insertions, 88 deletions
diff --git a/src/lib/krb5/ccache/file/fcc_close.c b/src/lib/krb5/ccache/file/fcc_close.c
index eadab4ad3d..dd3bc1c825 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
* <krb5/copyright.h>.
@@ -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 b65ed25ffc..700d21d723 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
* <krb5/copyright.h>.
@@ -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 209dad1576..5d0334cee0 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
* <krb5/copyright.h>.
@@ -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 6fd6e07f1c..640165e97f 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
* <krb5/copyright.h>.
@@ -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 9208701190..d743961c80 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
* <krb5/copyright.h>.
@@ -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 2b04eaddfa..20b594a961 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
* <krb5/copyright.h>.
@@ -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 7f31a30e65..336946281b 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
* <krb5/copyright.h>.
@@ -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
}