/*
*/
/*
*
* This file of the Kerberos V5 software is derived from public-domain code
* contributed by Daniel J. Bernstein, <brnstnd@acf10.nyu.edu>.
*
*/
/*
* I/O functions for the replay cache default implementation.
*/
#if defined(_WIN32)
#else
#endif
#include "k5-int.h"
#include <stdio.h> /* for P_tmpdir */
#include <unistd.h>
#include <syslog.h> /* SUNW */
#include <locale.h> /* Solaris Kerberos */
#include "rc_base.h"
#include "rc_file.h"
#include "rc_io.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif
#ifdef HAVE_NETINET_IN_H
#if !defined(_WINSOCKAPI_)
#endif
#else
#endif
/* Solaris Kerberos */
static char *
getdir(void)
{
char *dir;
#if defined(_WIN32)
dir = "C:";
#else
/* Solaris Kerberos */
if (geteuid() == 0)
else
#endif
return dir;
}
{
char *c;
int do_not_unlink = 0;
char *dir;
{
/* Solaris Kerberos */
if (*fn[0] == '/') {
return (KRB5_RC_IO_MALLOC);
} else {
return KRB5_RC_IO_MALLOC;
}
O_BINARY, 0600);
}
else
{
/* %d is max 11 digits (-, 10 digits of 32-bit number)
* 11 + /krb5_RC + aaa = 24, +6 for slop */
return KRB5_RC_IO_MALLOC;
if (fn)
return KRB5_RC_IO_MALLOC;
}
(int) UNIQUE);
(void) strcpy(c, "aaa");
{
if ((c[2]++) == 'z')
{
c[2] = 'a';
if ((c[1]++) == 'z')
{
c[1] = 'a';
if ((c[0]++) == 'z')
break; /* sigh */
}
}
}
if (fn)
}
if (d->fd == -1)
{
switch(errno)
{
case EFBIG:
#ifdef EDQUOT
case EDQUOT:
#endif
case ENOSPC:
goto cleanup;
case EIO:
goto cleanup;
case EPERM:
case EACCES:
case EROFS:
case EEXIST:
"Cannot create replay cache %s: %s"),
do_not_unlink = 1;
goto cleanup;
default:
"Cannot create replay cache %s: %s"),
goto cleanup;
}
}
sizeof(rc_vno));
if (retval)
goto cleanup;
if (retval) {
if (d->fn) {
if (!do_not_unlink)
}
if (d->fd != -1) {
}
}
return retval;
}
static krb5_error_code
char* full_pathname)
{
int use_errno = 0;
char *dir;
if (fn[0] == '/') {
return (KRB5_RC_IO_MALLOC);
} else {
return KRB5_RC_IO_MALLOC;
}
/* Solaris: BEGIN made changes to be safer and better code structure */
use_errno = 1;
goto cleanup;
}
do_not_unlink = 0;
#ifndef NO_USERID
/* must be owned by this user, to prevent some security problems with
* other users modifying replay cache stuff and must be a regular file
*/
goto cleanup;
}
#else
/* make sure the rcache is a regular file */
goto cleanup;
}
#endif
/* Make sure fstat() and lstat() have accessed the same file */
goto cleanup;
}
/* if we accessed the rcache via a symlink, bail out */
"and should be removed.\n", d->fn);
goto cleanup;
}
}
else {
use_errno = 1;
goto cleanup;
}
}
else {
use_errno = 1;
goto cleanup;
}
do_not_unlink = 0;
sizeof(rc_vno));
if (retval)
goto cleanup;
if (use_errno) {
switch(errno)
{
case EFBIG:
#ifdef EDQUOT
case EDQUOT:
#endif
case ENOSPC:
break;
case EIO:
break;
case EPERM:
case EACCES:
case EROFS:
"Cannot open replay cache %s: %s"),
break;
default:
"Cannot open replay cache %s: %s"),
}
}
/* Solaris: END made changes to be safer and better code structure */
if (retval) {
if (d->fn) {
if (!do_not_unlink)
}
if (d->fd >= 0)
}
return retval;
}
{
}
{
#if defined(_WIN32) || defined(__CYGWIN__)
/*
* Initial work around provided by Tom Sanfilippo to work around
* poor Windows emulation of POSIX functions. Rename and dup has
* different semantics!
*
* Additional fixes and explanation provided by dalmeida@mit.edu:
*
* First, we save the offset of "old". Then, we close and remove
* the "new" file so we can do the rename. We also close "old" to
* make sure the rename succeeds (though that might not be
* necessary on some systems).
*
* Next, we do the rename. If all goes well, we seek the "new"
* file to the position "old" was at.
*
* --- WARNING!!! ---
*
* Since "old" is now gone, we mourn its disappearance, but we
* cannot emulate that Unix behavior... THIS BEHAVIOR IS
* DIFFERENT FROM UNIX. However, it is ok because this function
* gets called such that "old" gets closed right afterwards.
*/
goto cleanup;
}
if (retval)
goto cleanup;
goto cleanup;
}
return retval;
#else
return KRB5_RC_IO_UNKNOWN;
return 0;
#endif
}
unsigned int num)
{
switch(errno)
{
#ifdef EDQUOT
case EDQUOT:
#endif
case EFBIG:
case ENOSPC:
"Can't write to replay cache %s: %s"),
return KRB5_RC_IO_SPACE;
case EIO:
"Can't write to replay cache %s: %s"),
return KRB5_RC_IO_IO;
case EBADF:
default:
"Can't write to replay cache %s: %s"),
return KRB5_RC_IO_UNKNOWN;
}
return 0;
}
{
#if defined(_WIN32)
#ifndef fsync
#endif
#endif
switch(errno)
{
case EBADF: return KRB5_RC_IO_UNKNOWN;
case EIO: return KRB5_RC_IO_IO;
default:
"Cannot sync replay cache file %s: %s"),
return KRB5_RC_IO_UNKNOWN;
}
}
return 0;
}
/*ARGSUSED*/
unsigned int num)
{
int count;
switch(errno)
{
case EIO: return KRB5_RC_IO_IO;
case EBADF:
default:
"Can't read from replay cache %s: %s"),
return KRB5_RC_IO_UNKNOWN;
}
if (count == 0)
return KRB5_RC_IO_EOF;
return 0;
}
/*ARGSUSED*/
{
}
if (d->fd != -1) {
return KRB5_RC_IO_UNKNOWN;
d->fd = -1;
}
return 0;
}
/*ARGSUSED*/
{
switch(errno)
{
case EIO:
"Can't destroy replay cache %s: %s"),
return KRB5_RC_IO_IO;
case EPERM:
case EBUSY:
case EROFS:
"Can't destroy replay cache %s: %s"),
return KRB5_RC_IO_PERM;
case EBADF:
default:
"Can't destroy replay cache %s: %s"),
return KRB5_RC_IO_UNKNOWN;
}
return 0;
}
/*ARGSUSED*/
{
return 0;
}
/*ARGSUSED*/
{
return 0;
}
/*ARGSUSED*/
long
{
else
return 0;
}