From 19df0c089cb23f2206dba4152cac3e3072b5be4d Mon Sep 17 00:00:00 2001 From: John Kohl Date: Tue, 10 Jul 1990 09:55:01 +0000 Subject: Bring local mods onto trunk git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1042 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/rcache/rc_base.c | 89 ++++++++++++++++++++++++++----- src/lib/krb5/rcache/rc_base.h | 31 ++--------- src/lib/krb5/rcache/rc_dfl.c | 121 ++++++++++++++++++++++++------------------ src/lib/krb5/rcache/rc_dfl.h | 22 ++++---- src/lib/krb5/rcache/rc_io.c | 88 ++++++++++++++++-------------- src/lib/krb5/rcache/rc_io.h | 2 +- 6 files changed, 207 insertions(+), 146 deletions(-) (limited to 'src') diff --git a/src/lib/krb5/rcache/rc_base.c b/src/lib/krb5/rcache/rc_base.c index 93248710b5..199beee2ce 100644 --- a/src/lib/krb5/rcache/rc_base.c +++ b/src/lib/krb5/rcache/rc_base.c @@ -4,27 +4,27 @@ Copyright 1990, Daniel J. Bernstein. All rights reserved. Please address any questions or comments to the author at brnstnd@acf10.nyu.edu. */ -#include -#include -extern char *getenv(char *); /* ain't there an include file for this? */ #ifdef SEMAPHORE #include #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 @@ -36,7 +36,7 @@ krb5_error_code krb5_rc_register_type(struct krb5_rc_type *ops) 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 @@ -51,7 +51,9 @@ krb5_error_code krb5_rc_register_type(struct krb5_rc_type *ops) 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 @@ -63,18 +65,23 @@ krb5_error_code krb5_rc_resolve_type(krb5_RC *id,char *type) 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")) @@ -83,7 +90,11 @@ char *krb5_rc_default_type(void) return "dfl"; } +#ifdef __STDC__ char *krb5_rc_default_name(void) +#else +char *krb5_rc_default_name() +#endif { char *s; if (s = getenv("KRB5RCACHENAME")) @@ -91,3 +102,55 @@ char *krb5_rc_default_name(void) 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; +} + diff --git a/src/lib/krb5/rcache/rc_base.h b/src/lib/krb5/rcache/rc_base.h index 047b8163b6..f931450091 100644 --- a/src/lib/krb5/rcache/rc_base.h +++ b/src/lib/krb5/rcache/rc_base.h @@ -6,34 +6,9 @@ Please address any questions or comments to the author at brnstnd@acf10.nyu.edu. #ifndef KRB5_RC_H #define KRB5_RC_H -#include "krb5/krb5.h" +#include +#include -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 diff --git a/src/lib/krb5/rcache/rc_dfl.c b/src/lib/krb5/rcache/rc_dfl.c index 643ebd2dc6..3179bc9118 100644 --- a/src/lib/krb5/rcache/rc_dfl.c +++ b/src/lib/krb5/rcache/rc_dfl.c @@ -4,17 +4,11 @@ Copyright 1990, Daniel J. Bernstein. All rights reserved. Please address any questions or comments to the author at brnstnd@acf10.nyu.edu. */ -#include -#include -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 /* If NOIOSTUFF is defined at compile time, dfl rcaches will be per-process. @@ -41,7 +35,7 @@ struct dfl_data 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 */ @@ -69,21 +63,28 @@ struct auth_replay } ; -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; } @@ -92,7 +93,11 @@ static int auth_to_rep(krb5_tkt_authent *auth,struct auth_replay *rep) #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) && @@ -102,7 +107,9 @@ static int cmp(struct auth_replay *old,struct auth_replay *new,krb5_deltat t) 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; @@ -139,9 +146,11 @@ struct authlist /* 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; @@ -158,7 +167,7 @@ static int store(krb5_RC id,struct auth_replay *rep) break; default: ; /* wtf? */ } - + if (!(ta = (struct authlist *) malloc(sizeof(struct authlist)))) return CMP_MALLOC; ta->na = t->a; t->a = ta; @@ -168,20 +177,25 @@ static int store(krb5_RC id,struct auth_replay *rep) 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; @@ -201,9 +215,10 @@ krb5_error_code krb5_rc_dfl_init(krb5_RC id,krb5_deltat 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); @@ -221,7 +236,8 @@ krb5_error_code krb5_rc_dfl_close(krb5_RC id) 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)) @@ -230,25 +246,28 @@ krb5_error_code krb5_rc_dfl_destroy(krb5_RC id) 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; @@ -319,20 +338,25 @@ would be inefficient. */ #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? */ ; } @@ -358,9 +382,10 @@ krb5_error_code krb5_rc_dfl_store(krb5_RC id,krb5_tkt_authent *auth) 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; @@ -392,8 +417,13 @@ krb5_error_code krb5_rc_dfl_expunge(krb5_RC id) #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; @@ -426,18 +456,3 @@ krb5_error_code krb5_rc_dfl_expunge(krb5_RC id) #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 - } -; diff --git a/src/lib/krb5/rcache/rc_dfl.h b/src/lib/krb5/rcache/rc_dfl.h index 0d230e3aa7..6c08a256f3 100644 --- a/src/lib/krb5/rcache/rc_dfl.h +++ b/src/lib/krb5/rcache/rc_dfl.h @@ -6,19 +6,17 @@ Please address any questions or comments to the author at brnstnd@acf10.nyu.edu. #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 diff --git a/src/lib/krb5/rcache/rc_io.c b/src/lib/krb5/rcache/rc_io.c index f6ea4798b3..32829f4221 100644 --- a/src/lib/krb5/rcache/rc_io.c +++ b/src/lib/krb5/rcache/rc_io.c @@ -4,38 +4,27 @@ Copyright 1990, Daniel J. Bernstein. All rights reserved. Please address any questions or comments to the author at brnstnd@acf10.nyu.edu. */ -#include -#include -#ifdef BSD -#include -#endif -#include #include /* for P_tmpdir */ -#include -#include -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 +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() { @@ -43,8 +32,8 @@ 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 @@ -52,7 +41,9 @@ static void getdir() } } -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; @@ -64,19 +55,21 @@ krb5_error_code krb5_rc_io_creat PROTOTYPE((krb5_rc_iostuff *d,char **fn)) (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') { @@ -108,7 +101,9 @@ krb5_error_code krb5_rc_io_creat PROTOTYPE((krb5_rc_iostuff *d,char **fn)) 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))) @@ -133,7 +128,9 @@ krb5_error_code krb5_rc_io_open PROTOTYPE((krb5_rc_iostuff *d,char *fn)) 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; @@ -143,7 +140,10 @@ krb5_error_code krb5_rc_io_move PROTOTYPE((krb5_rc_iostuff *new,krb5_rc_iostuff 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) @@ -165,19 +165,26 @@ krb5_error_code krb5_rc_io_write PROTOTYPE((krb5_rc_iostuff *d,krb5_pointer buf, 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 */ @@ -185,7 +192,8 @@ krb5_error_code krb5_rc_io_close PROTOTYPE((krb5_rc_iostuff *d)) 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) @@ -200,13 +208,15 @@ krb5_error_code krb5_rc_io_destroy PROTOTYPE((krb5_rc_iostuff *d)) 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; diff --git a/src/lib/krb5/rcache/rc_io.h b/src/lib/krb5/rcache/rc_io.h index 82d3be8b3d..b47480613c 100644 --- a/src/lib/krb5/rcache/rc_io.h +++ b/src/lib/krb5/rcache/rc_io.h @@ -6,7 +6,7 @@ Please address any questions or comments to the author at brnstnd@acf10.nyu.edu. #ifndef KRB5_RC_IO_H #define KRB5_RC_IO_H -#include "krb5/krb5.h" +#include typedef struct krb5_rc_iostuff { -- cgit