From b197402ea22010295d9242d6950b2edb6b9e1899 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Fri, 18 Jul 2008 03:08:38 +0000 Subject: [PATCH] Revert due to potential file modes race condition ticket: 6002 status: open git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20538 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/rcache/rc_io.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/lib/krb5/rcache/rc_io.c b/src/lib/krb5/rcache/rc_io.c index 84c83382f..59d15c2fa 100644 --- a/src/lib/krb5/rcache/rc_io.c +++ b/src/lib/krb5/rcache/rc_io.c @@ -68,6 +68,7 @@ getdir(void) krb5_error_code krb5_rc_io_creat(krb5_context context, krb5_rc_iostuff *d, char **fn) { + char *c; krb5_int16 rc_vno = htons(KRB5_RC_VNO); krb5_error_code retval = 0; int do_not_unlink = 0; @@ -85,29 +86,24 @@ krb5_rc_io_creat(krb5_context context, krb5_rc_iostuff *d, char **fn) d->fd = THREEPARAMOPEN(d->fn, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL | O_BINARY, 0600); } else { - if (asprintf(&d->fn, "%s%skrb5_RCXXXXXX", - dir, PATH_SEPARATOR) < 0) { + if (asprintf(&d->fn, "%s%skrb5_RC%daaa", + dir, PATH_SEPARATOR, (int) UNIQUE) < 0) { d->fn = NULL; return KRB5_RC_IO_MALLOC; } - d->fd = mkstemp(d->fn); - if (d->fd != -1) { -#if defined(HAVE_FCHMOD) || defined(HAVE_CHMOD) -#ifdef HAVE_FCHMOD - retval = fchmod(d->fd, 0600); -#else - retval = chmod(d->fn, 0600); -#endif - if (retval == -1) { - retval = KRB5_RC_IO_UNKNOWN; - krb5_set_error_message(context, retval, - "Cannot chmod replay cache file %s: %s", - d->fn, strerror(errno)); - goto cleanup; + c = d->fn + strlen(d->fn) - 3; + while ((d->fd = THREEPARAMOPEN(d->fn, O_WRONLY | O_CREAT | O_TRUNC | + O_EXCL | O_BINARY, 0600)) == -1) { + if ((c[2]++) == 'z') { + c[2] = 'a'; + if ((c[1]++) == 'z') { + c[1] = 'a'; + if ((c[0]++) == 'z') + break; /* sigh */ + } } -#endif } - if (retval != 0 && d->fd != -1 && fn) { + if (fn) { *fn = strdup(d->fn + dirlen); if (*fn == NULL) { free(d->fn); -- 2.26.2