#define __KRB5_FILE_CCACHE__
#include <krb5/krb5.h>
+#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_FCC_MAXLEN 100
#ifndef TKT_ROOT
#define TKT_ROOT "/tmp/tkt"
* system errors
* permission errors
*/
-krb5_error
+krb5_error_code
krb5_fcc_close(id)
krb5_ccache id;
{
#ifdef OPENCLOSE
#else
- close(id->data->fd);
+ close(((krb5_fcc_data *) id->data)->fd);
#endif
- ret = unlink(id->data->filename);
+ ret = unlink(((krb5_fcc_data *) id->data)->filename);
if (ret < 0)
return errno;
- free(id->data->filename);
- free(id->data);
+ free(((krb5_fcc_data *) id->data)->filename);
+ free(((krb5_fcc_data *) id->data));
free(id);
return KRB5_OK;
char *
krb5_fcc_default_name ()
{
- char *krb5ccache;
+ char *krb5ccache, *getenv();
int len;
/* Is the environment variable defined? */
#ifndef lint
static char fcc_destry_c[] = "$Id$";
-#endif lint
+#endif /* lint */
#include <krb5/copyright.h>
+#include "fcc.h"
+
/*
* Effects:
* Destroys the contents of id.
* Errors:
* system errors
*/
-krb5_error
-krb5_fcc_destroy(id)
+krb5_error_code krb5_fcc_destroy(id)
krb5_ccache id;
{
struct stat buf;
int ret;
#ifdef OPENCLOSE
- id->data->fd = open(id->data->filename, O_RDWR, 0);
- if (id->data->fd < 0)
+ ((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(id->data->fd, 0, L_SET);
+ lseek(((krb5_fcc_data *) id->data)->fd, 0, L_SET);
#endif
- ret = fstat(id->data->fd, &buf);
+ ret = fstat(((krb5_fcc_data *) id->data)->fd, &buf);
if (ret < 0)
return errno;
bzero(zeros, BUFSIZ);
for (i=0; i < size / BUFSIZ; i++)
- if (write(id->data->fd, zeros, BUFSIZ) < 0)
+ if (write(((krb5_fcc_data *) id->data)->fd, zeros, BUFSIZ) < 0)
return errno;
- if (write(id->data->fd, zeros, size % BUFSIZ) < 0)
+ if (write(((krb5_fcc_data *) id->data)->fd, zeros, size % BUFSIZ) < 0)
return errno;
#ifdef OPENCLOSE
- close(id->data->fd);
+ close(((krb5_fcc_data *) id->data)->fd);
#endif
}
#ifndef lint
static char fcc_eseq_c[] = "$Id$";
-#endif lint
+#endif /* lint */
#include <krb5/copyright.h>
#include "fcc.h"
* Finishes sequential processing of the file credentials ccache id,
* and invalidates the cursor (it must never be used after this call).
*/
-krb5_error
+/* ARGSUSED */
+krb5_error_code
krb5_fcc_end_seq_get(id, cursor)
krb5_ccache id;
krb5_cc_cursor *cursor;
{
#ifdef OPENCLOSE
#else
- close(id->data->fd);
+ close(((krb5_fcc_data *) id->data)->fd);
#endif
- free((krb5_fcc_cursor) cursor);
+ free((krb5_fcc_cursor *) cursor);
return KRB5_OK;
}
#include <krb5/copyright.h>
+extern krb5_cc_ops krb5_fcc_ops;
+
/*
* Effects:
* Creates a new file cred cache whose name is guaranteed to be
* KRB5_NOMEM - there was insufficient memory to allocate the
* krb5_ccache. id is undefined.
*/
-krb5_err
+krb5_error_code
krb5_fcc_generate_new (id)
krb5_ccache id;
+
{
+ int ret;
char scratch[100]; /* XXX Is this large enough */
/* Allocate memory */
- id = (krb_ccache) malloc(sizeof(struct _krb5_ccache));
+ id = (krb5_ccache) malloc(sizeof(struct _krb5_ccache));
if (id == NULL)
return KRB5_NOMEM;
sprintf(scratch, "%sXXXXXX", TKT_ROOT);
mktemp(scratch);
- id->data = malloc(sizeof(krb5_fcc_data));
- if (id->data == NULL) {
+ ((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;
}
- id->data->filename = malloc(strlen(scratch) + 1);
- if (id->data->filename == NULL) {
- free(id->data);
+ ((krb5_fcc_data *) id->data)->filename = (char *)
+ malloc(strlen(scratch) + 1);
+ if (((krb5_fcc_data *) id->data)->filename == NULL) {
+ free(((krb5_fcc_data *) id->data));
free(id);
return KRB5_NOMEM;
}
/* Set up the filename */
- strcpy(id->data->filename, scratch);
+ 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));
/* Make sure the file name is reserved */
- ret = open(id->data->filename, O_CREAT | O_EXCL, 0);
+ ret = open(((krb5_fcc_data *) id->data)->filename, O_CREAT | O_EXCL, 0);
if (ret == -1 && errno != EEXIST)
return ret;
else {
krb5_fcc_get_name (id)
krb5_ccache id;
{
- return (char *) id->data->filename;
+ return (char *) ((krb5_fcc_data *) id->data)->filename;
}
#endif lint
#include <krb5/copyright.h>
+#include "fcc.h"
/*
* Modifies:
* system errors
* KRB5_NOMEM
*/
-krb5_error
+krb5_error_code
krb5_fcc_get_principal(id, princ)
krb5_ccache id;
krb5_principal *princ;
{
#ifdef OPENCLOSE
- id->data->fd = open(id->data->filename, O_RDONLY, 0);
- if (id->data->fd < 0)
+ ((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(id->data->fd, 0, L_SET);
+ lseek(((krb5_fcc_data *) id->data)->fd, 0, L_SET);
#endif
return (krb5_fcc_read_principal(princ));
* system errors
* permission errors
*/
-krb5_error
+krb5_error_code
krb5_fcc_initialize(id, princ)
krb5_ccache id;
krb5_principal princ;
{
int ret;
- ret = open(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;
- id->data->fd = ret;
+ ((krb5_fcc_data *) id->data)->fd = ret;
- ret = fchmod(id->data->fd, S_IREAD | S_IWRITE);
+ ret = fchmod(((krb5_fcc_data *) id->data)->fd, S_IREAD | S_IWRITE);
if (ret == -1)
return ret;
krb5_fcc_write_principal(id, princ);
#ifdef OPENCLOSE
- close(id->data->fd);
+ close(((krb5_fcc_data *) id->data)->fd);
#endif
return KRB5_OK;
#include "fcc.h"
+/* XXX Deal with kret values */
+
/*
* Requires:
* cursor is a krb5_cc_cursor originally obtained from
* Errors:
* system errors
*/
-krb5_error
+krb5_error_code
krb5_fcc_next_cred(id, creds, cursor)
krb5_ccache id;
krb5_creds *creds;
krb5_cc_cursor *cursor;
{
int ret;
- krb5_error kret;
+ krb5_error_code kret;
krb5_fcc_cursor *fcursor;
#ifdef OPENCLOSE
- ret = open(id->data->filename, O_RDONLY, 0);
+ ret = open(((krb5_fcc_data *) id->data)->filename, O_RDONLY, 0);
if (ret < 0)
return errno;
- id->data->fd = ret;
+ ((krb5_fcc_data *) id->data)->fd = ret;
#endif
fcursor = (krb5_fcc_cursor *) cursor;
- ret = lseek(id->data->fd, fcursor->pos, L_SET);
+ ret = lseek(((krb5_fcc_data *) id->data)->fd, fcursor->pos, L_SET);
if (ret < 0)
return errno;
kret = krb5_fcc_read_data(&creds->ticket);
kret = krb5_fcc_read_data(&creds->second_ticket);
- fcursor->pos = tell(id->data->fd);
- cursor = (krb5_cc_cursor) fcursor;
+ fcursor->pos = tell(((krb5_fcc_data *) id->data)->fd);
+ cursor = (krb5_cc_cursor *) fcursor;
#ifdef OPENCLOSE
- close(id->data->fd);
+ close(((krb5_fcc_data *) id->data)->fd);
#endif
return KRB5_OK;
#endif lint
#include <krb5/copyright.h>
+#include "fcc.h"
+
+/* XXX Deal with kret return values */
/* XXX Doesn't deal if < sizeof(o) bytes are written XXX */
-#define krb5_fcc_read(i,b,l) (read(i->data->fd,b,l)==-1 ? errno : KRB5_OK)
+#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:
- * id->data->fd is open and at the right position in the file.
+ * ((krb5_fcc_data *) id->data)->fd is open and at the right position
+ * in the file.
*
* Effects:
* Allocates memory for and decodes the appropriate type from the
* KRB5_NOMEM
*/
-krb5_error
+krb5_error_code
krb5_fcc_read_principal(id, princ)
krb5_ccache id;
krb5_principal princ;
{
- krb5_error kret;
+ krb5_error_code kret;
krb5_int32 length;
+ int i;
/* Read the number of components */
krb5_fcc_read_int32(id, &length);
/* Read length components */
for (i=0; i < length; i++) {
kret = krb5_fcc_read_data(id, princ[i]);
+ if (kret != KRB5_OK) {
+ free(princ);
+ return kret;
+ }
}
return KRB5_OK;
}
-krb5_error
+krb5_error_code
krb5_fcc_read_keyblock(id, keyblock)
krb5_ccache id;
krb5_keyblock *keyblock;
{
- krb5_error kret;
+ krb5_error_code kret;
int ret;
keyblock = (krb5_keyblock *) malloc(sizeof(krb5_keyblock));
kret = krb5_fcc_read_keytype(id, &keyblock->keytype);
kret = krb5_fcc_read_int(id, &keyblock->length);
- ret = read(id->data->fd, keyblock->contents,
+ ret = read(((krb5_fcc_data *) id->data)->fd, keyblock->contents,
(keyblock->length)*sizeof(krb5_octet));
return KRB5_OK;
}
-krb5_error
+krb5_error_code
krb5_fcc_read_data(id, data)
krb5_ccache id;
krb5_data *data;
{
- krb5_error kret;
+ krb5_error_code kret;
int ret;
data = (krb5_data *) malloc(sizeof(krb5_data));
return KRB5_NOMEM;
}
- ret = read(id->data->fd, data->data, data->length);
+ ret = read(((krb5_fcc_data *) id->data)->fd, data->data, data->length);
if (ret == -1)
return errno;
return KRB5_OK;
}
-krb5_error
+krb5_error_code
krb5_fcc_read_int32(id, i)
krb5_ccache id;
krb5_int32 *i;
return krb5_fcc_read(id, i, sizeof(krb5_int32));
}
-krb5_error
+krb5_error_code
krb5_fcc_read_keytype(id, k)
krb5_ccache id;
krb5_keytype *k;
return krb5_fcc_read(id, k, sizeof(krb5_keytype));
}
-krb5_error
+krb5_error_code
krb5_fcc_read_int(id, i)
krb5_ccache id;
int *i;
return krb5_fcc_read(id, i, sizeof(int));
}
-krb5_error
+krb5_error_code
krb5_fcc_read_bool(id, b)
krb5_ccache id;
krb5_boolean *b;
return krb5_fcc_read(id, b, sizeof(krb5_boolean));
}
-krb5_error
+krb5_error_code
krb5_fcc_read_times(id, t)
krb5_ccache id;
krb5_ticket_times *t;
#include "fcc.h"
-extern struct krb5_cc_ops krb5_fcc_ops;
+extern krb5_cc_ops krb5_fcc_ops;
/*
* Requires:
* krb5_ccache. id is undefined.
* permission errors
*/
-krb5_error
+krb5_error_code
krb5_fcc_resolve (id, residual)
krb5_ccache id;
char *residual;
if (id == NULL)
return KRB5_NOMEM;
- id->data = (char *) malloc(sizeof(krb5_fcc_data));
- if (id->data == NULL) {
+ ((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;
}
- id->data->filename = (char *) malloc(strlen(residual) + 1);
- if (id->data->filename == NULL) {
- free(id->data);
+ ((krb5_fcc_data *) id->data)->filename = (char *)
+ malloc(strlen(residual) + 1);
+ if (((krb5_fcc_data *) id->data)->filename == NULL) {
+ free(((krb5_fcc_data *) id->data));
free(id);
return KRB5_NOMEM;
}
bcopy((char *) &krb5_fcc_ops, id->ops, sizeof(struct _krb5_ccache));
/* Set up the filename */
- strcpy(id->data->filename, residual);
+ strcpy(((krb5_fcc_data *) id->data)->filename, residual);
/* Make sure the file name is reserved */
- ret = open(id->data->filename, O_CREAT | O_EXCL, 0);
+ ret = open(((krb5_fcc_data *) id->data)->filename, O_CREAT | O_EXCL, 0);
if (ret == -1 && errno != EEXIST)
return ret;
else {
* permission errors
* KRB5_NOMEM
*/
-krb5_error
+krb5_error_code
krb5_fcc_retrieve(id, whichfields, mcreds, creds)
krb5_ccache id;
krb5_flags whichfields;
* KRB5_NOMEM
* system errors
*/
-krb5_error
+krb5_error_code
krb5_fcc_start_seq_get(id, cursor)
krb5_ccache id;
krb5_cc_cursor *cursor;
{
krb5_fcc_cursor *fcursor;
+ int ret;
- fcursor = (krb5_cc_cursor) malloc(sizeof(krb5_fcc_cursor));
+ fcursor = (krb5_fcc_cursor *) malloc(sizeof(krb5_fcc_cursor));
if (fcursor == NULL)
return KRB5_NOMEM;
/* Make sure we start reading right after the primary principal */
#ifdef OPENCLOSE
- ret = open(id->data->filename, O_RDONLY, 0);
+ ret = open(((krb5_fcc_data *) id->data)->filename, O_RDONLY, 0);
if (ret < 0)
return errno;
- id->data->fd = ret;
+ ((krb5_fcc_data *) id->data)->fd = ret;
#else
- lseek(id->data->fd, 0, L_SET);
+ lseek(((krb5_fcc_data *) id->data)->fd, 0, L_SET);
#endif
krb5_fcc_skip_pprincipal(id);
- fcursor->pos = tell(id->data->fd);
- cursor = (krb5_cc_cursor) fcursor;
+ fcursor->pos = tell(((krb5_fcc_data *) id->data)->fd);
+ cursor = (krb5_cc_cursor *) fcursor;
#ifdef OPENCLOSE
- close(id->data->fd);
+ close(((krb5_fcc_data *) id->data)->fd);
#endif
+
+ return KRB5_OK;
}
#include "fcc.h"
/* XXX Doesn't deal if < sizeof(o) bytes are written XXX */
-#define krb5_fcc_write(i,b,l) (write(i->data->fd,b,l)==-1 ? errno : KRB5_OK)
+#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))
* system errors
* storage failure errors
*/
-krb5_error
+krb5_error_code
krb5_fcc_store(id, creds)
krb5_ccache id;
krb5_creds *creds;
{
#define TCHECK(ret) if (ret != KRB5_OK) goto lose;
- krb5_error ret;
+ krb5_error_code ret;
/* Make sure we are writing to the end of the file */
#ifdef OPENCLOSE
- id->data->fd = open(id->data->filename, O_APPEND, 0);
- if (id->data->fd < 0)
+ ((krb5_fcc_data *) id->data)->fd = open(((krb5_fcc_data *) id->data)->filename, O_APPEND, 0);
+ if (((krb5_fcc_data *) id->data)->fd < 0)
return errno;
#else
- ret = lseek(id->data->fd, L_XTND, 0);
+ ret = lseek(((krb5_fcc_data *) id->data)->fd, L_XTND, 0);
if (ret < 0)
return errno;
#endif
lose:
#ifdef OPENCLOSE
- close(id->data->fd);
+ close(((krb5_fcc_data *) id->data)->fd);
#endif
return ret;
* FOR ALL OF THE FOLLOWING FUNCTIONS:
*
* Requires:
- * id->data->fd is open and at the right position.
+ * ((krb5_fcc_data *) id->data)->fd is open and at the right position.
*
* Effects:
* Stores an encoded version of the second argument in the
* system errors
*/
-static krb5_error
+static krb5_error_code
krb5_fcc_store_principal(id, princ)
krb5_ccache id;
krb5_principal princ;
{
- krb5_error ret;
+ krb5_error_code ret;
krb5_principal temp;
krb5_int32 i, length = 0;
return KRB5_OK;
}
-static krb5_error
+static krb5_error_code
krb5_store_keyblock(id, keyblock)
krb5_ccache id;
krb5_keyblock *keyblock;
{
- krb5_error ret;
+ 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(id->data->fd, keyblock->contents,
+ ret = write(((krb5_fcc_data *) id->data)->fd, keyblock->contents,
(keyblock->length)*sizeof(krb5_octet));
CHECK(ret);
}
-static krb5_error
+static krb5_error_code
krb5_fcc_store_data(id, data)
krb5_ccache id;
krb5_data *data;
{
- krb5_error ret;
+ krb5_error_code ret;
ret = krb5_fcc_store_int32(id, data->length);
CHECK(ret);
- ret = write(id->data->fd, data->data, data->length);
+ ret = write(((krb5_fcc_data *) id->data)->fd, data->data, data->length);
if (ret == -1)
return errno;