rc_io.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* 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.
*/
# define PATH_SEPARATOR "\\"
#else
# define PATH_SEPARATOR "/"
#endif
#define NEED_SOCKETS
#define NEED_LOWLEVEL_IO
#include <krb5.h>
#include <unistd.h>
#include <syslog.h> /* SUNW */
#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_) && !defined(HAVE_MACSOCK_H)
#endif
#else
#endif
#ifndef HAVE_ERRNO
#endif
static int dirlen = 0;
static char *dir;
/* The do ... while(0) is required to insure that GETDIR looks like a
single statement in all situations (just {}'s may cause troubles in
static int false = 0;
static void
getdir(void)
{
dir = "C:\\";
#else
if (geteuid() == 0)
else
#endif
}
krb5_rc_iostuff *d;
char **fn;
{
char *c;
{
if (*fn[0] == '/') {
return (KRB5_RC_IO_MALLOC);
} else {
return KRB5_RC_IO_MALLOC;
}
}
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)
(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 fail;
case EIO:
case EPERM:
case EACCES:
case EROFS:
case EEXIST:
default:
}
}
{
fail:
return retval;
}
return 0;
}
krb5_rc_iostuff *d;
char *fn;
{
krb5_error_code retval = 0;
int do_not_unlink = 1;
int use_errno = 0;
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;
}
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:
break;
default:
}
}
/* Solaris: END made changes to be safer and better code structure */
if (retval) {
if (d->fn) {
if (!do_not_unlink) {
/* unlink in case there is a bogus RC. */
}
}
}
return retval;
}
{
/*
* Work around provided by Tom Sanfilippo to work around poor
* Windows emulation of POSIX functions. Rename and dup has
* different semantics!
*/
return KRB5_RC_IO_UNKNOWN;
return KRB5_RC_IO_MALLOC;
#else
return KRB5_RC_IO_UNKNOWN;
#ifdef macintosh
#else
#endif
#endif
return 0;
}
/*ARGSUSED*/
krb5_rc_iostuff *d;
int num;
{
switch(errno)
{
case EBADF: return KRB5_RC_IO_UNKNOWN;
case EFBIG: return KRB5_RC_IO_SPACE;
#ifdef EDQUOT
case EDQUOT: return KRB5_RC_IO_SPACE;
#endif
case ENOSPC: return KRB5_RC_IO_SPACE;
case EIO: return KRB5_RC_IO_IO;
default: return KRB5_RC_IO_UNKNOWN;
}
return 0;
}
/*ARGSUSED*/
krb5_rc_iostuff *d;
{
#if !defined(MSDOS_FILESYSTEM) && !defined(macintosh)
switch(errno)
{
case EBADF: return KRB5_RC_IO_UNKNOWN;
case EIO: return KRB5_RC_IO_IO;
default: return KRB5_RC_IO_UNKNOWN;
}
}
#endif
return 0;
}
/*ARGSUSED*/
krb5_rc_iostuff *d;
int num;
{
int count;
switch(errno)
{
case EBADF: return KRB5_RC_IO_UNKNOWN;
case EIO: return KRB5_RC_IO_IO;
default: return KRB5_RC_IO_UNKNOWN;
}
if (count == 0)
return KRB5_RC_IO_EOF;
return 0;
}
/*ARGSUSED*/
krb5_rc_iostuff *d;
{
return KRB5_RC_IO_UNKNOWN;
return 0;
}
/*ARGSUSED*/
krb5_rc_iostuff *d;
{
switch(errno)
{
case EBADF: return KRB5_RC_IO_UNKNOWN;
case EIO: return KRB5_RC_IO_IO;
case EPERM: return KRB5_RC_IO_PERM;
case EBUSY: return KRB5_RC_IO_PERM;
case EROFS: return KRB5_RC_IO_PERM;
default: return KRB5_RC_IO_UNKNOWN;
}
return 0;
}
/*ARGSUSED*/
krb5_rc_iostuff *d;
{
return 0;
}
/*ARGSUSED*/
krb5_rc_iostuff *d;
{
return 0;
}
/*ARGSUSED*/
long
krb5_rc_io_size (context, d)
krb5_rc_iostuff *d;
{
else
return 0;
}