#include "fcc-os.h"
/* XXX Until I find out the right #define for this.. XXX */
-#define KRB5_OK 0
-#define KRB5_NOMEM 1
-#define KRB5_NOTFOUND 2
+#define KRB5_OK -1000
+#define KRB5_NOMEM -1001
+#define KRB5_NOTFOUND -1002
+#define KRB5_EOF -1003
#define KRB5_FCC_MAXLEN 100
#ifndef TKT_ROOT
#define TKT_ROOT "/tmp/tkt"
#endif
+/* macros to make checking flags easier */
+#define OPENCLOSE(id) (((krb5_fcc_data *)id->data)->flags & KRB5_TC_OPENCLOSE)
+
typedef struct _krb5_fcc_data {
char *filename;
int fd;
+ krb5_flags flags;
} krb5_fcc_data;
/* An off_t can be arbitrarily complex */
* Effects:
* Closes the file cache, invalidates the id, and frees any resources
* associated with the cache.
- *
- * Errors:
- * system errors
- * permission errors
*/
krb5_error_code
krb5_fcc_close(id)
krb5_ccache id;
{
- int ret;
-
-#ifdef OPENCLOSE
-#else
- close(((krb5_fcc_data *) id->data)->fd);
-#endif
+ if (OPENCLOSE(id))
+ close(((krb5_fcc_data *) id->data)->fd);
- ret = unlink(((krb5_fcc_data *) id->data)->filename);
- if (ret < 0)
- return errno;
-
free(((krb5_fcc_data *) id->data)->filename);
free(((krb5_fcc_data *) id->data));
free(id);
char zeros[BUFSIZ];
int ret, i;
-#ifdef OPENCLOSE
- ((krb5_fcc_data *) id->data)->fd = open(((krb5_fcc_data *) id->data)->
- filename, O_RDWR, 0);
- if (((krb5_fcc_data *) id->data)->fd < 0)
- return errno;
-#else
- lseek(((krb5_fcc_data *) id->data)->fd, 0, L_SET);
-#endif
+ if (OPENCLOSE(id)) {
+ ((krb5_fcc_data *) id->data)->fd = open(((krb5_fcc_data *) id->data)
+ ->filename, O_RDWR, 0);
+ if (((krb5_fcc_data *) id->data)->fd < 0)
+ return errno;
+ }
+ else
+ lseek(((krb5_fcc_data *) id->data)->fd, 0, L_SET);
+
ret = unlink(((krb5_fcc_data *) id->data)->filename);
if (ret < 0)
return errno;
krb5_ccache id;
krb5_cc_cursor *cursor;
{
-#ifdef OPENCLOSE
-#else
- close(((krb5_fcc_data *) id->data)->fd);
-#endif
+ if (OPENCLOSE(id))
+ close(((krb5_fcc_data *) id->data)->fd);
- free((krb5_fcc_cursor *) cursor);
+ free((krb5_fcc_cursor *) *cursor);
return KRB5_OK;
}
*/
krb5_error_code
krb5_fcc_generate_new (id)
- krb5_ccache id;
-
+ krb5_ccache *id;
{
+ krb5_ccache lid;
int ret;
char scratch[100]; /* XXX Is this large enough */
/* Allocate memory */
- id = (krb5_ccache) malloc(sizeof(struct _krb5_ccache));
- if (id == NULL)
+ lid = (krb5_ccache) malloc(sizeof(struct _krb5_ccache));
+ if (lid == NULL)
return KRB5_NOMEM;
+ lid->ops = &krb5_fcc_ops;
+
sprintf(scratch, "%sXXXXXX", TKT_ROOT);
mktemp(scratch);
- id->data = (krb5_fcc_data *) malloc(sizeof(krb5_fcc_data));
- if (((krb5_fcc_data *) id->data) == NULL) {
- free(id);
+ lid->data = (krb5_fcc_data *) malloc(sizeof(krb5_fcc_data));
+ if (((krb5_fcc_data *) lid->data) == NULL) {
+ free(lid);
return KRB5_NOMEM;
}
- ((krb5_fcc_data *) id->data)->filename = (char *)
+ ((krb5_fcc_data *) lid->data)->filename = (char *)
malloc(strlen(scratch) + 1);
- if (((krb5_fcc_data *) id->data)->filename == NULL) {
- free(((krb5_fcc_data *) id->data));
- free(id);
+ if (((krb5_fcc_data *) lid->data)->filename == NULL) {
+ free(((krb5_fcc_data *) lid->data));
+ free(lid);
return KRB5_NOMEM;
}
/* Set up the filename */
- strcpy(((krb5_fcc_data *) id->data)->filename, scratch);
-
- /* Copy the virtual operation pointers into id */
- bcopy((char *) &krb5_fcc_ops, id->ops, sizeof(krb5_cc_ops));
+ strcpy(((krb5_fcc_data *) lid->data)->filename, scratch);
/* Make sure the file name is reserved */
- ret = open(((krb5_fcc_data *) id->data)->filename, O_CREAT| O_EXCL,0600);
+ ret = open(((krb5_fcc_data *) lid->data)->filename, O_CREAT| O_EXCL,0600);
if (ret == -1)
return ret;
else {
close(ret);
+ *id = lid;
return KRB5_OK;
}
}
krb5_principal *princ;
{
krb5_error_code kret;
-#ifdef OPENCLOSE
- ((krb5_fcc_data *) id->data)->fd = open(((krb5_fcc_data *) id->data)->
- filename, O_RDONLY, 0);
- if (((krb5_fcc_data *) id->data)->fd < 0)
- return errno;
-#else
- lseek(((krb5_fcc_data *) id->data)->fd, 0, L_SET);
-#endif
+
+ if (OPENCLOSE(id)) {
+ ((krb5_fcc_data *) id->data)->fd = open(((krb5_fcc_data *) id->data)
+ ->filename, O_RDONLY, 0);
+ if (((krb5_fcc_data *) id->data)->fd < 0)
+ return errno;
+ }
+ else
+ lseek(((krb5_fcc_data *) id->data)->fd, 0, L_SET);
kret = krb5_fcc_read_principal(id, princ);
-#ifdef OPENCLOSE
- close(((krb5_fcc_data *) id->data)->fd);
-#endif
+ if (OPENCLOSE(id))
+ close(((krb5_fcc_data *) id->data)->fd);
return kret;
}
{
int ret;
- ret = open(((krb5_fcc_data *) id->data)->filename, O_CREAT | O_TRUNC | O_RDWR, 0);
+ ret = open(((krb5_fcc_data *) id->data)->filename, O_CREAT | O_TRUNC |
+ O_RDWR, 0);
if (ret < 0)
return errno;
((krb5_fcc_data *) id->data)->fd = ret;
krb5_fcc_store_principal(id, princ);
-#ifdef OPENCLOSE
- close(((krb5_fcc_data *) id->data)->fd);
-#endif
+ if (OPENCLOSE(id))
+ close(((krb5_fcc_data *) id->data)->fd);
return KRB5_OK;
}
krb5_error_code kret;
krb5_fcc_cursor *fcursor;
-#ifdef OPENCLOSE
- ret = open(((krb5_fcc_data *) id->data)->filename, O_RDONLY, 0);
- if (ret < 0)
- return errno;
- ((krb5_fcc_data *) id->data)->fd = ret;
-#endif
+ 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;
+ }
- fcursor = (krb5_fcc_cursor *) cursor;
+ fcursor = (krb5_fcc_cursor *) *cursor;
ret = lseek(((krb5_fcc_data *) id->data)->fd, fcursor->pos, L_SET);
if (ret < 0)
#include <krb5/copyright.h>
#include "fcc.h"
-/* XXX Deal with kret return values */
#define CHECK(ret) if (ret != KRB5_OK) return ret;
-/* XXX Doesn't deal if < sizeof(o) bytes are written XXX */
-#define krb5_fcc_read(i,b,l) (read(((krb5_fcc_data *)i->data)->fd,b,l) == -1 \
- ? errno : KRB5_OK)
+/*
+ * Effects:
+ * Reads len bytes from the cache id, storing them in buf.
+ *
+ * Errors:
+ * KRB5_EOF - there were not len bytes available
+ * system errors (read)
+ */
+krb5_error_code
+krb5_fcc_read(id, buf, len)
+ krb5_ccache id;
+ krb5_pointer buf;
+ int len;
+{
+ int ret;
+
+ ret = read(((krb5_fcc_data *) id->data)->fd, (char *) buf, len);
+ if (ret == -1)
+ return errno;
+ else if (ret != len)
+ return KRB5_EOF;
+ else
+ return KRB5_OK;
+}
/*
* FOR ALL OF THE FOLLOWING FUNCTIONS:
krb5_keyblock *keyblock;
{
krb5_error_code kret;
- char *temp; /* HACK! */
int ret;
- /*
- * XXX The third field should be a char *, not a char[1].
- * Alternatively, I am *VERY* confused.
- */
-
kret = krb5_fcc_read_keytype(id, &keyblock->keytype);
CHECK(kret);
kret = krb5_fcc_read_int(id, &keyblock->length);
CHECK(kret);
-
- temp = (char *) malloc(keyblock->length*sizeof(krb5_octet));
- if (temp == NULL)
- return KRB5_NOMEM;
-
- ret = read(((krb5_fcc_data *) id->data)->fd, temp,
- (keyblock->length)*sizeof(krb5_octet));
-
- /*
- keyblock->contents = (char *) malloc(keyblock->length*sizeof(krb5_octet));
+ keyblock->contents = (unsigned char *) malloc(keyblock->length*
+ sizeof(krb5_octet));
if (keyblock->contents == NULL)
return KRB5_NOMEM;
ret = read(((krb5_fcc_data *) id->data)->fd, keyblock->contents,
(keyblock->length)*sizeof(krb5_octet));
- */
if (ret < 0)
return errno;
krb5_error_code kret;
int ret;
- kret = krb5_fcc_read_int(id, &data->length);
+ kret = krb5_fcc_read_int32(id, &data->length);
CHECK(kret);
data->data = (char *) malloc(data->length);
krb5_ccache id;
krb5_int32 *i;
{
- return krb5_fcc_read(id, i, sizeof(krb5_int32));
+ return krb5_fcc_read(id, (krb5_pointer) i, sizeof(krb5_int32));
}
krb5_error_code
krb5_ccache id;
krb5_keytype *k;
{
- return krb5_fcc_read(id, k, sizeof(krb5_keytype));
+ return krb5_fcc_read(id, (krb5_pointer) k, sizeof(krb5_keytype));
}
krb5_error_code
krb5_ccache id;
int *i;
{
- return krb5_fcc_read(id, i, sizeof(int));
+ return krb5_fcc_read(id, (krb5_pointer) i, sizeof(int));
}
krb5_error_code
krb5_ccache id;
krb5_boolean *b;
{
- return krb5_fcc_read(id, b, sizeof(krb5_boolean));
+ return krb5_fcc_read(id, (krb5_pointer) b, sizeof(krb5_boolean));
}
krb5_error_code
krb5_ccache id;
krb5_ticket_times *t;
{
- return krb5_fcc_read(id, t, sizeof(krb5_ticket_times));
+ return krb5_fcc_read(id, (krb5_pointer) t, sizeof(krb5_ticket_times));
}
krb5_error_code
krb5_ccache id;
krb5_flags *f;
{
- return krb5_fcc_read(id, f, sizeof(krb5_flags));
+ return krb5_fcc_read(id, (krb5_pointer) f, sizeof(krb5_flags));
}
(! set(KRB5_TC_MATCH_TIMES) ||
times_match(mcreds->times, creds->times)))
{
- krb5_fcc_end_seq_get(id, cursor);
+ krb5_fcc_end_seq_get(id, &cursor);
return KRB5_OK;
}
return KRB5_NOMEM;
/* Make sure we start reading right after the primary principal */
-#ifdef OPENCLOSE
- ret = open(((krb5_fcc_data *) id->data)->filename, O_RDONLY, 0);
- if (ret < 0)
- return errno;
- ((krb5_fcc_data *) id->data)->fd = ret;
-#else
- lseek(((krb5_fcc_data *) id->data)->fd, 0, L_SET);
-#endif
+ 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;
+ }
+ else
+ lseek(((krb5_fcc_data *) id->data)->fd, 0, L_SET);
krb5_fcc_skip_principal(id);
fcursor->pos = tell(((krb5_fcc_data *) id->data)->fd);
- *cursor = (krb5_cc_cursor *) fcursor;
+ *cursor = (krb5_cc_cursor) fcursor;
-#ifdef OPENCLOSE
- close(((krb5_fcc_data *) id->data)->fd);
-#endif
+ if (OPENCLOSE(id))
+ close(((krb5_fcc_data *) id->data)->fd);
return KRB5_OK;
}
krb5_error_code ret;
/* Make sure we are writing to the end of the file */
-#ifdef OPENCLOSE
- ((krb5_fcc_data *) id->data)->fd = open(((krb5_fcc_data *) id->data)->
- filename, O_RDWR|O_APPEND, 0);
- if (((krb5_fcc_data *) id->data)->fd < 0)
- return errno;
-#endif
+ if (OPENCLOSE(id)) {
+ ((krb5_fcc_data *) id->data)->fd = open(((krb5_fcc_data *) id->data)
+ ->filename,
+ O_RDWR | O_APPEND, 0);
+ if (((krb5_fcc_data *) id->data)->fd < 0)
+ return errno;
+ }
ret = lseek(((krb5_fcc_data *) id->data)->fd, 0, L_XTND);
if (ret < 0)
TCHECK(ret);
ret = krb5_fcc_store_bool(id, &creds->is_skey);
TCHECK(ret);
+ ret = krb5_fcc_store_flags(id, &creds->ticket_flags);
+ TCHECK(ret);
ret = krb5_fcc_store_data(id, &creds->ticket);
TCHECK(ret);
ret = krb5_fcc_store_data(id, &creds->second_ticket);
lose:
-#ifdef OPENCLOSE
- close(((krb5_fcc_data *) id->data)->fd);
-#endif
+ if (OPENCLOSE(id))
+ close(((krb5_fcc_data *) id->data)->fd);
return ret;
#undef TCHECK
{
1,
1,
- "1"
+ (unsigned char *) "1"
},
{
1111,
test_creds.server[1] = &server2;
test_creds.server[2] = NULL;
}
+
+#define CHECK(kret,msg) \
+ if (kret != KRB5_OK) {\
+ printf("%s returned %d\n", msg, kret);\
+ };
+
+void fcc_test()
+{
+ krb5_ccache id;
+ krb5_creds creds;
+ krb5_error_code kret;
+ krb5_cc_cursor cursor;
+
+ init_test_cred();
+
+ kret = krb5_fcc_resolve(&id, "/tmp/tkt_test");
+ CHECK(kret, "resolve");
+ kret = krb5_fcc_initialize(id, test_creds.client);
+ CHECK(kret, "initialize");
+ kret = krb5_fcc_store(id, &test_creds);
+ CHECK(kret, "store");
+
+ kret = krb5_fcc_start_seq_get(id, &cursor);
+ CHECK(kret, "start_seq_get");
+ kret = 0;
+ while (kret != KRB5_EOF) {
+ printf("Calling next_cred\n");
+ kret = krb5_fcc_next_cred(id, &cursor, &creds);
+ CHECK(kret, "next_cred");
+ }
+ kret = krb5_fcc_end_seq_get(id, &cursor);
+ CHECK(kret, "end_seq_get");
+
+ kret = krb5_fcc_destroy(id);
+ CHECK(kret, "destroy");
+ kret = krb5_fcc_close(id);
+ CHECK(kret, "close");
+}
+
krb5_ccache id;
krb5_int32 *i;
{
- return krb5_fcc_write(id, i, sizeof(krb5_int32));
+ return krb5_fcc_write(id, (char *) i, sizeof(krb5_int32));
}
krb5_error_code
krb5_ccache id;
krb5_keytype *k;
{
- return krb5_fcc_write(id, k, sizeof(krb5_keytype));
+ return krb5_fcc_write(id, (char *) k, sizeof(krb5_keytype));
}
krb5_error_code
krb5_ccache id;
int *i;
{
- return krb5_fcc_write(id, i, sizeof(int));
+ return krb5_fcc_write(id, (char *) i, sizeof(int));
}
krb5_error_code
krb5_ccache id;
krb5_boolean *b;
{
- return krb5_fcc_write(id, b, sizeof(krb5_boolean));
+ return krb5_fcc_write(id, (char *) b, sizeof(krb5_boolean));
}
krb5_error_code
krb5_ccache id;
krb5_ticket_times *t;
{
- return krb5_fcc_write(id, t, sizeof(krb5_ticket_times));
+ return krb5_fcc_write(id, (char *) t, sizeof(krb5_ticket_times));
}
-
-
+krb5_error_code
+krb5_fcc_store_flags(id, f)
+ krb5_ccache id;
+ krb5_flags *f;
+{
+ return krb5_fcc_write(id, (char *) f, sizeof(krb5_flags));
+}