summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Kohl <jtkohl@mit.edu>1991-02-12 14:11:55 +0000
committerJohn Kohl <jtkohl@mit.edu>1991-02-12 14:11:55 +0000
commitc325452f2bfe0e697535f4b1a78e8a0f5440b932 (patch)
treed53ee90f5d0a8f464266f9dd3f830c1090c45029 /src
parent55e4184b711671ace3f54aea3939eb3ad3fa5cb3 (diff)
adapted from scc_maybe
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1676 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r--src/lib/krb5/ccache/file/fcc_maybe.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/lib/krb5/ccache/file/fcc_maybe.c b/src/lib/krb5/ccache/file/fcc_maybe.c
new file mode 100644
index 000000000..2a2a8878a
--- /dev/null
+++ b/src/lib/krb5/ccache/file/fcc_maybe.c
@@ -0,0 +1,86 @@
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990, 1991 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/copyright.h>.
+ *
+ * This file contains the source code for conditional open/close calls.
+ */
+
+#include "fcc.h"
+
+krb5_error_code
+krb5_fcc_close_file (id)
+ krb5_ccache id;
+{
+ int ret;
+ krb5_fcc_data *data = (krb5_fcc_data *)id->data;
+
+ if (data->fd == -1) {
+ abort (); /* XXX? */
+ }
+ ret = close (data->fd);
+ data->fd = -1;
+ return (ret == -1) ? krb5_fcc_interpret (errno) : 0;
+}
+
+krb5_error_code
+krb5_fcc_open_file (id, mode)
+ krb5_ccache id;
+ int mode;
+{
+ krb5_fcc_data *data = (krb5_fcc_data *)id->data;
+ krb5_int16 fcc_fvno = htons(KRB5_FCC_FVNO);
+ int fd;
+ int open_flag;
+
+ if (data->fd != -1) {
+ /* Don't know what state it's in; shut down and start anew. */
+ (void) close (data->fd);
+ data->fd = -1;
+ }
+ switch(mode) {
+ case FCC_OPEN_AND_ERASE:
+ open_flag = O_CREAT|O_TRUNC|O_RDWR;
+ break;
+ case FCC_OPEN_RDWR:
+ open_flag = O_RDWR;
+ break;
+ case FCC_OPEN_RDONLY:
+ default:
+ open_flag = O_RDONLY;
+ break;
+ }
+
+ fd = open (data->filename, open_flag, 0600);
+ if (fd == -1)
+ return krb5_fcc_interpret (errno);
+
+ if (mode == FCC_OPEN_AND_ERASE) {
+ /* write the version number */
+ int errsave, cnt;
+
+ if ((cnt = write(fd, (char *)&fcc_fvno, sizeof(fcc_fvno))) !=
+ sizeof(fcc_fvno)) {
+ errsave = errno;
+ (void) close(fd);
+ return (cnt == -1) ? krb5_fcc_interpret(errsave) : KRB5_CC_IO;
+ }
+ } else {
+ /* verify a valid version number is there */
+ if (read(fd, (char *)&fcc_fvno, sizeof(fcc_fvno)) !=
+ sizeof(fcc_fvno)) {
+ (void) close(fd);
+ return KRB5_CCACHE_BADVNO;
+ }
+ if (fcc_fvno != htons(KRB5_FCC_FVNO)) {
+ (void) close(fd);
+ return KRB5_CCACHE_BADVNO;
+ }
+ }
+ data->fd = fd;
+ return 0;
+}