#define __KRB5_FILE_CCACHE__
#include <krb5/krb5.h>
+#include "fcc-proto.h"
#include "fcc-os.h"
/* XXX Until I find out the right #define for this.. XXX */
* This file contains the source code for krb5_fcc_close.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_resolve_c[] = "$Id$";
-#endif /* lint */
+#endif /* !lint && !SABER */
#include <krb5/copyright.h>
* This file contains the source code for krb5_fcc_default_name.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_defnam_c[] = "$Id$";
-#endif lint
+#endif /* !lint && !SABER */
#include "fcc.h"
* This file contains the source code for krb5_fcc_destroy.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_destry_c[] = "$Id$";
-#endif /* lint */
+#endif /* !lint && !SABER */
#include <krb5/copyright.h>
* This file contains the source code for krb5_fcc_end_seq_get.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_eseq_c[] = "$Id$";
-#endif /* lint */
+#endif /* !lint && !SABER */
#include <krb5/copyright.h>
#include "fcc.h"
* This file contains the source code for krb5_fcc_generate_new.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_resolve_c[] = "$Id$";
-#endif lint
+#endif /* !lint && !SABER */
#include "fcc.h"
sprintf(scratch, "%sXXXXXX", TKT_ROOT);
mktemp(scratch);
- ((krb5_fcc_data *) id->data) = (krb5_fcc_data *)
- malloc(sizeof(krb5_fcc_data));
+ id->data = (krb5_fcc_data *) malloc(sizeof(krb5_fcc_data));
if (((krb5_fcc_data *) id->data) == NULL) {
free(id);
return KRB5_NOMEM;
strcpy(((krb5_fcc_data *) id->data)->filename, scratch);
/* Copy the virtual operation pointers into id */
- bcopy((char *) &krb5_fcc_ops, id->ops, sizeof(struct _krb5_ccache));
+ bcopy((char *) &krb5_fcc_ops, id->ops, sizeof(krb5_cc_ops));
/* Make sure the file name is reserved */
- ret = open(((krb5_fcc_data *) id->data)->filename, O_CREAT | O_EXCL, 0);
- if (ret == -1 && errno != EEXIST)
+ ret = open(((krb5_fcc_data *) id->data)->filename, O_CREAT| O_EXCL,0600);
+ if (ret == -1)
return ret;
else {
close(ret);
* This file contains the source code for krb5_fcc_get_name.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_resolve_c[] = "$Id$";
-#endif lint
+#endif /* !lint && !SABER */
#include <krb5/copyright.h>
* This file contains the source code for krb5_fcc_get_principal.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_gprinc_c[] = "$Id$";
-#endif lint
+#endif /* !lint && !SABER */
#include <krb5/copyright.h>
#include "fcc.h"
* This file contains the source code for krb5_fcc_initialize.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_resolve_c[] = "$Id$";
-#endif /* lint */
+#endif /* !lint && !SABER */
#include <krb5/copyright.h>
if (ret == -1)
return ret;
- krb5_fcc_write_principal(id, princ);
+ krb5_fcc_store_principal(id, princ);
#ifdef OPENCLOSE
close(((krb5_fcc_data *) id->data)->fd);
* This file contains the source code for krb5_fcc_next_cred.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_nseq_c[] = "$Id$";
-#endif lint
+#endif /* !lint && !SABER */
#include <krb5/copyright.h>
* Effects:
* Fills in creds with the "next" credentals structure from the cache
* id. The actual order the creds are returned in is arbitrary.
- * creds is set to allocated storage which must be freed by the caller
- * via a call to krb5_free_credentials.
+ * Space is allocated for the variable length fields in the
+ * credentials structure, so the object returned must be passed to
+ * krb5_destroy_credential.
*
* The cursor is updated for the next call to krb5_fcc_next_cred.
*
* system errors
*/
krb5_error_code
-krb5_fcc_next_cred(id, creds, cursor)
+krb5_fcc_next_cred(id, cursor, creds)
krb5_ccache id;
- krb5_creds *creds;
krb5_cc_cursor *cursor;
+ krb5_creds *creds;
{
+#define TCHECK(ret) if (ret != KRB5_OK) goto lose;
int ret;
krb5_error_code kret;
krb5_fcc_cursor *fcursor;
if (ret < 0)
return errno;
- creds = (krb5_creds *) malloc(sizeof(krb5_creds));
- if (creds == NULL)
- return KRB5_NOMEM;
-
- kret = krb5_fcc_read_principal(&creds->client);
- kret = krb5_fcc_read_principal(&creds->server);
- kret = krb5_fcc_read_keyblock(&creds->keyblock);
- kret = krb5_fcc_read_times(&creds->times);
- kret = krb5_fcc_read_bool(&creds->is_skey);
- kret = krb5_fcc_read_flags(&creds->ticket_flags);
- kret = krb5_fcc_read_data(&creds->ticket);
- kret = krb5_fcc_read_data(&creds->second_ticket);
-
+ kret = krb5_fcc_read_principal(id, &creds->client);
+ TCHECK(kret);
+ kret = krb5_fcc_read_principal(id, &creds->server);
+ TCHECK(kret);
+ kret = krb5_fcc_read_keyblock(id, &creds->keyblock);
+ TCHECK(kret);
+ kret = krb5_fcc_read_times(id, &creds->times);
+ TCHECK(kret);
+ kret = krb5_fcc_read_bool(id, &creds->is_skey);
+ TCHECK(kret);
+ kret = krb5_fcc_read_flags(id, &creds->ticket_flags);
+ TCHECK(kret);
+ kret = krb5_fcc_read_data(id, &creds->ticket);
+ TCHECK(kret);
+ kret = krb5_fcc_read_data(id, &creds->second_ticket);
+ TCHECK(kret);
+
fcursor->pos = tell(((krb5_fcc_data *) id->data)->fd);
cursor = (krb5_cc_cursor *) fcursor;
#ifdef OPENCLOSE
close(((krb5_fcc_data *) id->data)->fd);
#endif
-
- return KRB5_OK;
+lose:
+
+ return kret;
}
-/*
- * **************************************
- * Major problem:
- * This code is really confused (meaning that I was confused when I
- * wrote it). The declarations are set up such that the functions
- * below can copy data into a structure it is given a pointer to, but
- * they are written to allocate memory and return a pointer to that.
- * Of course, the pointer is never returned because I have one too few
- * levels of directory, so essentially nothing will work.
- *
- * Have fun, Bill.
- * **************************************
- */
-
-
/*
* $Source$
* $Author$
* credentials cache. These are not library-exported functions.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_read_c[] = "$Id$";
-#endif lint
+#endif /* !lint && !SABER */
#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)
* FOR ALL OF THE FOLLOWING FUNCTIONS:
*
* Requires:
- * ((krb5_fcc_data *) id->data)->fd is open and at the right position
- * in the file.
+ * id is open and set to read at the appropriate place in the file
*
* Effects:
- * Allocates memory for and decodes the appropriate type from the
- * cache id. The memory must be freed by the caller.
+ * Fills in the second argument with data of the appropriate type from
+ * the file. In some cases, the functions have to allocate space for
+ * variable length fields; therefore, krb5_destroy_<type> must be
+ * called for each filled in structure.
*
* Errors:
- * system errors
+ * system errors (read errors)
* KRB5_NOMEM
*/
krb5_error_code
krb5_fcc_read_principal(id, princ)
krb5_ccache id;
- krb5_principal princ;
+ krb5_principal *princ;
{
krb5_error_code kret;
krb5_int32 length;
int i;
/* Read the number of components */
- krb5_fcc_read_int32(id, &length);
-
- /* Get memory for length components */
- princ = (krb5_principal) malloc(sizeof(krb5_data *)*length);
- if (princ == NULL)
+ kret = krb5_fcc_read_int32(id, &length);
+ CHECK(kret);
+
+ /*
+ * The # of levels of indirection is confusing. A krb5_principal
+ * is an array of pointers to krb5_data. princ is a pointer to
+ * an array of pointers to krb5_data. (*princ)[i] a pointer to
+ * krb5_data.
+ */
+
+ /* Make *princ able to hold length pointers to krb5_data structs */
+ *princ = (krb5_principal) malloc(sizeof(krb5_data *)*length);
+ if (*princ == NULL)
return KRB5_NOMEM;
- /* Read length components */
+ /* XXX Memory leak XXX */
for (i=0; i < length; i++) {
- kret = krb5_fcc_read_data(id, princ[i]);
- if (kret != KRB5_OK) {
- free(princ);
- return kret;
- }
+ (*princ)[i] = (krb5_data *) malloc(sizeof(krb5_data));
+ if ((*princ)[i] == NULL)
+ return KRB5_NOMEM;
+
+ kret = krb5_fcc_read_data(id, (*princ)[i]);
+ CHECK(kret);
}
return KRB5_OK;
krb5_keyblock *keyblock;
{
krb5_error_code kret;
+ char *temp; /* HACK! */
int ret;
- keyblock = (krb5_keyblock *) malloc(sizeof(krb5_keyblock));
- if (keyblock == NULL)
- return KRB5_NOMEM;
-
+ /*
+ * 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));
+ if (keyblock->contents == NULL)
+ return KRB5_NOMEM;
+
ret = read(((krb5_fcc_data *) id->data)->fd, keyblock->contents,
(keyblock->length)*sizeof(krb5_octet));
+ */
- return KRB5_OK;
+ if (ret < 0)
+ return errno;
+ else
+ return KRB5_OK;
}
krb5_error_code
krb5_error_code kret;
int ret;
- data = (krb5_data *) malloc(sizeof(krb5_data));
- if (data == NULL)
- return KRB5_NOMEM;
-
- kret = krb5_fcc_read_int32(id, data->length);
+ kret = krb5_fcc_read_int(id, &data->length);
+ CHECK(kret);
data->data = (char *) malloc(data->length);
- if (data->data == NULL) {
- free(data);
+ if (data->data == NULL)
return KRB5_NOMEM;
- }
ret = read(((krb5_fcc_data *) id->data)->fd, data->data, data->length);
if (ret == -1)
return krb5_fcc_read(id, t, sizeof(krb5_ticket_times));
}
+krb5_error_code
+krb5_fcc_read_flags(id, f)
+ krb5_ccache id;
+ krb5_flags *f;
+{
+ return krb5_fcc_read(id, f, sizeof(krb5_flags));
+}
* This file contains the source code for krb5_fcc_resolve.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_resolve_c[] = "$Id$";
-#endif lint
+#endif /* !lint && !SABER */
#include <krb5/copyright.h>
*/
krb5_error_code
krb5_fcc_resolve (id, residual)
- krb5_ccache id;
+ krb5_ccache *id;
char *residual;
{
+ krb5_ccache lid;
int ret;
- 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;
- ((krb5_fcc_data *) id->data) = (krb5_fcc_data *)
- malloc(sizeof(krb5_fcc_data));
- if (((krb5_fcc_data *) id->data) == NULL) {
- free(id);
+ lid->ops = (krb5_cc_ops *) malloc(sizeof(krb5_cc_ops));
+ if (lid->ops == NULL) {
+ free(lid);
return KRB5_NOMEM;
}
- ((krb5_fcc_data *) id->data)->filename = (char *)
+ lid->data = (krb5_fcc_data *) malloc(sizeof(krb5_fcc_data));
+ if (((krb5_fcc_data *) lid->data) == NULL) {
+ free(lid->ops);
+ free(lid);
+ return KRB5_NOMEM;
+ }
+
+ ((krb5_fcc_data *) lid->data)->filename = (char *)
malloc(strlen(residual) + 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->ops);
+ free(lid);
return KRB5_NOMEM;
}
- /* Copy the virtual operation pointers into id */
- bcopy((char *) &krb5_fcc_ops, id->ops, sizeof(struct _krb5_ccache));
+ /* Copy the virtual operation pointers into lid */
+ bcopy((char *) &krb5_fcc_ops, lid->ops, sizeof(krb5_cc_ops));
/* Set up the filename */
- strcpy(((krb5_fcc_data *) id->data)->filename, residual);
+ strcpy(((krb5_fcc_data *) lid->data)->filename, residual);
/* Make sure the file name is reserved */
- ret = open(((krb5_fcc_data *) id->data)->filename, O_CREAT | O_EXCL, 0);
- if (ret == -1 && errno != EEXIST)
- return ret;
+ ret = open(((krb5_fcc_data *) lid->data)->filename, O_CREAT|O_EXCL,0600);
+ if (ret == -1)
+ return errno;
else {
close(ret);
+ *id = lid;
return KRB5_OK;
}
}
* This file contains the source code for krb5_fcc_retrieve.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_retrieve_c[] = "$Id$";
-#endif /* lint */
+#endif /* !lint && !SABER */
#include <krb5/copyright.h>
/* This function could be considerably faster if it kept indexing */
/* information.. sounds like a "next version" idea to me. :-) */
- krb5_cc_cursor *cursor;
+ krb5_cc_cursor cursor;
krb5_error_code kret;
- kret = krb5_fcc_start_seq_get(id, cursor);
+ kret = krb5_fcc_start_seq_get(id, &cursor);
if (kret != KRB5_OK)
return kret;
- while ((kret = krb5_fcc_next_cred(id, creds, cursor)) == KRB5_OK) {
- if (standard_fields_match(mcreds, creds)
+ while ((kret = krb5_fcc_next_cred(id, &cursor, creds)) == KRB5_OK) {
+ if (1 /* XXX standard_fields_match(mcreds, creds) */
&&
(! set(KRB5_TC_MATCH_IS_SKEY) ||
mcreds->is_skey == creds->is_skey)
}
/* This one doesn't match */
- krb5_free_credentials(creds);
+ /* XXX krb5_free_credentials(creds); */
}
/* If we get here, a match wasn't found */
- krb5_fcc_end_seq_get(id, cursor);
+ krb5_fcc_end_seq_get(id, &cursor);
return KRB5_NOTFOUND;
}
* This file contains the source code for krb5_fcc_start_seq_get.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_sseq_c[] = "$Id$";
-#endif lint
+#endif /* !lint && !SABER */
#include <krb5/copyright.h>
lseek(((krb5_fcc_data *) id->data)->fd, 0, L_SET);
#endif
- krb5_fcc_skip_pprincipal(id);
+ 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);
* This file contains the source code for krb5_fcc_store.
*/
-#ifndef lint
+#if !defined(lint) && !defined(SABER)
static char fcc_store_c[] = "$Id$";
-#endif /* lint */
+#endif /* !lint && !SABER */
#include <krb5/copyright.h>
#include "fcc.h"
-/* XXX Doesn't deal if < sizeof(o) bytes are written XXX */
-#define krb5_fcc_write(i,b,l) (write(((krb5_fcc_data *)i->data)->fd,b,l) == -1\
- ? errno : KRB5_OK)
-
-#define krb5_fcc_store_int32(id,i) krb5_fcc_write(id, i, sizeof(krb5_int32))
-#define krb5_fcc_store_keytype(id,k) krb5_fcc_write(id,k,sizeof(krb5_keytype))
-#define krb5_fcc_store_int(id,i) krb5_fcc_write(id,i,sizeof(int))
-#define krb5_fcc_store_bool(id,b) krb5_fcc_write(id,b,sizeof(krb5_boolean))
-#define krb5_fcc_store_times(id,t) krb5_fcc_write(id,t,sizeof(krb5_ticket_times))
-
#define CHECK(ret) if (ret != KRB5_OK) return 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_APPEND, 0);
+ ((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;
-#else
- ret = lseek(((krb5_fcc_data *) id->data)->fd, L_XTND, 0);
+#endif
+
+ ret = lseek(((krb5_fcc_data *) id->data)->fd, 0, L_XTND);
if (ret < 0)
return errno;
-#endif
ret = krb5_fcc_store_principal(id, creds->client);
TCHECK(ret);
return ret;
#undef TCHECK
}
-
-/*
- * FOR ALL OF THE FOLLOWING FUNCTIONS:
- *
- * Requires:
- * ((krb5_fcc_data *) id->data)->fd is open and at the right position.
- *
- * Effects:
- * Stores an encoded version of the second argument in the
- * cache file.
- *
- * Errors:
- * system errors
- */
-
-static krb5_error_code
-krb5_fcc_store_principal(id, princ)
- krb5_ccache id;
- krb5_principal princ;
-{
- krb5_error_code ret;
- krb5_principal temp;
- krb5_int32 i, length = 0;
-
- /* Count the number of components */
- temp = princ;
- while (temp++)
- length += 1;
-
- ret = krb5_fcc_store_int32(id, &length);
- CHECK(ret);
- for (i=0; i < length; i++) {
- ret = krb5_store_data(id, princ[i]);
- CHECK(ret);
- }
-
- return KRB5_OK;
-}
-
-static krb5_error_code
-krb5_store_keyblock(id, keyblock)
- krb5_ccache id;
- krb5_keyblock *keyblock;
-{
- krb5_error_code ret;
-
- ret = krb5_fcc_store_keytype(id, &keyblock->keytype);
- CHECK(ret);
- ret = krb5_fcc_store_int(id, &keyblock->length);
- CHECK(ret);
- ret = write(((krb5_fcc_data *) id->data)->fd, keyblock->contents,
- (keyblock->length)*sizeof(krb5_octet));
- CHECK(ret);
-
- return KRB5_OK;
-}
-
-
-static krb5_error_code
-krb5_fcc_store_data(id, data)
- krb5_ccache id;
- krb5_data *data;
-{
- krb5_error_code ret;
-
- ret = krb5_fcc_store_int32(id, data->length);
- CHECK(ret);
- ret = write(((krb5_fcc_data *) id->data)->fd, data->data, data->length);
- if (ret == -1)
- return errno;
-
- return KRB5_OK;
-}
-
-
#include "fcc.h"
-krb5_data client[] = {
- {
+krb5_data client1 = {
#define DATA "client1-comp1"
- sizeof(DATA),
- DATA,
+ sizeof(DATA),
+ DATA,
#undef DATA
- },
- {
+};
+
+krb5_data client2 = {
#define DATA "client1-comp2"
- sizeof(DATA),
- DATA,
+ sizeof(DATA),
+ DATA,
#undef DATA
- },
};
-krb5_data server[] = {
- {
+krb5_data server1 = {
#define DATA "server1-comp1"
- sizeof(DATA),
- DATA,
+ sizeof(DATA),
+ DATA,
#undef DATA
- },
- {
+};
+
+krb5_data server2 = {
#define DATA "server1-comp2"
- sizeof(DATA),
- DATA,
+ sizeof(DATA),
+ DATA,
#undef DATA
- },
};
krb5_creds test_creds = {
NULL,
{
1,
- 5,
+ 1,
"1"
},
{
void init_test_cred()
{
- test_creds.client = &client;
- test_creds.server = &server;
+ test_creds.client = (krb5_principal) malloc(sizeof(krb5_data *)*3);
+ test_creds.client[0] = &client1;
+ test_creds.client[1] = &client2;
+ test_creds.client[2] = NULL;
+
+ test_creds.server = (krb5_principal) malloc(sizeof(krb5_data *)*3);
+ test_creds.server[0] = &server1;
+ test_creds.server[1] = &server2;
+ test_creds.server[2] = NULL;
}