+/* -*- mode: c; indent-tabs-mode: nil -*- */
/*
* lib/krb5/keytab/rc-int.h
*
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
- *
+ *
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
- *
+ *
*
* This file contains constant and function declarations used in the
* file-based replay cache routines.
krb5_magic magic;
char *type;
krb5_error_code (KRB5_CALLCONV *init)
- (krb5_context, krb5_rcache,krb5_deltat); /* create */
+ (krb5_context, krb5_rcache,krb5_deltat); /* create */
krb5_error_code (KRB5_CALLCONV *recover)
- (krb5_context, krb5_rcache); /* open */
+ (krb5_context, krb5_rcache); /* open */
krb5_error_code (KRB5_CALLCONV *recover_or_init)
- (krb5_context, krb5_rcache,krb5_deltat);
+ (krb5_context, krb5_rcache,krb5_deltat);
krb5_error_code (KRB5_CALLCONV *destroy)
- (krb5_context, krb5_rcache);
+ (krb5_context, krb5_rcache);
krb5_error_code (KRB5_CALLCONV *close)
- (krb5_context, krb5_rcache);
+ (krb5_context, krb5_rcache);
krb5_error_code (KRB5_CALLCONV *store)
- (krb5_context, krb5_rcache,krb5_donot_replay *);
+ (krb5_context, krb5_rcache,krb5_donot_replay *);
krb5_error_code (KRB5_CALLCONV *expunge)
- (krb5_context, krb5_rcache);
+ (krb5_context, krb5_rcache);
krb5_error_code (KRB5_CALLCONV *get_span)
- (krb5_context, krb5_rcache,krb5_deltat *);
+ (krb5_context, krb5_rcache,krb5_deltat *);
char *(KRB5_CALLCONV *get_name)
- (krb5_context, krb5_rcache);
+ (krb5_context, krb5_rcache);
krb5_error_code (KRB5_CALLCONV *resolve)
- (krb5_context, krb5_rcache, char *);
+ (krb5_context, krb5_rcache, char *);
};
typedef struct _krb5_rc_ops krb5_rc_ops;
+/* -*- mode: c; indent-tabs-mode: nil -*- */
/*
* lib/krb5/rcache/rc_base.c
*
*
*/
-
/*
* Base "glue" functions for the replay cache.
*/
struct krb5_rc_typelist *t, *t_next;
k5_mutex_destroy(&rc_typelist_lock);
for (t = typehead; t != &krb5_rc_typelist_dfl; t = t_next) {
- t_next = t->next;
- free(t);
+ t_next = t->next;
+ free(t);
}
}
krb5_error_code krb5_rc_register_type(krb5_context context,
- const krb5_rc_ops *ops)
+ const krb5_rc_ops *ops)
{
struct krb5_rc_typelist *t;
krb5_error_code err;
err = k5_mutex_lock(&rc_typelist_lock);
if (err)
- return err;
+ return err;
for (t = typehead;t && strcmp(t->ops->type,ops->type);t = t->next)
- ;
+ ;
if (t) {
- k5_mutex_unlock(&rc_typelist_lock);
- return KRB5_RC_TYPE_EXISTS;
+ k5_mutex_unlock(&rc_typelist_lock);
+ return KRB5_RC_TYPE_EXISTS;
}
t = (struct krb5_rc_typelist *) malloc(sizeof(struct krb5_rc_typelist));
if (t == NULL) {
- k5_mutex_unlock(&rc_typelist_lock);
- return KRB5_RC_MALLOC;
+ k5_mutex_unlock(&rc_typelist_lock);
+ return KRB5_RC_MALLOC;
}
t->next = typehead;
t->ops = ops;
}
krb5_error_code krb5_rc_resolve_type(krb5_context context, krb5_rcache *id,
- char *type)
+ char *type)
{
struct krb5_rc_typelist *t;
krb5_error_code err;
err = k5_mutex_lock(&rc_typelist_lock);
if (err)
- return err;
+ return err;
for (t = typehead;t && strcmp(t->ops->type,type);t = t->next)
- ;
+ ;
if (!t) {
- k5_mutex_unlock(&rc_typelist_lock);
- return KRB5_RC_TYPE_NOTFOUND;
+ k5_mutex_unlock(&rc_typelist_lock);
+ return KRB5_RC_TYPE_NOTFOUND;
}
/* allocate *id? nah */
(*id)->ops = t->ops;
{
char *s;
if ((s = getenv("KRB5RCACHETYPE")))
- return s;
+ return s;
else
- return "dfl";
+ return "dfl";
}
char * krb5_rc_default_name(krb5_context context)
{
char *s;
if ((s = getenv("KRB5RCACHENAME")))
- return s;
+ return s;
else
- return (char *) 0;
+ return (char *) 0;
}
krb5_error_code
krb5_error_code retval;
if (!(*id = (krb5_rcache )malloc(sizeof(**id))))
- return KRB5_RC_MALLOC;
+ return KRB5_RC_MALLOC;
- if ((retval = krb5_rc_resolve_type(context, id,
- krb5_rc_default_type(context)))) {
- FREE(*id);
- return retval;
+ if ((retval = krb5_rc_resolve_type(context, id,
+ krb5_rc_default_type(context)))) {
+ FREE(*id);
+ return retval;
}
- if ((retval = krb5_rc_resolve(context, *id,
- krb5_rc_default_name(context)))) {
- k5_mutex_destroy(&(*id)->lock);
- FREE(*id);
- return retval;
+ if ((retval = krb5_rc_resolve(context, *id,
+ krb5_rc_default_name(context)))) {
+ k5_mutex_destroy(&(*id)->lock);
+ FREE(*id);
+ return retval;
}
(*id)->magic = KV5M_RCACHE;
return retval;
unsigned int diff;
if (!(residual = strchr(string_name,':')))
- return KRB5_RC_PARSE;
-
+ return KRB5_RC_PARSE;
+
diff = residual - string_name;
if (!(type = malloc(diff + 1)))
- return KRB5_RC_MALLOC;
+ return KRB5_RC_MALLOC;
(void) strncpy(type, string_name, diff);
type[residual - string_name] = '\0';
if (!(*id = (krb5_rcache) malloc(sizeof(**id)))) {
- FREE(type);
- return KRB5_RC_MALLOC;
+ FREE(type);
+ return KRB5_RC_MALLOC;
}
if ((retval = krb5_rc_resolve_type(context, id,type))) {
- FREE(type);
- FREE(*id);
- return retval;
+ FREE(type);
+ FREE(*id);
+ return retval;
}
FREE(type);
if ((retval = krb5_rc_resolve(context, *id,residual + 1))) {
- k5_mutex_destroy(&(*id)->lock);
- FREE(*id);
- return retval;
+ k5_mutex_destroy(&(*id)->lock);
+ FREE(*id);
+ return retval;
}
(*id)->magic = KV5M_RCACHE;
return retval;
}
-
+/* -*- mode: c; indent-tabs-mode: nil -*- */
/*
* lib/krb5/rcache/rc_base.h
*
+/* -*- mode: c; indent-tabs-mode: nil -*- */
/*
* lib/krb5/rcache/rc_conv.c
*
*
*/
-
/*
* An implementation for the default replay cache type.
*/
#include "rc_base.h"
/*
-Local stuff:
- krb5_auth_to_replay(context, krb5_tkt_authent *auth,krb5_donot_replay *rep)
+ Local stuff:
+ krb5_auth_to_replay(context, krb5_tkt_authent *auth,krb5_donot_replay *rep)
given auth, take important information and make rep; return -1 if failed
*/
krb5_error_code
krb5_auth_to_rep(krb5_context context, krb5_tkt_authent *auth, krb5_donot_replay *rep)
{
- krb5_error_code retval;
- rep->cusec = auth->authenticator->cusec;
- rep->ctime = auth->authenticator->ctime;
- if ((retval = krb5_unparse_name(context, auth->ticket->server, &rep->server)))
- return retval; /* shouldn't happen */
- if ((retval = krb5_unparse_name(context, auth->authenticator->client,
- &rep->client))) {
- FREE(rep->server);
- return retval; /* shouldn't happen. */
- }
- return 0;
+ krb5_error_code retval;
+ rep->cusec = auth->authenticator->cusec;
+ rep->ctime = auth->authenticator->ctime;
+ if ((retval = krb5_unparse_name(context, auth->ticket->server, &rep->server)))
+ return retval; /* shouldn't happen */
+ if ((retval = krb5_unparse_name(context, auth->authenticator->client,
+ &rep->client))) {
+ FREE(rep->server);
+ return retval; /* shouldn't happen. */
+ }
+ return 0;
}
+/* -*- mode: c; indent-tabs-mode: nil -*- */
/*
* lib/krb5/rcache/rc_dfl.c
*
*
*/
-
/*
* An implementation for the default replay cache type.
*/
*/
/*
-Local stuff:
+ Local stuff:
-static int hash(krb5_donot_replay *rep, int hsize)
+ static int hash(krb5_donot_replay *rep, int hsize)
returns hash value of *rep, between 0 and hsize - 1
-HASHSIZE
+ HASHSIZE
size of hash table (constant), can be preset
-static int cmp(krb5_donot_replay *old, krb5_donot_replay *new, krb5_deltat t)
+ static int cmp(krb5_donot_replay *old, krb5_donot_replay *new, krb5_deltat t)
compare old and new; return CMP_REPLAY or CMP_HOHUM
-static int alive(krb5_context, krb5_donot_replay *new, krb5_deltat t)
+ static int alive(krb5_context, krb5_donot_replay *new, krb5_deltat t)
see if new is still alive; return CMP_EXPIRED or CMP_HOHUM
-CMP_MALLOC, CMP_EXPIRED, CMP_REPLAY, CMP_HOHUM
+ CMP_MALLOC, CMP_EXPIRED, CMP_REPLAY, CMP_HOHUM
return codes from cmp(), alive(), and store()
-struct dfl_data
+ struct dfl_data
data stored in this cache type, namely "dfl"
-struct authlist
+ struct authlist
multilinked list of reps
-static int rc_store(context, krb5_rcache id, krb5_donot_replay *rep)
+ static int rc_store(context, krb5_rcache id, krb5_donot_replay *rep)
store rep in cache id; return CMP_REPLAY if replay, else CMP_MALLOC/CMP_HOHUM
*/
cmp(krb5_donot_replay *old, krb5_donot_replay *new1, krb5_deltat t)
{
if ((old->cusec == new1->cusec) && /* most likely to distinguish */
- (old->ctime == new1->ctime) &&
- (strcmp(old->client, new1->client) == 0) &&
- (strcmp(old->server, new1->server) == 0)) /* always true */
- return CMP_REPLAY;
+ (old->ctime == new1->ctime) &&
+ (strcmp(old->client, new1->client) == 0) &&
+ (strcmp(old->server, new1->server) == 0)) /* always true */
+ return CMP_REPLAY;
return CMP_HOHUM;
}
alive(krb5_int32 mytime, krb5_donot_replay *new1, krb5_deltat t)
{
if (mytime == 0)
- return CMP_HOHUM; /* who cares? */
+ return CMP_HOHUM; /* who cares? */
/* I hope we don't have to worry about overflow */
if (new1->ctime + t < mytime)
- return CMP_EXPIRED;
+ return CMP_EXPIRED;
return CMP_HOHUM;
}
static int
rc_store(krb5_context context, krb5_rcache id, krb5_donot_replay *rep,
- krb5_int32 now)
+ krb5_int32 now)
{
struct dfl_data *t = (struct dfl_data *)id->data;
unsigned int rephash;
rephash = hash(rep, t->hsize);
for (ta = t->h[rephash]; ta; ta = ta->nh) {
- switch(cmp(&ta->rep, rep, t->lifespan))
- {
- case CMP_REPLAY:
- return CMP_REPLAY;
- case CMP_HOHUM:
- if (alive(now, &ta->rep, t->lifespan) == CMP_EXPIRED)
- t->nummisses++;
- else
- t->numhits++;
- break;
- default:
- ; /* wtf? */
- }
+ switch(cmp(&ta->rep, rep, t->lifespan))
+ {
+ case CMP_REPLAY:
+ return CMP_REPLAY;
+ case CMP_HOHUM:
+ if (alive(now, &ta->rep, t->lifespan) == CMP_EXPIRED)
+ t->nummisses++;
+ else
+ t->numhits++;
+ break;
+ default:
+ ; /* wtf? */
+ }
}
if (!(ta = (struct authlist *) malloc(sizeof(struct authlist))))
- return CMP_MALLOC;
+ return CMP_MALLOC;
ta->na = t->a; t->a = ta;
ta->nh = t->h[rephash]; t->h[rephash] = ta;
ta->rep = *rep;
if (!(ta->rep.client = strdup(rep->client))) {
- FREE(ta);
- return CMP_MALLOC;
+ FREE(ta);
+ return CMP_MALLOC;
}
if (!(ta->rep.server = strdup(rep->server))) {
- FREE(ta->rep.client);
- FREE(ta);
- return CMP_MALLOC;
+ FREE(ta->rep.client);
+ FREE(ta);
+ return CMP_MALLOC;
}
return CMP_HOHUM;
krb5_error_code KRB5_CALLCONV
krb5_rc_dfl_get_span(krb5_context context, krb5_rcache id,
- krb5_deltat *lifespan)
+ krb5_deltat *lifespan)
{
krb5_error_code err;
struct dfl_data *t;
err = k5_mutex_lock(&id->lock);
if (err)
- return err;
+ return err;
t = (struct dfl_data *) id->data;
*lifespan = t->lifespan;
k5_mutex_unlock(&id->lock);
/* default to clockskew from the context */
#ifndef NOIOSTUFF
if ((retval = krb5_rc_io_creat(context, &t->d, &t->name))) {
- return retval;
+ return retval;
}
if ((krb5_rc_io_write(context, &t->d,
- (krb5_pointer) &t->lifespan, sizeof(t->lifespan))
- || krb5_rc_io_sync(context, &t->d))) {
- return KRB5_RC_IO;
+ (krb5_pointer) &t->lifespan, sizeof(t->lifespan))
+ || krb5_rc_io_sync(context, &t->d))) {
+ return KRB5_RC_IO;
}
#endif
return 0;
retval = k5_mutex_lock(&id->lock);
if (retval)
- return retval;
+ return retval;
retval = krb5_rc_dfl_init_locked(context, id, lifespan);
k5_mutex_unlock(&id->lock);
return retval;
FREE(t->h);
if (t->name)
- FREE(t->name);
+ FREE(t->name);
while ((q = t->a))
{
- t->a = q->na;
- FREE(q->rep.client);
- FREE(q->rep.server);
- FREE(q);
+ t->a = q->na;
+ FREE(q->rep.client);
+ FREE(q->rep.server);
+ FREE(q);
}
#ifndef NOIOSTUFF
(void) krb5_rc_io_close(context, &t->d);
krb5_error_code retval;
retval = k5_mutex_lock(&id->lock);
if (retval)
- return retval;
+ return retval;
krb5_rc_dfl_close_no_free(context, id);
k5_mutex_unlock(&id->lock);
k5_mutex_destroy(&id->lock);
{
#ifndef NOIOSTUFF
if (krb5_rc_io_destroy(context, &((struct dfl_data *) (id->data))->d))
- return KRB5_RC_IO;
+ return KRB5_RC_IO;
#endif
return krb5_rc_dfl_close(context, id);
}
/* allocate id? no */
if (!(t = (struct dfl_data *) calloc(1, sizeof(struct dfl_data))))
- return KRB5_RC_MALLOC;
+ return KRB5_RC_MALLOC;
id->data = (krb5_pointer) t;
if (name) {
- t->name = strdup(name);
- if (!t->name) {
- retval = KRB5_RC_MALLOC;
- goto cleanup;
- }
+ t->name = strdup(name);
+ if (!t->name) {
+ retval = KRB5_RC_MALLOC;
+ goto cleanup;
+ }
} else
- t->name = 0;
+ t->name = 0;
t->numhits = t->nummisses = 0;
t->hsize = HASHSIZE; /* no need to store---it's memory-only */
t->h = (struct authlist **) malloc(t->hsize*sizeof(struct authlist *));
if (!t->h) {
- retval = KRB5_RC_MALLOC;
- goto cleanup;
+ retval = KRB5_RC_MALLOC;
+ goto cleanup;
}
memset(t->h, 0, t->hsize*sizeof(struct authlist *));
t->a = (struct authlist *) 0;
cleanup:
if (t) {
- if (t->name)
- krb5_xfree(t->name);
- if (t->h)
- krb5_xfree(t->h);
- krb5_xfree(t);
+ if (t->name)
+ krb5_xfree(t->name);
+ if (t->h)
+ krb5_xfree(t->h);
+ krb5_xfree(t);
}
return retval;
}
*rep = NULL;
if (rp)
{
- if (rp->client)
- free(rp->client);
-
- if (rp->server)
- free(rp->server);
- rp->client = NULL;
- rp->server = NULL;
- free(rp);
+ if (rp->client)
+ free(rp->client);
+
+ if (rp->server)
+ free(rp->server);
+ rp->client = NULL;
+ rp->server = NULL;
+ free(rp);
}
}
static krb5_error_code
krb5_rc_io_fetch(krb5_context context, struct dfl_data *t,
- krb5_donot_replay *rep, int maxlen)
+ krb5_donot_replay *rep, int maxlen)
{
int len2;
unsigned int len;
rep->client = rep->server = 0;
retval = krb5_rc_io_read(context, &t->d, (krb5_pointer) &len2,
- sizeof(len2));
+ sizeof(len2));
if (retval)
- return retval;
+ return retval;
if ((len2 <= 0) || (len2 >= maxlen))
- return KRB5_RC_IO_EOF;
+ return KRB5_RC_IO_EOF;
len = len2;
rep->client = malloc (len);
if (!rep->client)
- return KRB5_RC_MALLOC;
+ return KRB5_RC_MALLOC;
retval = krb5_rc_io_read(context, &t->d, (krb5_pointer) rep->client, len);
if (retval)
- goto errout;
+ goto errout;
- retval = krb5_rc_io_read(context, &t->d, (krb5_pointer) &len2,
- sizeof(len2));
+ retval = krb5_rc_io_read(context, &t->d, (krb5_pointer) &len2,
+ sizeof(len2));
if (retval)
- goto errout;
+ goto errout;
if ((len2 <= 0) || (len2 >= maxlen)) {
- retval = KRB5_RC_IO_EOF;
- goto errout;
+ retval = KRB5_RC_IO_EOF;
+ goto errout;
}
len = len2;
rep->server = malloc (len);
if (!rep->server) {
- retval = KRB5_RC_MALLOC;
- goto errout;
+ retval = KRB5_RC_MALLOC;
+ goto errout;
}
retval = krb5_rc_io_read(context, &t->d, (krb5_pointer) rep->server, len);
if (retval)
- goto errout;
+ goto errout;
retval = krb5_rc_io_read(context, &t->d, (krb5_pointer) &rep->cusec,
- sizeof(rep->cusec));
+ sizeof(rep->cusec));
if (retval)
- goto errout;
+ goto errout;
retval = krb5_rc_io_read(context, &t->d, (krb5_pointer) &rep->ctime,
- sizeof(rep->ctime));
+ sizeof(rep->ctime));
if (retval)
- goto errout;
+ goto errout;
return 0;
errout:
if (rep->client)
- krb5_xfree(rep->client);
+ krb5_xfree(rep->client);
if (rep->server)
- krb5_xfree(rep->server);
+ krb5_xfree(rep->server);
rep->client = rep->server = 0;
return retval;
}
krb5_int32 now;
if ((retval = krb5_rc_io_open(context, &t->d, t->name))) {
- return retval;
+ return retval;
}
t->recovering = 1;
rep = NULL;
if (krb5_rc_io_read(context, &t->d, (krb5_pointer) &t->lifespan,
- sizeof(t->lifespan))) {
- retval = KRB5_RC_IO;
- goto io_fail;
+ sizeof(t->lifespan))) {
+ retval = KRB5_RC_IO;
+ goto io_fail;
}
if (!(rep = (krb5_donot_replay *) malloc(sizeof(krb5_donot_replay)))) {
- retval = KRB5_RC_MALLOC;
- goto io_fail;
+ retval = KRB5_RC_MALLOC;
+ goto io_fail;
}
rep->client = NULL;
rep->server = NULL;
if (krb5_timeofday(context, &now))
- now = 0;
+ now = 0;
/* now read in each auth_replay and insert into table */
for (;;) {
- if (krb5_rc_io_mark(context, &t->d)) {
- retval = KRB5_RC_IO;
- goto io_fail;
- }
-
- retval = krb5_rc_io_fetch(context, t, rep, (int) max_size);
-
- if (retval == KRB5_RC_IO_EOF)
- break;
- else if (retval != 0)
- goto io_fail;
-
-
- if (alive(now, rep, t->lifespan) != CMP_EXPIRED) {
- if (rc_store(context, id, rep, now) == CMP_MALLOC) {
- retval = KRB5_RC_MALLOC; goto io_fail;
- }
- } else {
- expired_entries++;
- }
- /*
- * free fields allocated by rc_io_fetch
- */
- FREE(rep->server);
- FREE(rep->client);
- rep->server = 0;
- rep->client = 0;
+ if (krb5_rc_io_mark(context, &t->d)) {
+ retval = KRB5_RC_IO;
+ goto io_fail;
+ }
+
+ retval = krb5_rc_io_fetch(context, t, rep, (int) max_size);
+
+ if (retval == KRB5_RC_IO_EOF)
+ break;
+ else if (retval != 0)
+ goto io_fail;
+
+
+ if (alive(now, rep, t->lifespan) != CMP_EXPIRED) {
+ if (rc_store(context, id, rep, now) == CMP_MALLOC) {
+ retval = KRB5_RC_MALLOC; goto io_fail;
+ }
+ } else {
+ expired_entries++;
+ }
+ /*
+ * free fields allocated by rc_io_fetch
+ */
+ FREE(rep->server);
+ FREE(rep->client);
+ rep->server = 0;
+ rep->client = 0;
}
retval = 0;
krb5_rc_io_unmark(context, &t->d);
io_fail:
krb5_rc_free_entry(context, &rep);
if (retval)
- krb5_rc_io_close(context, &t->d);
+ krb5_rc_io_close(context, &t->d);
else if (expired_entries > EXCESSREPS)
- retval = krb5_rc_dfl_expunge_locked(context, id);
+ retval = krb5_rc_dfl_expunge_locked(context, id);
t->recovering = 0;
return retval;
krb5_error_code ret;
ret = k5_mutex_lock(&id->lock);
if (ret)
- return ret;
+ return ret;
ret = krb5_rc_dfl_recover_locked(context, id);
k5_mutex_unlock(&id->lock);
return ret;
krb5_error_code KRB5_CALLCONV
krb5_rc_dfl_recover_or_init(krb5_context context, krb5_rcache id,
- krb5_deltat lifespan)
+ krb5_deltat lifespan)
{
krb5_error_code retval;
retval = k5_mutex_lock(&id->lock);
if (retval)
- return retval;
+ return retval;
retval = krb5_rc_dfl_recover_locked(context, id);
if (retval)
- retval = krb5_rc_dfl_init_locked(context, id, lifespan);
+ retval = krb5_rc_dfl_init_locked(context, id, lifespan);
k5_mutex_unlock(&id->lock);
return retval;
}
static krb5_error_code
krb5_rc_io_store(krb5_context context, struct dfl_data *t,
- krb5_donot_replay *rep)
+ krb5_donot_replay *rep)
{
unsigned int clientlen, serverlen, len;
char *buf, *ptr;
clientlen = strlen(rep->client) + 1;
serverlen = strlen(rep->server) + 1;
len = sizeof(clientlen) + clientlen + sizeof(serverlen) + serverlen +
- sizeof(rep->cusec) + sizeof(rep->ctime);
+ sizeof(rep->cusec) + sizeof(rep->ctime);
buf = malloc(len);
if (buf == 0)
- return KRB5_RC_MALLOC;
+ return KRB5_RC_MALLOC;
ptr = buf;
memcpy(ptr, &clientlen, sizeof(clientlen)); ptr += sizeof(clientlen);
memcpy(ptr, rep->client, clientlen); ptr += clientlen;
ret = krb5_timeofday(context, &now);
if (ret)
- return ret;
+ return ret;
ret = k5_mutex_lock(&id->lock);
if (ret)
- return ret;
+ return ret;
switch(rc_store(context, id, rep, now)) {
case CMP_MALLOC:
- k5_mutex_unlock(&id->lock);
- return KRB5_RC_MALLOC;
+ k5_mutex_unlock(&id->lock);
+ return KRB5_RC_MALLOC;
case CMP_REPLAY:
- k5_mutex_unlock(&id->lock);
- return KRB5KRB_AP_ERR_REPEAT;
+ k5_mutex_unlock(&id->lock);
+ return KRB5KRB_AP_ERR_REPEAT;
case 0: break;
default: /* wtf? */ ;
}
#ifndef NOIOSTUFF
ret = krb5_rc_io_store(context, t, rep);
if (ret) {
- k5_mutex_unlock(&id->lock);
- return ret;
+ k5_mutex_unlock(&id->lock);
+ return ret;
}
#endif
/* Shall we automatically expunge? */
if (t->nummisses > t->numhits + EXCESSREPS)
{
- ret = krb5_rc_dfl_expunge_locked(context, id);
- k5_mutex_unlock(&id->lock);
- return ret;
+ ret = krb5_rc_dfl_expunge_locked(context, id);
+ k5_mutex_unlock(&id->lock);
+ return ret;
}
#ifndef NOIOSTUFF
else
{
- if (krb5_rc_io_sync(context, &t->d)) {
- k5_mutex_unlock(&id->lock);
- return KRB5_RC_IO;
- }
+ if (krb5_rc_io_sync(context, &t->d)) {
+ k5_mutex_unlock(&id->lock);
+ return KRB5_RC_IO;
+ }
}
#endif
k5_mutex_unlock(&id->lock);
krb5_int32 now;
if (krb5_timestamp(context, &now))
- now = 0;
+ now = 0;
for (q = &t->a; *q; q = qt) {
- qt = &(*q)->na;
- if (alive(now, &(*q)->rep, t->lifespan) == CMP_EXPIRED) {
- FREE((*q)->rep.client);
- FREE((*q)->rep.server);
- FREE(*q);
- *q = *qt; /* why doesn't this feel right? */
- }
+ qt = &(*q)->na;
+ if (alive(now, &(*q)->rep, t->lifespan) == CMP_EXPIRED) {
+ FREE((*q)->rep.client);
+ FREE((*q)->rep.server);
+ FREE(*q);
+ *q = *qt; /* why doesn't this feel right? */
+ }
}
for (i = 0; i < t->hsize; i++)
- t->h[i] = (struct authlist *) 0;
+ t->h[i] = (struct authlist *) 0;
for (r = t->a; r; r = r->na) {
- i = hash(&r->rep, t->hsize);
- rt = t->h[i];
- t->h[i] = r;
- r->nh = rt;
+ i = hash(&r->rep, t->hsize);
+ rt = t->h[i];
+ t->h[i] = r;
+ r->nh = rt;
}
return 0;
#else
krb5_deltat lifespan = t->lifespan; /* save original lifespan */
if (! t->recovering) {
- name = t->name;
- t->name = 0; /* Clear name so it isn't freed */
- (void) krb5_rc_dfl_close_no_free(context, id);
- retval = krb5_rc_dfl_resolve(context, id, name);
- free(name);
- if (retval)
- return retval;
- retval = krb5_rc_dfl_recover_locked(context, id);
- if (retval)
- return retval;
- t = (struct dfl_data *)id->data; /* point to recovered cache */
+ name = t->name;
+ t->name = 0; /* Clear name so it isn't freed */
+ (void) krb5_rc_dfl_close_no_free(context, id);
+ retval = krb5_rc_dfl_resolve(context, id, name);
+ free(name);
+ if (retval)
+ return retval;
+ retval = krb5_rc_dfl_recover_locked(context, id);
+ if (retval)
+ return retval;
+ t = (struct dfl_data *)id->data; /* point to recovered cache */
}
tmp = (krb5_rcache) malloc(sizeof(*tmp));
if (!tmp)
- return ENOMEM;
+ return ENOMEM;
retval = krb5_rc_resolve_type(context, &tmp, "dfl");
if (retval) {
free(tmp);
if (retval)
goto cleanup;
for (q = t->a; q; q = q->na) {
- if (krb5_rc_io_store(context, (struct dfl_data *)tmp->data, &q->rep)) {
+ if (krb5_rc_io_store(context, (struct dfl_data *)tmp->data, &q->rep)) {
retval = KRB5_RC_IO;
goto cleanup;
}
if (krb5_rc_io_move(context, &t->d, &((struct dfl_data *)tmp->data)->d))
goto cleanup;
retval = 0;
- cleanup:
+cleanup:
(void) krb5_rc_dfl_close(context, tmp);
return retval;
#endif
krb5_error_code ret;
ret = k5_mutex_lock(&id->lock);
if (ret)
- return ret;
+ return ret;
ret = krb5_rc_dfl_expunge_locked(context, id);
k5_mutex_unlock(&id->lock);
return ret;
+/* -*- mode: c; indent-tabs-mode: nil -*- */
/*
* lib/krb5/rcache/rc_dfl.h
*
#ifndef KRB5_RC_DFL_H
#define KRB5_RC_DFL_H
-krb5_error_code KRB5_CALLCONV krb5_rc_dfl_init
- (krb5_context,
- krb5_rcache,
- krb5_deltat);
-krb5_error_code KRB5_CALLCONV krb5_rc_dfl_recover
- (krb5_context,
- krb5_rcache);
+krb5_error_code KRB5_CALLCONV krb5_rc_dfl_init
+ (krb5_context,
+ krb5_rcache,
+ krb5_deltat);
+krb5_error_code KRB5_CALLCONV krb5_rc_dfl_recover
+ (krb5_context,
+ krb5_rcache);
krb5_error_code KRB5_CALLCONV krb5_rc_dfl_recover_or_init
- (krb5_context, krb5_rcache, krb5_deltat);
-krb5_error_code KRB5_CALLCONV krb5_rc_dfl_destroy
- (krb5_context,
- krb5_rcache);
-krb5_error_code KRB5_CALLCONV krb5_rc_dfl_close
- (krb5_context,
- krb5_rcache);
-krb5_error_code KRB5_CALLCONV krb5_rc_dfl_store
- (krb5_context,
- krb5_rcache,
- krb5_donot_replay *);
-krb5_error_code KRB5_CALLCONV krb5_rc_dfl_expunge
- (krb5_context,
- krb5_rcache);
-krb5_error_code KRB5_CALLCONV krb5_rc_dfl_get_span
- (krb5_context,
- krb5_rcache,
- krb5_deltat *);
-char * KRB5_CALLCONV krb5_rc_dfl_get_name
- (krb5_context,
- krb5_rcache);
-krb5_error_code KRB5_CALLCONV krb5_rc_dfl_resolve
- (krb5_context,
- krb5_rcache,
- char *);
+ (krb5_context, krb5_rcache, krb5_deltat);
+krb5_error_code KRB5_CALLCONV krb5_rc_dfl_destroy
+ (krb5_context,
+ krb5_rcache);
+krb5_error_code KRB5_CALLCONV krb5_rc_dfl_close
+ (krb5_context,
+ krb5_rcache);
+krb5_error_code KRB5_CALLCONV krb5_rc_dfl_store
+ (krb5_context,
+ krb5_rcache,
+ krb5_donot_replay *);
+krb5_error_code KRB5_CALLCONV krb5_rc_dfl_expunge
+ (krb5_context,
+ krb5_rcache);
+krb5_error_code KRB5_CALLCONV krb5_rc_dfl_get_span
+ (krb5_context,
+ krb5_rcache,
+ krb5_deltat *);
+char * KRB5_CALLCONV krb5_rc_dfl_get_name
+ (krb5_context,
+ krb5_rcache);
+krb5_error_code KRB5_CALLCONV krb5_rc_dfl_resolve
+ (krb5_context,
+ krb5_rcache,
+ char *);
krb5_error_code krb5_rc_dfl_close_no_free
- (krb5_context,
- krb5_rcache);
-void krb5_rc_free_entry
- (krb5_context,
- krb5_donot_replay **);
+ (krb5_context,
+ krb5_rcache);
+void krb5_rc_free_entry
+ (krb5_context,
+ krb5_donot_replay **);
#endif
-
+/* -*- mode: c; indent-tabs-mode: nil -*- */
/*
* lib/krb5/rcache/rc_io.c
*
*
*/
-
/*
* I/O functions for the replay cache default implementation.
*/
# define PATH_SEPARATOR "/"
#endif
-#define KRB5_RC_VNO 0x0501 /* krb5, rcache v 1 */
+#define KRB5_RC_VNO 0x0501 /* krb5, rcache v 1 */
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
if (!(dir = getenv("KRB5RCACHEDIR"))) {
#if defined(_WIN32)
- if (!(dir = getenv("TEMP")))
- if (!(dir = getenv("TMP")))
- dir = "C:";
+ if (!(dir = getenv("TEMP")))
+ if (!(dir = getenv("TMP")))
+ dir = "C:";
#else
- if (!(dir = getenv("TMPDIR"))) {
+ if (!(dir = getenv("TMPDIR"))) {
#ifdef RCTMPDIR
- dir = RCTMPDIR;
+ dir = RCTMPDIR;
#else
- dir = "/tmp";
+ dir = "/tmp";
#endif
- }
+ }
#endif
}
return dir;
memset(&stbuf, 0, sizeof(stbuf));
if (asprintf(&d->fn, "%s%skrb5_RCXXXXXX",
- dir, PATH_SEPARATOR) < 0) {
- d->fn = NULL;
- return KRB5_RC_IO_MALLOC;
+ dir, PATH_SEPARATOR) < 0) {
+ d->fn = NULL;
+ return KRB5_RC_IO_MALLOC;
}
d->fd = mkstemp(d->fn);
if (d->fd == -1) {
- /*
- * This return value is deliberate because d->fd == -1 causes
- * caller to go into errno interpretation code.
- */
- return 0;
+ /*
+ * This return value is deliberate because d->fd == -1 causes
+ * caller to go into errno interpretation code.
+ */
+ return 0;
}
#if HAVE_SYS_STAT_H
/*
*/
retval = fstat(d->fd, &stbuf);
if (retval) {
- krb5_set_error_message(context, retval,
- "Cannot fstat replay cache file %s: %s",
- d->fn, strerror(errno));
- return KRB5_RC_IO_UNKNOWN;
+ krb5_set_error_message(context, retval,
+ "Cannot fstat replay cache file %s: %s",
+ d->fn, strerror(errno));
+ return KRB5_RC_IO_UNKNOWN;
}
if (stbuf.st_mode & 077) {
- krb5_set_error_message(context, retval,
- "Insecure mkstemp() file mode "
- "for replay cache file %s; "
- "try running this program "
- "with umask 077 ", d->fn);
- return KRB5_RC_IO_UNKNOWN;
+ krb5_set_error_message(context, retval,
+ "Insecure mkstemp() file mode "
+ "for replay cache file %s; "
+ "try running this program "
+ "with umask 077 ", d->fn);
+ return KRB5_RC_IO_UNKNOWN;
}
#endif
return 0;
static krb5_error_code
rc_map_errno (krb5_context context, int e, const char *fn,
- const char *operation)
+ const char *operation)
{
switch (e) {
case EFBIG:
case EDQUOT:
#endif
case ENOSPC:
- return KRB5_RC_IO_SPACE;
+ return KRB5_RC_IO_SPACE;
case EIO:
- return KRB5_RC_IO_IO;
+ return KRB5_RC_IO_IO;
case EPERM:
case EACCES:
case EROFS:
case EEXIST:
- krb5_set_error_message(context, KRB5_RC_IO_PERM,
- "Cannot %s replay cache file %s: %s",
- operation, fn, strerror(e));
- return KRB5_RC_IO_PERM;
+ krb5_set_error_message(context, KRB5_RC_IO_PERM,
+ "Cannot %s replay cache file %s: %s",
+ operation, fn, strerror(e));
+ return KRB5_RC_IO_PERM;
default:
- krb5_set_error_message(context, KRB5_RC_IO_UNKNOWN,
- "Cannot %s replay cache: %s",
- operation, strerror(e));
- return KRB5_RC_IO_UNKNOWN;
+ krb5_set_error_message(context, KRB5_RC_IO_UNKNOWN,
+ "Cannot %s replay cache: %s",
+ operation, strerror(e));
+ return KRB5_RC_IO_UNKNOWN;
}
}
GETDIR;
if (fn && *fn) {
- if (asprintf(&d->fn, "%s%s%s", dir, PATH_SEPARATOR, *fn) < 0)
- return KRB5_RC_IO_MALLOC;
- unlink(d->fn);
- d->fd = THREEPARAMOPEN(d->fn, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL |
- O_BINARY, 0600);
+ if (asprintf(&d->fn, "%s%s%s", dir, PATH_SEPARATOR, *fn) < 0)
+ return KRB5_RC_IO_MALLOC;
+ unlink(d->fn);
+ d->fd = THREEPARAMOPEN(d->fn, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL |
+ O_BINARY, 0600);
} else {
- retval = krb5_rc_io_mkstemp(context, d, dir);
- if (retval)
- goto cleanup;
- if (d->fd != -1 && fn) {
- *fn = strdup(d->fn + dirlen);
- if (*fn == NULL) {
- free(d->fn);
- return KRB5_RC_IO_MALLOC;
- }
- }
+ retval = krb5_rc_io_mkstemp(context, d, dir);
+ if (retval)
+ goto cleanup;
+ if (d->fd != -1 && fn) {
+ *fn = strdup(d->fn + dirlen);
+ if (*fn == NULL) {
+ free(d->fn);
+ return KRB5_RC_IO_MALLOC;
+ }
+ }
}
if (d->fd == -1) {
- retval = rc_map_errno(context, errno, d->fn, "create");
- if (retval == KRB5_RC_IO_PERM)
- do_not_unlink = 1;
- goto cleanup;
+ retval = rc_map_errno(context, errno, d->fn, "create");
+ if (retval == KRB5_RC_IO_PERM)
+ do_not_unlink = 1;
+ goto cleanup;
}
set_cloexec_fd(d->fd);
retval = krb5_rc_io_write(context, d, (krb5_pointer)&rc_vno,
- sizeof(rc_vno));
+ sizeof(rc_vno));
if (retval)
- goto cleanup;
+ goto cleanup;
retval = krb5_rc_io_sync(context, d);
- cleanup:
+cleanup:
if (retval) {
- if (d->fn) {
- if (!do_not_unlink)
- (void) unlink(d->fn);
- FREE(d->fn);
- d->fn = NULL;
- }
- if (d->fd != -1) {
- (void) close(d->fd);
- }
+ if (d->fn) {
+ if (!do_not_unlink)
+ (void) unlink(d->fn);
+ FREE(d->fn);
+ d->fn = NULL;
+ }
+ if (d->fd != -1) {
+ (void) close(d->fd);
+ }
}
return retval;
}
static krb5_error_code
krb5_rc_io_open_internal(krb5_context context, krb5_rc_iostuff *d, char *fn,
- char* full_pathname)
+ char* full_pathname)
{
krb5_int16 rc_vno;
krb5_error_code retval = 0;
GETDIR;
if (full_pathname) {
- if (!(d->fn = strdup(full_pathname)))
- return KRB5_RC_IO_MALLOC;
+ if (!(d->fn = strdup(full_pathname)))
+ return KRB5_RC_IO_MALLOC;
} else {
- if (asprintf(&d->fn, "%s%s%s", dir, PATH_SEPARATOR, fn) < 0)
- return KRB5_RC_IO_MALLOC;
+ if (asprintf(&d->fn, "%s%s%s", dir, PATH_SEPARATOR, fn) < 0)
+ return KRB5_RC_IO_MALLOC;
}
#ifdef NO_USERID
d->fd = THREEPARAMOPEN(d->fn, O_RDWR | O_BINARY, 0600);
#else
if ((d->fd = stat(d->fn, &statb)) != -1) {
- uid_t me;
-
- me = geteuid();
- /* must be owned by this user, to prevent some security problems with
- * other users modifying replay cache stufff */
- if ((statb.st_uid != me) || ((statb.st_mode & S_IFMT) != S_IFREG)) {
- FREE(d->fn);
- return KRB5_RC_IO_PERM;
- }
- d->fd = THREEPARAMOPEN(d->fn, O_RDWR | O_BINARY, 0600);
+ uid_t me;
+
+ me = geteuid();
+ /* must be owned by this user, to prevent some security problems with
+ * other users modifying replay cache stufff */
+ if ((statb.st_uid != me) || ((statb.st_mode & S_IFMT) != S_IFREG)) {
+ FREE(d->fn);
+ return KRB5_RC_IO_PERM;
+ }
+ d->fd = THREEPARAMOPEN(d->fn, O_RDWR | O_BINARY, 0600);
}
#endif
if (d->fd == -1) {
- retval = rc_map_errno(context, errno, d->fn, "open");
- goto cleanup;
+ retval = rc_map_errno(context, errno, d->fn, "open");
+ goto cleanup;
}
set_cloexec_fd(d->fd);
do_not_unlink = 0;
retval = krb5_rc_io_read(context, d, (krb5_pointer) &rc_vno,
- sizeof(rc_vno));
+ sizeof(rc_vno));
if (retval)
- goto cleanup;
+ goto cleanup;
if (ntohs(rc_vno) != KRB5_RC_VNO)
- retval = KRB5_RCACHE_BADVNO;
+ retval = KRB5_RCACHE_BADVNO;
- cleanup:
+cleanup:
if (retval) {
- if (d->fn) {
- if (!do_not_unlink)
- (void) unlink(d->fn);
- FREE(d->fn);
- d->fn = NULL;
- }
- if (d->fd >= 0)
- (void) close(d->fd);
+ if (d->fn) {
+ if (!do_not_unlink)
+ (void) unlink(d->fn);
+ FREE(d->fn);
+ d->fn = NULL;
+ }
+ if (d->fd >= 0)
+ (void) close(d->fd);
}
return retval;
}
krb5_error_code
krb5_rc_io_move(krb5_context context, krb5_rc_iostuff *new1,
- krb5_rc_iostuff *old)
+ krb5_rc_iostuff *old)
{
#if defined(_WIN32) || defined(__CYGWIN__)
char *new_fn = NULL;
old->fd = -1;
if (rename(old_fn, new_fn) == -1) { /* MUST be atomic! */
- retval = KRB5_RC_IO_UNKNOWN;
- goto cleanup;
+ retval = KRB5_RC_IO_UNKNOWN;
+ goto cleanup;
}
retval = krb5_rc_io_open_internal(context, new1, 0, new_fn);
if (retval)
- goto cleanup;
+ goto cleanup;
if (lseek(new1->fd, offset, SEEK_SET) == -1) {
- retval = KRB5_RC_IO_UNKNOWN;
- goto cleanup;
+ retval = KRB5_RC_IO_UNKNOWN;
+ goto cleanup;
}
- cleanup:
+cleanup:
free(new_fn);
free(old_fn);
return retval;
#else
char *fn = NULL;
if (rename(old->fn, new1->fn) == -1) /* MUST be atomic! */
- return KRB5_RC_IO_UNKNOWN;
+ return KRB5_RC_IO_UNKNOWN;
fn = new1->fn;
- new1->fn = NULL; /* avoid clobbering */
+ new1->fn = NULL; /* avoid clobbering */
(void) krb5_rc_io_close(context, new1);
new1->fn = fn;
new1->fd = dup(old->fd);
krb5_error_code
krb5_rc_io_write(krb5_context context, krb5_rc_iostuff *d, krb5_pointer buf,
- unsigned int num)
+ unsigned int num)
{
if (write(d->fd, (char *) buf, num) == -1)
- switch(errno)
- {
+ switch(errno)
+ {
#ifdef EDQUOT
- case EDQUOT:
+ case EDQUOT:
#endif
- case EFBIG:
- case ENOSPC:
- krb5_set_error_message (context, KRB5_RC_IO_SPACE,
- "Can't write to replay cache: %s",
- strerror(errno));
- return KRB5_RC_IO_SPACE;
- case EIO:
- krb5_set_error_message (context, KRB5_RC_IO_IO,
- "Can't write to replay cache: %s",
- strerror(errno));
- return KRB5_RC_IO_IO;
- case EBADF:
- default:
- krb5_set_error_message (context, KRB5_RC_IO_UNKNOWN,
- "Can't write to replay cache: %s",
- strerror(errno));
- return KRB5_RC_IO_UNKNOWN;
- }
+ case EFBIG:
+ case ENOSPC:
+ krb5_set_error_message (context, KRB5_RC_IO_SPACE,
+ "Can't write to replay cache: %s",
+ strerror(errno));
+ return KRB5_RC_IO_SPACE;
+ case EIO:
+ krb5_set_error_message (context, KRB5_RC_IO_IO,
+ "Can't write to replay cache: %s",
+ strerror(errno));
+ return KRB5_RC_IO_IO;
+ case EBADF:
+ default:
+ krb5_set_error_message (context, KRB5_RC_IO_UNKNOWN,
+ "Can't write to replay cache: %s",
+ strerror(errno));
+ return KRB5_RC_IO_UNKNOWN;
+ }
return 0;
}
#endif
#endif
if (fsync(d->fd) == -1) {
- switch(errno)
- {
- case EBADF: return KRB5_RC_IO_UNKNOWN;
- case EIO: return KRB5_RC_IO_IO;
- default:
- krb5_set_error_message(context, KRB5_RC_IO_UNKNOWN,
- "Cannot sync replay cache file: %s",
- strerror(errno));
- return KRB5_RC_IO_UNKNOWN;
- }
+ switch(errno)
+ {
+ case EBADF: return KRB5_RC_IO_UNKNOWN;
+ case EIO: return KRB5_RC_IO_IO;
+ default:
+ krb5_set_error_message(context, KRB5_RC_IO_UNKNOWN,
+ "Cannot sync replay cache file: %s",
+ strerror(errno));
+ return KRB5_RC_IO_UNKNOWN;
+ }
}
return 0;
}
krb5_error_code
krb5_rc_io_read(krb5_context context, krb5_rc_iostuff *d, krb5_pointer buf,
- unsigned int num)
+ unsigned int num)
{
int count;
if ((count = read(d->fd, (char *) buf, num)) == -1)
- switch(errno)
- {
- case EIO: return KRB5_RC_IO_IO;
- case EBADF:
- default:
- krb5_set_error_message(context, KRB5_RC_IO_UNKNOWN,
- "Can't read from replay cache: %s",
- strerror(errno));
- return KRB5_RC_IO_UNKNOWN;
- }
+ switch(errno)
+ {
+ case EIO: return KRB5_RC_IO_IO;
+ case EBADF:
+ default:
+ krb5_set_error_message(context, KRB5_RC_IO_UNKNOWN,
+ "Can't read from replay cache: %s",
+ strerror(errno));
+ return KRB5_RC_IO_UNKNOWN;
+ }
if (count < 0 || (unsigned int)count != num)
- return KRB5_RC_IO_EOF;
+ return KRB5_RC_IO_EOF;
return 0;
}
krb5_rc_io_close(krb5_context context, krb5_rc_iostuff *d)
{
if (d->fn != NULL) {
- FREE(d->fn);
- d->fn = NULL;
+ FREE(d->fn);
+ d->fn = NULL;
}
if (d->fd != -1) {
- if (close(d->fd) == -1) /* can't happen */
- return KRB5_RC_IO_UNKNOWN;
- d->fd = -1;
+ if (close(d->fd) == -1) /* can't happen */
+ return KRB5_RC_IO_UNKNOWN;
+ d->fd = -1;
}
return 0;
}
krb5_rc_io_destroy(krb5_context context, krb5_rc_iostuff *d)
{
if (unlink(d->fn) == -1)
- switch(errno)
- {
- case EIO:
- krb5_set_error_message(context, KRB5_RC_IO_IO,
- "Can't destroy replay cache: %s",
- strerror(errno));
- return KRB5_RC_IO_IO;
- case EPERM:
- case EBUSY:
- case EROFS:
- krb5_set_error_message(context, KRB5_RC_IO_PERM,
- "Can't destroy replay cache: %s",
- strerror(errno));
- return KRB5_RC_IO_PERM;
- case EBADF:
- default:
- krb5_set_error_message(context, KRB5_RC_IO_UNKNOWN,
- "Can't destroy replay cache: %s",
- strerror(errno));
- return KRB5_RC_IO_UNKNOWN;
- }
+ switch(errno)
+ {
+ case EIO:
+ krb5_set_error_message(context, KRB5_RC_IO_IO,
+ "Can't destroy replay cache: %s",
+ strerror(errno));
+ return KRB5_RC_IO_IO;
+ case EPERM:
+ case EBUSY:
+ case EROFS:
+ krb5_set_error_message(context, KRB5_RC_IO_PERM,
+ "Can't destroy replay cache: %s",
+ strerror(errno));
+ return KRB5_RC_IO_PERM;
+ case EBADF:
+ default:
+ krb5_set_error_message(context, KRB5_RC_IO_UNKNOWN,
+ "Can't destroy replay cache: %s",
+ strerror(errno));
+ return KRB5_RC_IO_UNKNOWN;
+ }
return 0;
}
struct stat statb;
if (fstat(d->fd, &statb) == 0)
- return statb.st_size;
+ return statb.st_size;
else
- return 0;
+ return 0;
}
+/* -*- mode: c; indent-tabs-mode: nil -*- */
/*
* lib/krb5/rcache/rc_io.h
*
/* first argument is always iostuff for result file */
-krb5_error_code krb5_rc_io_creat
- (krb5_context,
- krb5_rc_iostuff *,
- char **);
-krb5_error_code krb5_rc_io_open
- (krb5_context,
- krb5_rc_iostuff *,
- char *);
-krb5_error_code krb5_rc_io_move
- (krb5_context,
- krb5_rc_iostuff *,
- krb5_rc_iostuff *);
-krb5_error_code krb5_rc_io_write
- (krb5_context,
- krb5_rc_iostuff *,
- krb5_pointer,
- unsigned int);
-krb5_error_code krb5_rc_io_read
- (krb5_context,
- krb5_rc_iostuff *,
- krb5_pointer,
- unsigned int);
-krb5_error_code krb5_rc_io_close
- (krb5_context,
- krb5_rc_iostuff *);
-krb5_error_code krb5_rc_io_destroy
- (krb5_context,
- krb5_rc_iostuff *);
-krb5_error_code krb5_rc_io_mark
- (krb5_context,
- krb5_rc_iostuff *);
-krb5_error_code krb5_rc_io_unmark
- (krb5_context,
- krb5_rc_iostuff *);
+krb5_error_code krb5_rc_io_creat
+ (krb5_context,
+ krb5_rc_iostuff *,
+ char **);
+krb5_error_code krb5_rc_io_open
+ (krb5_context,
+ krb5_rc_iostuff *,
+ char *);
+krb5_error_code krb5_rc_io_move
+ (krb5_context,
+ krb5_rc_iostuff *,
+ krb5_rc_iostuff *);
+krb5_error_code krb5_rc_io_write
+ (krb5_context,
+ krb5_rc_iostuff *,
+ krb5_pointer,
+ unsigned int);
+krb5_error_code krb5_rc_io_read
+ (krb5_context,
+ krb5_rc_iostuff *,
+ krb5_pointer,
+ unsigned int);
+krb5_error_code krb5_rc_io_close
+ (krb5_context,
+ krb5_rc_iostuff *);
+krb5_error_code krb5_rc_io_destroy
+ (krb5_context,
+ krb5_rc_iostuff *);
+krb5_error_code krb5_rc_io_mark
+ (krb5_context,
+ krb5_rc_iostuff *);
+krb5_error_code krb5_rc_io_unmark
+ (krb5_context,
+ krb5_rc_iostuff *);
krb5_error_code krb5_rc_io_sync
- (krb5_context,
- krb5_rc_iostuff *);
+ (krb5_context,
+ krb5_rc_iostuff *);
long krb5_rc_io_size
- (krb5_context,
- krb5_rc_iostuff *);
+ (krb5_context,
+ krb5_rc_iostuff *);
#endif
+/* -*- mode: c; indent-tabs-mode: nil -*- */
/*
* lib/krb5/rcache/rc_none.c
*
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
- *
+ *
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
- *
+ *
*
* replay cache no-op implementation
*/
{
return 0;
}
-#define krb5_rc_none_recover krb5_rc_none_noargs
-#define krb5_rc_none_destroy krb5_rc_none_noargs
-#define krb5_rc_none_close krb5_rc_none_noargs
-#define krb5_rc_none_expunge krb5_rc_none_noargs
+#define krb5_rc_none_recover krb5_rc_none_noargs
+#define krb5_rc_none_destroy krb5_rc_none_noargs
+#define krb5_rc_none_close krb5_rc_none_noargs
+#define krb5_rc_none_expunge krb5_rc_none_noargs
static krb5_error_code KRB5_CALLCONV
krb5_rc_none_store(krb5_context ctx, krb5_rcache rc, krb5_donot_replay *r)
+/* -*- mode: c; indent-tabs-mode: nil -*- */
/*
* lib/krb5/rcache/rcdef.c
*
#include "rc_dfl.h"
const krb5_rc_ops krb5_rc_dfl_ops =
- {
- 0,
- "dfl",
- krb5_rc_dfl_init,
- krb5_rc_dfl_recover,
- krb5_rc_dfl_recover_or_init,
- krb5_rc_dfl_destroy,
- krb5_rc_dfl_close,
- krb5_rc_dfl_store,
- krb5_rc_dfl_expunge,
- krb5_rc_dfl_get_span,
- krb5_rc_dfl_get_name,
- krb5_rc_dfl_resolve
- }
-;
+{
+ 0,
+ "dfl",
+ krb5_rc_dfl_init,
+ krb5_rc_dfl_recover,
+ krb5_rc_dfl_recover_or_init,
+ krb5_rc_dfl_destroy,
+ krb5_rc_dfl_close,
+ krb5_rc_dfl_store,
+ krb5_rc_dfl_expunge,
+ krb5_rc_dfl_get_span,
+ krb5_rc_dfl_get_name,
+ krb5_rc_dfl_resolve
+};
+/* -*- mode: c; indent-tabs-mode: nil -*- */
/*
* lib/krb5/rcache/rcfns.c
*
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
- *
+ *
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
krb5_error_code KRB5_CALLCONV
krb5_rc_recover_or_initialize (krb5_context context, krb5_rcache id,
- krb5_deltat span)
+ krb5_deltat span)
{
return krb5_x(id->ops->recover_or_init,(context, id, span));
}
krb5_error_code KRB5_CALLCONV
krb5_rc_store (krb5_context context, krb5_rcache id,
- krb5_donot_replay *dontreplay)
+ krb5_donot_replay *dontreplay)
{
return krb5_x((id)->ops->store,(context, id, dontreplay));
}
krb5_error_code KRB5_CALLCONV
krb5_rc_get_lifespan (krb5_context context, krb5_rcache id,
- krb5_deltat *spanp)
+ krb5_deltat *spanp)
{
return krb5_x((id)->ops->get_span,(context, id, spanp));
}
+/* -*- mode: c; indent-tabs-mode: nil -*- */
/*
* lib/krb5/rcache/ser_rc.c
*
/*
* Routines to deal with externalizing krb5_rcache.
- * krb5_rcache_size();
- * krb5_rcache_externalize();
- * krb5_rcache_internalize();
+ * krb5_rcache_size();
+ * krb5_rcache_externalize();
+ * krb5_rcache_internalize();
*/
static krb5_error_code krb5_rcache_size
- (krb5_context, krb5_pointer, size_t *);
+ (krb5_context, krb5_pointer, size_t *);
static krb5_error_code krb5_rcache_externalize
- (krb5_context, krb5_pointer, krb5_octet **, size_t *);
+ (krb5_context, krb5_pointer, krb5_octet **, size_t *);
static krb5_error_code krb5_rcache_internalize
- (krb5_context,krb5_pointer *, krb5_octet **, size_t *);
+ (krb5_context,krb5_pointer *, krb5_octet **, size_t *);
/*
* Serialization entry for this type.
*/
static const krb5_ser_entry krb5_rcache_ser_entry = {
- KV5M_RCACHE, /* Type */
- krb5_rcache_size, /* Sizer routine */
- krb5_rcache_externalize, /* Externalize routine */
- krb5_rcache_internalize /* Internalize routine */
+ KV5M_RCACHE, /* Type */
+ krb5_rcache_size, /* Sizer routine */
+ krb5_rcache_externalize, /* Externalize routine */
+ krb5_rcache_internalize /* Internalize routine */
};
\f
/*
- * krb5_rcache_size() - Determine the size required to externalize
- * this krb5_rcache variant.
+ * krb5_rcache_size() - Determine the size required to externalize
+ * this krb5_rcache variant.
*/
static krb5_error_code
krb5_rcache_size(krb5_context kcontext, krb5_pointer arg, size_t *sizep)
{
- krb5_error_code kret;
- krb5_rcache rcache;
- size_t required;
+ krb5_error_code kret;
+ krb5_rcache rcache;
+ size_t required;
kret = EINVAL;
if ((rcache = (krb5_rcache) arg)) {
- /*
- * Saving FILE: variants of krb5_rcache requires at minimum:
- * krb5_int32 for KV5M_RCACHE
- * krb5_int32 for length of rcache name.
- * krb5_int32 for KV5M_RCACHE
- */
- required = sizeof(krb5_int32) * 3;
- if (rcache->ops && rcache->ops->type)
- required += (strlen(rcache->ops->type)+1);
+ /*
+ * Saving FILE: variants of krb5_rcache requires at minimum:
+ * krb5_int32 for KV5M_RCACHE
+ * krb5_int32 for length of rcache name.
+ * krb5_int32 for KV5M_RCACHE
+ */
+ required = sizeof(krb5_int32) * 3;
+ if (rcache->ops && rcache->ops->type)
+ required += (strlen(rcache->ops->type)+1);
- /*
- * The rcache name is formed as follows:
- * <type>:<name>
- */
- required += strlen(krb5_rc_get_name(kcontext, rcache));
+ /*
+ * The rcache name is formed as follows:
+ * <type>:<name>
+ */
+ required += strlen(krb5_rc_get_name(kcontext, rcache));
- kret = 0;
- *sizep += required;
+ kret = 0;
+ *sizep += required;
}
return(kret);
}
\f
/*
- * krb5_rcache_externalize() - Externalize the krb5_rcache.
+ * krb5_rcache_externalize() - Externalize the krb5_rcache.
*/
static krb5_error_code
krb5_rcache_externalize(krb5_context kcontext, krb5_pointer arg, krb5_octet **buffer, size_t *lenremain)
{
- krb5_error_code kret;
- krb5_rcache rcache;
- size_t required;
- krb5_octet *bp;
- size_t remain;
- char *rcname;
- size_t namelen;
- char *fnamep;
+ krb5_error_code kret;
+ krb5_rcache rcache;
+ size_t required;
+ krb5_octet *bp;
+ size_t remain;
+ char *rcname;
+ size_t namelen;
+ char *fnamep;
required = 0;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
if ((rcache = (krb5_rcache) arg)) {
- kret = ENOMEM;
- if (!krb5_rcache_size(kcontext, arg, &required) &&
- (required <= remain)) {
- /* Our identifier */
- (void) krb5_ser_pack_int32(KV5M_RCACHE, &bp, &remain);
+ kret = ENOMEM;
+ if (!krb5_rcache_size(kcontext, arg, &required) &&
+ (required <= remain)) {
+ /* Our identifier */
+ (void) krb5_ser_pack_int32(KV5M_RCACHE, &bp, &remain);
- /* Calculate the length of the name */
- namelen = (rcache->ops && rcache->ops->type) ?
- strlen(rcache->ops->type)+1 : 0;
- fnamep = krb5_rc_get_name(kcontext, rcache);
- namelen += (strlen(fnamep)+1);
+ /* Calculate the length of the name */
+ namelen = (rcache->ops && rcache->ops->type) ?
+ strlen(rcache->ops->type)+1 : 0;
+ fnamep = krb5_rc_get_name(kcontext, rcache);
+ namelen += (strlen(fnamep)+1);
- if (rcache->ops && rcache->ops->type) {
- if (asprintf(&rcname, "%s:%s", rcache->ops->type, fnamep) < 0)
- rcname = NULL;
- } else
- rcname = strdup(fnamep);
+ if (rcache->ops && rcache->ops->type) {
+ if (asprintf(&rcname, "%s:%s", rcache->ops->type, fnamep) < 0)
+ rcname = NULL;
+ } else
+ rcname = strdup(fnamep);
- if (rcname) {
- /* Put the length of the file name */
- (void) krb5_ser_pack_int32((krb5_int32) strlen(rcname),
- &bp, &remain);
-
- /* Put the name */
- (void) krb5_ser_pack_bytes((krb5_octet *) rcname,
- strlen(rcname),
- &bp, &remain);
+ if (rcname) {
+ /* Put the length of the file name */
+ (void) krb5_ser_pack_int32((krb5_int32) strlen(rcname),
+ &bp, &remain);
- /* Put the trailer */
- (void) krb5_ser_pack_int32(KV5M_RCACHE, &bp, &remain);
- kret = 0;
- *buffer = bp;
- *lenremain = remain;
- free(rcname);
- }
- }
+ /* Put the name */
+ (void) krb5_ser_pack_bytes((krb5_octet *) rcname,
+ strlen(rcname),
+ &bp, &remain);
+
+ /* Put the trailer */
+ (void) krb5_ser_pack_int32(KV5M_RCACHE, &bp, &remain);
+ kret = 0;
+ *buffer = bp;
+ *lenremain = remain;
+ free(rcname);
+ }
+ }
}
return(kret);
}
\f
/*
- * krb5_rcache_internalize() - Internalize the krb5_rcache.
+ * krb5_rcache_internalize() - Internalize the krb5_rcache.
*/
static krb5_error_code
krb5_rcache_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain)
{
- krb5_error_code kret;
- krb5_rcache rcache;
- krb5_int32 ibuf;
- krb5_octet *bp;
- size_t remain;
- char *rcname;
+ krb5_error_code kret;
+ krb5_rcache rcache;
+ krb5_int32 ibuf;
+ krb5_octet *bp;
+ size_t remain;
+ char *rcname;
bp = *buffer;
remain = *lenremain;
kret = EINVAL;
/* Read our magic number */
if (krb5_ser_unpack_int32(&ibuf, &bp, &remain))
- ibuf = 0;
+ ibuf = 0;
if (ibuf == KV5M_RCACHE) {
- kret = ENOMEM;
+ kret = ENOMEM;
- /* Get the length of the rcache name */
- kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain);
+ /* Get the length of the rcache name */
+ kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain);
- if (!kret &&
- (rcname = (char *) malloc((size_t) (ibuf+1))) &&
- !(kret = krb5_ser_unpack_bytes((krb5_octet *) rcname,
- (size_t) ibuf,
- &bp, &remain))) {
- rcname[ibuf] = '\0';
- if (!(kret = krb5_rc_resolve_full(kcontext, &rcache, rcname))) {
- (void) krb5_rc_recover(kcontext, rcache);
- if (!kret &&
- !(kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)) &&
- (ibuf == KV5M_RCACHE)) {
- *buffer = bp;
- *lenremain = remain;
- *argp = (krb5_pointer) rcache;
- }
- else
- krb5_rc_close(kcontext, rcache);
- }
- free(rcname);
- }
+ if (!kret &&
+ (rcname = (char *) malloc((size_t) (ibuf+1))) &&
+ !(kret = krb5_ser_unpack_bytes((krb5_octet *) rcname,
+ (size_t) ibuf,
+ &bp, &remain))) {
+ rcname[ibuf] = '\0';
+ if (!(kret = krb5_rc_resolve_full(kcontext, &rcache, rcname))) {
+ (void) krb5_rc_recover(kcontext, rcache);
+ if (!kret &&
+ !(kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain)) &&
+ (ibuf == KV5M_RCACHE)) {
+ *buffer = bp;
+ *lenremain = remain;
+ *argp = (krb5_pointer) rcache;
+ }
+ else
+ krb5_rc_close(kcontext, rcache);
+ }
+ free(rcname);
+ }
}
return(kret);
}