From 323be20b1464912ee495a6f17417611c364252fc Mon Sep 17 00:00:00 2001 From: Keith Vetter Date: Wed, 22 Mar 1995 05:12:02 +0000 Subject: [PATCH] Bug fixes in ccache/file for the PC: files need to be opened in binary mode, unitialized variable and changed some clever code that depends upon 32 bit integers. Also, added hooks, ala k4, that notify the world when the cache changes. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5184 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/ccache/file/ChangeLog | 15 +++++++++ src/lib/krb5/ccache/file/fcc_destry.c | 45 +++++++++++++++++++++++++-- src/lib/krb5/ccache/file/fcc_gennew.c | 4 ++- src/lib/krb5/ccache/file/fcc_init.c | 3 +- src/lib/krb5/ccache/file/fcc_maybe.c | 2 +- src/lib/krb5/ccache/file/fcc_ops.c | 37 ++++++++++++++++++++-- src/lib/krb5/ccache/file/fcc_read.c | 7 ++++- src/lib/krb5/ccache/file/fcc_store.c | 1 + 8 files changed, 105 insertions(+), 9 deletions(-) diff --git a/src/lib/krb5/ccache/file/ChangeLog b/src/lib/krb5/ccache/file/ChangeLog index a370e33f4..990d3afb1 100644 --- a/src/lib/krb5/ccache/file/ChangeLog +++ b/src/lib/krb5/ccache/file/ChangeLog @@ -1,3 +1,18 @@ +Tue Mar 21 19:14:49 1995 Keith Vetter (keithv@fusion.com) + + * fcc_destroy.c: open file on the PC in binary mode, worked around + the unixism of working with deleted files. + * fcc_genn.c: open file on the PC in binary mode. + * fcc_init.c: uninitialized variable on the PC. + * fcc_maybe.c: open file on the PC in binary mode. + * fcc_read.c: a real clever one-line piece of code to turn 4 bytes + into a 32 bit integer fails miserbly on 16 bit machines. Fixed. + * fcc_ops.c: added hooks to notify programs when the ccache changes. + For windows, the code is taken from the K4 release, for other + platforms it does nothing. + * fcc_destroy.c, fcc_genn.c, fcc_init.c, fcc_store.c: added calls to + the hook described for fcc_ops.c. + Fri Mar 17 19:23:09 1995 John Gilmore (gnu at toad.com) * Makefile.in (LDFLAGS): Eliminate, duplicates config/pre.in. diff --git a/src/lib/krb5/ccache/file/fcc_destry.c b/src/lib/krb5/ccache/file/fcc_destry.c index f4a92f0ed..290f93aba 100644 --- a/src/lib/krb5/ccache/file/fcc_destry.c +++ b/src/lib/krb5/ccache/file/fcc_destry.c @@ -48,7 +48,7 @@ krb5_fcc_destroy(context, id) if (OPENCLOSE(id)) { - ret = open(((krb5_fcc_data *) id->data)->filename, O_RDWR, 0); + ret = open(((krb5_fcc_data *) id->data)->filename, O_RDWR | O_BINARY, 0); if (ret < 0) { kret = krb5_fcc_interpret(context, errno); goto cleanup; @@ -58,6 +58,45 @@ krb5_fcc_destroy(context, id) else lseek(((krb5_fcc_data *) id->data)->fd, 0, SEEK_SET); +#ifdef MSDOS_FILESYSTEM +/* "disgusting bit of UNIX trivia" - that's how the writers of NFS describe +** the ability of UNIX to still write to a file which has been unlinked. +** Naturally, the PC can't do this. As a result, we have to delete the file +** after we wipe it clean but that throws off all the error handling code. +** So we have do the work ourselves. +*/ + ret = fstat(((krb5_fcc_data *) id->data)->fd, &buf); + if (ret == -1) { + kret = krb5_fcc_interpret(context, errno); + size = 0; /* Nothing to wipe clean */ + } else + size = (unsigned long) buf.st_size; + + memset(zeros, 0, BUFSIZ); + while (size > 0) { + wlen = (int) ((size > BUFSIZ) ? BUFSIZ : size); /* How much to write */ + i = write(((krb5_fcc_data *) id->data)->fd, zeros, wlen); + if (i < 0) { + kret = krb5_fcc_interpret(context, errno); + /* Don't jump to cleanup--we still want to delete the file. */ + break; + } + size -= i; /* We've read this much */ + } + + ret = unlink(((krb5_fcc_data *) id->data)->filename); + if (ret < 0) { + kret = krb5_fcc_interpret(context, errno); + if (OPENCLOSE(id)) { + (void) close(((krb5_fcc_data *)id->data)->fd); + ((krb5_fcc_data *) id->data)->fd = -1; + kret = ret; + } + goto cleanup; + } + +#else /* MSDOS_FILESYSTEM */ + ret = unlink(((krb5_fcc_data *) id->data)->filename); if (ret < 0) { kret = krb5_fcc_interpret(context, errno); @@ -81,7 +120,6 @@ krb5_fcc_destroy(context, id) /* XXX This may not be legal XXX */ size = (unsigned long) buf.st_size; - memset(zeros, 0, BUFSIZ); for (i=0; i < size / BUFSIZ; i++) if (write(((krb5_fcc_data *) id->data)->fd, zeros, BUFSIZ) < 0) { @@ -109,10 +147,13 @@ krb5_fcc_destroy(context, id) if (ret) kret = krb5_fcc_interpret(context, errno); +#endif /* MSDOS_FILESYSTEM */ + cleanup: krb5_xfree(((krb5_fcc_data *) id->data)->filename); krb5_xfree(id->data); krb5_xfree(id); + krb5_change_cache (); return kret; } diff --git a/src/lib/krb5/ccache/file/fcc_gennew.c b/src/lib/krb5/ccache/file/fcc_gennew.c index d299903c7..f3d0cf3c8 100644 --- a/src/lib/krb5/ccache/file/fcc_gennew.c +++ b/src/lib/krb5/ccache/file/fcc_gennew.c @@ -101,7 +101,7 @@ krb5_fcc_generate_new (context, id) /* Make sure the file name is reserved */ ret = open(((krb5_fcc_data *) lid->data)->filename, - O_CREAT | O_EXCL | O_WRONLY, 0); + O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0); if (ret == -1) { retcode = krb5_fcc_interpret(context, errno); goto err_out; @@ -133,6 +133,8 @@ krb5_fcc_generate_new (context, id) } *id = lid; + + krb5_change_cache (); return KRB5_OK; } diff --git a/src/lib/krb5/ccache/file/fcc_init.c b/src/lib/krb5/ccache/file/fcc_init.c index 4411ebcb8..c8e4dce37 100644 --- a/src/lib/krb5/ccache/file/fcc_init.c +++ b/src/lib/krb5/ccache/file/fcc_init.c @@ -47,7 +47,7 @@ krb5_fcc_initialize(context, id, princ) krb5_principal princ; { krb5_error_code kret = 0; - int reti; + int reti = 0; MAYBE_OPEN(context, id, FCC_OPEN_AND_ERASE); @@ -66,6 +66,7 @@ krb5_fcc_initialize(context, id, princ) krb5_fcc_store_principal(context, id, princ); MAYBE_CLOSE(context, id, kret); + krb5_change_cache (); return kret; } diff --git a/src/lib/krb5/ccache/file/fcc_maybe.c b/src/lib/krb5/ccache/file/fcc_maybe.c index f0e316f4e..43579aafe 100644 --- a/src/lib/krb5/ccache/file/fcc_maybe.c +++ b/src/lib/krb5/ccache/file/fcc_maybe.c @@ -236,7 +236,7 @@ krb5_fcc_open_file (context, id, mode) break; } - fd = open (data->filename, open_flag, 0600); + fd = open (data->filename, open_flag | O_BINARY, 0600); if (fd == -1) return krb5_fcc_interpret (context, errno); diff --git a/src/lib/krb5/ccache/file/fcc_ops.c b/src/lib/krb5/ccache/file/fcc_ops.c index 12f26e698..6c577b820 100644 --- a/src/lib/krb5/ccache/file/fcc_ops.c +++ b/src/lib/krb5/ccache/file/fcc_ops.c @@ -24,8 +24,7 @@ * This file contains the structure krb5_fcc_ops. */ - - +#define NEED_WINDOWS #include "fcc.h" krb5_cc_ops krb5_fcc_ops = { @@ -47,10 +46,42 @@ krb5_cc_ops krb5_fcc_ops = { krb5_fcc_set_flags, }; +#ifdef _WINDOWS + +/* + * krb5_change_cache should be called after the cache changes. + * A notification message is is posted out to all top level + * windows so that they may recheck the cache based on the + * changes made. We register a unique message type with which + * we'll communicate to all other processes. + */ + +void +krb5_change_cache (int send) { + + SendMessage(HWND_BROADCAST, krb5_get_notification_message(), 0, 0); +} +unsigned int INTERFACE +krb5_get_notification_message (void) { + static unsigned int message = 0; - + if (message == 0) + message = RegisterWindowMessage(WM_KERBEROS5_CHANGED); + return message; +} +#else /* _WINDOWS */ +void INTERFACE +krb5_change_cache () +{ + return; +} +unsigned int INTERFACE +krb5_get_notification_message () { + return 0; +} +#endif /* _WINDOWS */ diff --git a/src/lib/krb5/ccache/file/fcc_read.c b/src/lib/krb5/ccache/file/fcc_read.c index bf4c871f0..ae8052c06 100644 --- a/src/lib/krb5/ccache/file/fcc_read.c +++ b/src/lib/krb5/ccache/file/fcc_read.c @@ -325,6 +325,7 @@ krb5_fcc_read_int32(context, id, i) krb5_fcc_data *data = (krb5_fcc_data *)id->data; krb5_error_code retval; unsigned char buf[4]; + krb5_int32 val; if ((data->version == KRB5_FCC_FVNO_1) || (data->version == KRB5_FCC_FVNO_2)) @@ -333,7 +334,11 @@ krb5_fcc_read_int32(context, id, i) retval = krb5_fcc_read(context, id, buf, 4); if (retval) return retval; - *i = (((((buf[0] << 8) + buf[1]) << 8 ) + buf[2]) << 8) + buf[3]; + val = buf[0]; + val = (val << 8) | buf[1]; + val = (val << 8) | buf[2]; + val = (val << 8) | buf[3]; + *i = val; return 0; } } diff --git a/src/lib/krb5/ccache/file/fcc_store.c b/src/lib/krb5/ccache/file/fcc_store.c index 12eef45bf..fec27aeb6 100644 --- a/src/lib/krb5/ccache/file/fcc_store.c +++ b/src/lib/krb5/ccache/file/fcc_store.c @@ -82,6 +82,7 @@ krb5_fcc_store(context, id, creds) lose: MAYBE_CLOSE(context, id, ret); + krb5_change_cache (); return ret; #undef TCHECK } -- 2.26.2