* $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>.
{
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);
* $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>.
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;
}
* $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>.
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;
}
* $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>.
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;
}
* $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>.
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;
}
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);
* $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>.
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;
* $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>.
#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);
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
}