*/
#if !defined(lint) && !defined(SABER)
-static char fcc_resolve_c[] = "$Id$";
+static char fcc_init_c[] = "$Id$";
#endif /* !lint && !SABER */
#include <krb5/copyright.h>
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;
}
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;
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;
}
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;
}
/* 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);
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
}