Please address any questions or comments to the author at brnstnd@acf10.nyu.edu.
*/
-#include <string.h>
-#include <malloc.h>
-extern char *getenv(char *); /* ain't there an include file for this? */
#ifdef SEMAPHORE
#include <semaphore.h>
#endif
#include "rc_base.h"
-#include "rc_err.h"
-static struct krb5_rc_typelist
+#define FREE(x) ((void) free((char *) (x)))
+
+struct krb5_rc_typelist
{
- struct krb5_rc_type *ops;
+ krb5_rc_ops *ops;
struct krb5_rc_typelist *next;
- }
-*typehead = (struct krb5_rc_typelist *) 0;
+ };
+static struct krb5_rc_typelist krb5_rc_typelist_dfl = { &krb5_rc_dfl_ops, 0 };
+static struct krb5_rc_typelist *typehead = &krb5_rc_typelist_dfl;
#ifdef SEMAPHORE
semaphore ex_typelist = 1;
#endif
-krb5_error_code krb5_rc_register_type(struct krb5_rc_type *ops)
+krb5_error_code krb5_rc_register_type(ops)
+krb5_rc_ops *ops;
{
struct krb5_rc_typelist *t;
#ifdef SEMAPHORE
up(&ex_typelist);
#endif
if (t)
- return KRB5_RC_EXIST;
+ return KRB5_RC_TYPE_EXISTS;
if (!(t = (struct krb5_rc_typelist *) malloc(sizeof(struct krb5_rc_typelist))))
return KRB5_RC_MALLOC;
#ifdef SEMAPHORE
return 0;
}
-krb5_error_code krb5_rc_resolve_type(krb5_RC *id,char *type)
+krb5_error_code krb5_rc_resolve_type(id, type)
+krb5_rcache *id;
+char *type;
{
struct krb5_rc_typelist *t;
#ifdef SEMAPHORE
up(&ex_typelist);
#endif
if (!t)
- return KRB5_RC_NOTFOUND;
+ return KRB5_RC_TYPE_NOTFOUND;
/* allocate *id? nah */
(*id)->ops = t->ops;
return 0;
}
-char *krb5_rc_get_type(krb5_RC id)
+char *krb5_rc_get_type(id)
+krb5_rcache id;
{
return id->ops->type;
}
+#ifdef __STDC__
char *krb5_rc_default_type(void)
+#else
+char *krb5_rc_default_type()
+#endif
{
char *s;
if (s = getenv("KRB5RCACHETYPE"))
return "dfl";
}
+#ifdef __STDC__
char *krb5_rc_default_name(void)
+#else
+char *krb5_rc_default_name()
+#endif
{
char *s;
if (s = getenv("KRB5RCACHENAME"))
else
return (char *) 0;
}
+
+krb5_error_code
+krb5_rc_default(id)
+krb5_rcache *id;
+{
+ krb5_error_code retval;
+
+ if (!(*id = (krb5_rcache )malloc(sizeof(**id))))
+ return KRB5_RC_MALLOC;
+
+ if (retval = krb5_rc_resolve_type(id, krb5_rc_default_type())) {
+ FREE(*id);
+ return retval;
+ }
+ if (retval = krb5_rc_resolve(*id, krb5_rc_default_name()))
+ FREE(*id);
+ return retval;
+}
+
+
+krb5_error_code krb5_rc_resolve_full(id, string_name)
+krb5_rcache *id;
+char *string_name;
+{
+ char *type;
+ char *residual;
+ krb5_error_code retval;
+
+ if (!(residual = strchr(string_name,':')))
+ return KRB5_RC_PARSE;
+
+ if (!(type = malloc(residual - string_name + 1)))
+ return KRB5_RC_MALLOC;
+ (void) strncpy(type,string_name,residual - string_name);
+ type[residual - string_name] = '\0';
+
+ if (!(*id = (krb5_rcache) malloc(sizeof(**id)))) {
+ FREE(type);
+ return KRB5_RC_MALLOC;
+ }
+
+ if (retval = krb5_rc_resolve_type(id,type)) {
+ FREE(type);
+ FREE(*id);
+ return retval;
+ }
+ FREE(type);
+ if (retval = krb5_rc_resolve(*id,residual + 1))
+ FREE(*id);
+ return retval;
+}
+
#ifndef KRB5_RC_H
#define KRB5_RC_H
-#include "krb5/krb5.h"
+#include <krb5/krb5.h>
+#include <krb5/ext-proto.h>
-typedef struct krb5_inRC
- {
- struct krb5_rc_type *ops;
- void *data;
- }
-*krb5_RC;
-
-struct krb5_rc_type
- {
- char *type;
- krb5_error_code (*init)PROTOTYPE((krb5_RC,krb5_deltat)); /* i.e., create */
- krb5_error_code (*recover)PROTOTYPE((krb5_RC)); /* i.e., open */
- krb5_error_code (*destroy)PROTOTYPE((krb5_RC));
- krb5_error_code (*close)PROTOTYPE((krb5_RC));
- krb5_error_code (*store)PROTOTYPE((krb5_RC,krb5_tkt_authent *));
- krb5_error_code (*expunge)PROTOTYPE((krb5_RC));
- krb5_error_code (*get_span)PROTOTYPE((krb5_RC,krb5_deltat *));
- char *(*get_name)PROTOTYPE((krb5_RC));
- krb5_error_code (*resolve)PROTOTYPE((krb5_RC *,char *name));
- }
-;
-
-krb5_error_code krb5_rc_register_type PROTOTYPE((struct krb5_rc_type *ops));
-krb5_error_code krb5_rc_resolve_type PROTOTYPE((krb5_RC *id,char *type));
-char *krb5_rc_get_type PROTOTYPE((krb5_RC id));
-char *krb5_rc_default_type PROTOTYPE((void));
-char *krb5_rc_default_name PROTOTYPE((void));
+/* all the stuff that was here is now in rcache.h, included by krb5/krb5.h */
#endif
Please address any questions or comments to the author at brnstnd@acf10.nyu.edu.
*/
-#include <string.h>
-#include <malloc.h>
-extern int free(char *);
#define FREE(x) ((void) free((char *) (x)))
-#include "krb5/krb5.h"
-krb5_error_code krb5_timeofday PROTOTYPE((krb5_int32 *)); /* aargh */
#include "rc_base.h"
#include "rc_dfl.h"
#include "rc_io.h"
-#include "rc_err.h"
-#include "rc_io_err.h"
+#include <krb5/libos-proto.h>
/*
If NOIOSTUFF is defined at compile time, dfl rcaches will be per-process.
data stored in this cache type, namely "dfl"
struct authlist
multilinked list of reps
-static int store(krb5_RC id,struct auth_replay *rep)
+static int store(krb5_rcache id,struct auth_replay *rep)
store rep in cache id; return CMP_REPLAY if replay, else CMP_MALLOC/CMP_HOHUM
*/
}
;
-static int hash(struct auth_replay *rep,int hsize)
+static int hash(rep, hsize)
+struct auth_replay *rep;
+int hsize;
{
return (((rep->cmsec + rep->ctime + *rep->server + *rep->client)
% hsize) + hsize) % hsize;
/* We take this opportunity to once again complain about C's idiotic %. */
}
-static int auth_to_rep(krb5_tkt_authent *auth,struct auth_replay *rep)
+static krb5_error_code auth_to_rep(auth, rep)
+krb5_tkt_authent *auth;
+struct auth_replay *rep;
{
+ krb5_error_code retval;
rep->cmsec = auth->authenticator->cmsec;
rep->ctime = auth->authenticator->ctime;
- if (krb5_unparse_name(auth->ticket->server,&rep->server))
- return -1; /* shouldn't happen */
- if (krb5_unparse_name(auth->authenticator->client,&rep->client))
- return -1; /* shouldn't happen. */
+ if (retval = krb5_unparse_name(auth->ticket->server,&rep->server))
+ return retval; /* shouldn't happen */
+ if (retval = krb5_unparse_name(auth->authenticator->client,&rep->client)) {
+ FREE(rep->server);
+ return retval; /* shouldn't happen. */
+ }
return 0;
}
#define CMP_REPLAY -1
#define CMP_HOHUM 0
-static int cmp(struct auth_replay *old,struct auth_replay *new,krb5_deltat t)
+/*ARGSUSED*/
+static int cmp(old, new, t)
+struct auth_replay *old;
+struct auth_replay *new;
+krb5_deltat t;
{
if ((old->cmsec == new->cmsec) && /* most likely to distinguish */
(old->ctime == new->ctime) &&
return CMP_HOHUM;
}
-static int alive(struct auth_replay *new,krb5_deltat t)
+static int alive(new, t)
+struct auth_replay *new;
+krb5_deltat t;
{
krb5_int32 time;
/* of course, list is backwards from file */
/* hash could be forwards since we have to search on match, but naaaah */
-static int store(krb5_RC id,struct auth_replay *rep)
+static int store(id, rep)
+krb5_rcache id;
+struct auth_replay *rep;
{
- struct dfl_data *t = id->data;
+ struct dfl_data *t = (struct dfl_data *)id->data;
int rephash;
struct authlist *ta;
break;
default: ; /* wtf? */
}
-
+
if (!(ta = (struct authlist *) malloc(sizeof(struct authlist))))
return CMP_MALLOC;
ta->na = t->a; t->a = ta;
return CMP_HOHUM;
}
-char *krb5_rc_dfl_get_name(krb5_RC id)
+char *krb5_rc_dfl_get_name(id)
+krb5_rcache id;
{
return ((struct dfl_data *) (id->data))->name;
}
-krb5_error_code krb5_rc_dfl_get_span(krb5_RC id,krb5_deltat *lifespan)
+krb5_error_code krb5_rc_dfl_get_span(id, lifespan)
+krb5_rcache id;
+krb5_deltat *lifespan;
{
*lifespan = ((struct dfl_data *) (id->data))->lifespan;
return 0;
}
-krb5_error_code krb5_rc_dfl_init(krb5_RC id,krb5_deltat lifespan)
+krb5_error_code krb5_rc_dfl_init(id, lifespan)
+krb5_rcache id;
+krb5_deltat lifespan;
{
- struct dfl_data *t = id->data;
+ struct dfl_data *t = (struct dfl_data *)id->data;
int i;
t->lifespan = lifespan;
return 0;
}
-krb5_error_code krb5_rc_dfl_close(krb5_RC id)
+krb5_error_code krb5_rc_dfl_close(id)
+krb5_rcache id;
{
- struct dfl_data *t = id->data;
+ struct dfl_data *t = (struct dfl_data *)id->data;
struct authlist *q;
FREE(t->h);
return 0;
}
-krb5_error_code krb5_rc_dfl_destroy(krb5_RC id)
+krb5_error_code krb5_rc_dfl_destroy(id)
+krb5_rcache id;
{
#ifndef NOIOSTUFF
if (krb5_rc_io_destroy(&((struct dfl_data *) (id->data))->d))
return krb5_rc_dfl_close(id);
}
-krb5_error_code krb5_rc_dfl_resolve(krb5_RC *id,char *name)
+krb5_error_code krb5_rc_dfl_resolve(id, name)
+krb5_rcache id;
+char *name;
{
struct dfl_data *t;
/* allocate id? no */
if (!(t = (struct dfl_data *) malloc(sizeof(struct dfl_data))))
return KRB5_RC_MALLOC;
- (*id)->data = t;
+ id->data = (krb5_pointer) t;
t->name = name; /* gee, difficult... */
return 0;
}
-krb5_error_code krb5_rc_dfl_recover(krb5_RC id)
+krb5_error_code krb5_rc_dfl_recover(id)
+krb5_rcache id;
{
#ifdef NOIOSTUFF
return KRB5_RC_NOIO;
#else
- struct dfl_data *t = id->data;
+ struct dfl_data *t = (struct dfl_data *)id->data;
int i;
struct auth_replay *rep;
#endif
}
-krb5_error_code krb5_rc_dfl_store(krb5_RC id,krb5_tkt_authent *auth)
+krb5_error_code krb5_rc_dfl_store(id, auth)
+krb5_rcache id;
+krb5_tkt_authent *auth;
{
- struct dfl_data *t = id->data;
+ struct dfl_data *t = (struct dfl_data *)id->data;
struct auth_replay *rep;
int i;
+ krb5_error_code retval;
if (!(rep = (struct auth_replay *) malloc(sizeof(struct auth_replay))))
return KRB5_RC_MALLOC;
- if (auth_to_rep(auth,rep))
- { FREE(rep); return KRB5_RC_UNKNOWN; }
+ if (retval = auth_to_rep(auth,rep))
+ { FREE(rep); return retval; }
switch(store(id,rep))
{
- case CMP_MALLOC: FREE(rep); return KRB5_RC_MALLOC; break;
- case CMP_REPLAY: FREE(rep); return KRB5_RC_REPLAY; break;
+ case CMP_MALLOC: FREE(rep->client); FREE(rep->server); FREE(rep);
+ return KRB5_RC_MALLOC; break;
+ case CMP_REPLAY: FREE(rep->client); FREE(rep->server); FREE(rep);
+ return KRB5KRB_AP_ERR_REPEAT; break;
case 0: break;
default: /* wtf? */ ;
}
return 0;
}
-krb5_error_code krb5_rc_dfl_expunge(krb5_RC id)
+krb5_error_code krb5_rc_dfl_expunge(id)
+krb5_rcache id;
{
- struct dfl_data *t = id->data;
+ struct dfl_data *t = (struct dfl_data *)id->data;
int i;
#ifdef NOIOSTUFF
struct authlist **q;
#else
struct krb5_rc_iostuff tmp;
struct authlist *q;
+ char *name = t->name;
(void) krb5_rc_dfl_close(id);
+ switch(krb5_rc_dfl_resolve(id, name)) {
+ case KRB5_RC_MALLOC: return KRB5_RC_MALLOC;
+ default: ;
+ }
switch(krb5_rc_dfl_recover(id))
{
case KRB5_RC_MALLOC: return KRB5_RC_MALLOC;
#endif
return 0;
}
-
-struct krb5_rc_type krb5_rc_dfl_ops =
- {
- "dfl",
- krb5_rc_dfl_init,
- krb5_rc_dfl_recover,
- 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
- }
-;
#ifndef KRB5_RC_DFL_H
#define KRB5_RC_DFL_H
-#include "krb5/krb5.h"
-#include "rc_base.h"
-struct krb5_rc_type krb5_rc_dfl_ops; /* initialized to the following */
+krb5_rc_ops krb5_rc_dfl_ops; /* initialized to the following */
-krb5_error_code krb5_rc_dfl_init PROTOTYPE((krb5_RC,krb5_deltat));
-krb5_error_code krb5_rc_dfl_recover PROTOTYPE((krb5_RC));
-krb5_error_code krb5_rc_dfl_destroy PROTOTYPE((krb5_RC));
-krb5_error_code krb5_rc_dfl_close PROTOTYPE((krb5_RC));
-krb5_error_code krb5_rc_dfl_store PROTOTYPE((krb5_RC,krb5_tkt_authent *));
-krb5_error_code krb5_rc_dfl_expunge PROTOTYPE((krb5_RC));
-krb5_error_code krb5_rc_dfl_get_span PROTOTYPE((krb5_RC,krb5_deltat *));
-char *krb5_rc_dfl_get_name PROTOTYPE((krb5_RC));
-krb5_error_code krb5_rc_dfl_resolve PROTOTYPE((krb5_RC *,char *name));
+krb5_error_code krb5_rc_dfl_init PROTOTYPE((krb5_rcache,krb5_deltat));
+krb5_error_code krb5_rc_dfl_recover PROTOTYPE((krb5_rcache));
+krb5_error_code krb5_rc_dfl_destroy PROTOTYPE((krb5_rcache));
+krb5_error_code krb5_rc_dfl_close PROTOTYPE((krb5_rcache));
+krb5_error_code krb5_rc_dfl_store PROTOTYPE((krb5_rcache,krb5_tkt_authent *));
+krb5_error_code krb5_rc_dfl_expunge PROTOTYPE((krb5_rcache));
+krb5_error_code krb5_rc_dfl_get_span PROTOTYPE((krb5_rcache,krb5_deltat *));
+char *krb5_rc_dfl_get_name PROTOTYPE((krb5_rcache));
+krb5_error_code krb5_rc_dfl_resolve PROTOTYPE((krb5_rcache,char *));
#endif
Please address any questions or comments to the author at brnstnd@acf10.nyu.edu.
*/
-#include <sys/types.h>
-#include <sys/file.h>
-#ifdef BSD
-#include <limits.h>
-#endif
-#include <string.h>
#include <stdio.h> /* for P_tmpdir */
-#include <malloc.h>
-#include <errno.h>
-extern int errno; /* this should be in errno.h, but isn't on some systems */
-extern char *getenv(char *); /* ain't there an include file for this? */
-extern int open(char *,int,int);
-extern char *sprintf(char *,char *,...);
-extern int getpid(void);
-extern int rename(char *,char *);
-extern int free(char *);
-#define FREE(x) ((void) free((char *) (x)))
-extern int close(int);
-extern int unlink(char *);
-extern int lseek(int,int,int);
-extern int read(int,char *,int);
-extern int write(int,char *,int);
-extern int fsync(int);
+
+#include "rc_base.h"
+#include "rc_dfl.h"
+#include "rc_io.h"
#include "rc_io.h"
-#include "rc_io_err.h"
+#include <krb5/sysincl.h>
+extern int errno; /* this should be in errno.h, but isn't on some systems */
+
+#define FREE(x) ((void) free((char *) (x)))
#define UNIQUE getpid() /* hopefully unique number */
int dirlen = 0;
char *dir;
-#define GETDIR do { if (!dirlen) getdir(); } while(0); /* stupid C syntax */
+/* The do ... while(0) is required to insure that GETDIR looks like a
+ single statement in all situations (just {}'s may cause troubles in
+ certain situations, such as nested if/else clauses. */
+
+#define GETDIR do { if (!dirlen) getdir(); } while(0)
static void getdir()
{
{
if (!(dir = getenv("KRB5RCACHEDIR")))
if (!(dir = getenv("TMPDIR")))
-#ifdef P_tmpdir
- dir = P_tmpdir;
+#ifdef RCTMPDIR
+ dir = RCTMPDIR;
#else
dir = "/tmp";
#endif
}
}
-krb5_error_code krb5_rc_io_creat PROTOTYPE((krb5_rc_iostuff *d,char **fn))
+krb5_error_code krb5_rc_io_creat (d, fn)
+krb5_rc_iostuff *d;
+char **fn;
{
char *c;
(void) strcpy(d->fn,dir);
(void) strcat(d->fn,"/");
(void) strcat(d->fn,*fn);
- d->fd = open(d->fn,O_WRONLY | O_CREAT | O_TRUNC,0600);
+ d->fd = open(d->fn,O_WRONLY | O_CREAT | O_TRUNC | O_EXCL,0600);
}
else
{
+ /* %d is max 11 digits (-, 10 digits of 32-bit number)
+ 11 + /krb5_RC + aaa = 24, +6 for slop */
if (!(d->fn = malloc(30 + dirlen)))
return KRB5_RC_IO_MALLOC;
if (fn)
- if (!(*fn = malloc(30)))
+ if (!(*fn = malloc(35)))
{ FREE(d->fn); return KRB5_RC_IO_MALLOC; }
(void) sprintf(d->fn,"%s/krb5_RC%d",dir,UNIQUE);
c = d->fn + strlen(d->fn);
(void) strcpy(c,"aaa");
- while ((d->fd = open(d->fn,O_WRONLY | O_CREAT | O_TRUNC,0600)) == -1)
+ while ((d->fd = open(d->fn,O_WRONLY|O_CREAT|O_TRUNC|O_EXCL,0600)) == -1)
{
if ((c[2]++) == 'z')
{
return 0;
}
-krb5_error_code krb5_rc_io_open PROTOTYPE((krb5_rc_iostuff *d,char *fn))
+krb5_error_code krb5_rc_io_open (d, fn)
+krb5_rc_iostuff *d;
+char *fn;
{
GETDIR;
if (!(d->fn = malloc(strlen(fn) + dirlen + 1)))
return 0;
}
-krb5_error_code krb5_rc_io_move PROTOTYPE((krb5_rc_iostuff *new,krb5_rc_iostuff *old))
+krb5_error_code krb5_rc_io_move (new, old)
+krb5_rc_iostuff *new;
+krb5_rc_iostuff *old;
{
if (rename(old->fn,new->fn) == -1) /* MUST be atomic! */
return KRB5_RC_IO_UNKNOWN;
return 0;
}
-krb5_error_code krb5_rc_io_write PROTOTYPE((krb5_rc_iostuff *d,krb5_pointer buf,int num))
+krb5_error_code krb5_rc_io_write (d, buf, num)
+krb5_rc_iostuff *d;
+krb5_pointer buf;
+int num;
{
if (write(d->fd,(char *) buf,num) == -1)
switch(errno)
return 0;
}
-krb5_error_code krb5_rc_io_read PROTOTYPE((krb5_rc_iostuff *d,krb5_pointer buf,int num))
+krb5_error_code krb5_rc_io_read (d, buf, num)
+krb5_rc_iostuff *d;
+krb5_pointer buf;
+int num;
{
- if (read(d->fd,(char *) buf,num) == -1)
+ int count;
+ if ((count = read(d->fd,(char *) buf,num)) == -1)
switch(errno)
{
case EBADF: return KRB5_RC_IO_UNKNOWN; break;
case EIO: return KRB5_RC_IO_IO; break;
default: return KRB5_RC_IO_UNKNOWN; break;
}
+ if (count == 0)
+ return KRB5_RC_IO_EOF;
return 0;
}
-krb5_error_code krb5_rc_io_close PROTOTYPE((krb5_rc_iostuff *d))
+krb5_error_code krb5_rc_io_close (d)
+krb5_rc_iostuff *d;
{
FREE(d->fn);
if (close(d->fd) == -1) /* can't happen */
return 0;
}
-krb5_error_code krb5_rc_io_destroy PROTOTYPE((krb5_rc_iostuff *d))
+krb5_error_code krb5_rc_io_destroy (d)
+krb5_rc_iostuff *d;
{
if (unlink(d->fn) == -1)
switch(errno)
return 0;
}
-krb5_error_code krb5_rc_io_mark PROTOTYPE((krb5_rc_iostuff *d))
+krb5_error_code krb5_rc_io_mark (d)
+krb5_rc_iostuff *d;
{
d->mark = lseek(d->fd,0,L_INCR); /* can't fail */
return 0;
}
-krb5_error_code krb5_rc_io_unmark PROTOTYPE((krb5_rc_iostuff *d))
+krb5_error_code krb5_rc_io_unmark (d)
+krb5_rc_iostuff *d;
{
(void) lseek(d->fd,d->mark,L_SET); /* if it fails, tough luck */
return 0;
#ifndef KRB5_RC_IO_H
#define KRB5_RC_IO_H
-#include "krb5/krb5.h"
+#include <krb5/osconf.h>
typedef struct krb5_rc_iostuff
{