/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
*
* 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
#if HAVE_SYS_STAT_H
#endif
#include "k5-int.h"
#include <stdio.h> /* for P_tmpdir */
/* Solaris Kerberos */
#include <locale.h>
#include <syslog.h>
#include "rc_base.h"
#include "rc_dfl.h"
#include "rc_io.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif
#ifdef HAVE_NETINET_IN_H
#if !defined(_WINSOCKAPI_)
#endif
#else
#endif
static char *
getdir(void)
{
char *dir;
/* Solaris Kerberos */
#if 0
#if defined(_WIN32)
dir = "C:";
#else
#ifdef RCTMPDIR
#else
dir = "/tmp";
#endif
}
#endif
}
#endif
if (geteuid() == 0)
else
return dir;
}
/*
* Called from krb5_rc_io_creat(); calls mkstemp() and does some
* sanity checking on the file modes in case some broken mkstemp()
* implementation creates the file with overly permissive modes. To
* avoid race conditions, do not fchmod() a file for which mkstemp set
* incorrect modes.
*/
static krb5_error_code
{
#if HAVE_SYS_STAT_H
#endif
dir, PATH_SEPARATOR) < 0) {
return KRB5_RC_IO_MALLOC;
}
if (d->fd == -1) {
/*
* This return value is deliberate because d->fd == -1 causes
* caller to go into errno interpretation code.
*/
return 0;
}
#if HAVE_SYS_STAT_H
/*
* Be paranoid and check that mkstemp made the file accessible
* only to the user.
*/
if (retval) {
/* Solaris Kerberos */
"Cannot fstat replay cache file %s: %s"),
return KRB5_RC_IO_UNKNOWN;
}
/* Solaris Kerberos */
"Insecure mkstemp() file mode "
"for replay cache file %s; "
"try running this program "
"with umask 077 "), d->fn);
return KRB5_RC_IO_UNKNOWN;
}
#endif
return 0;
}
#if 0
#endif
static krb5_error_code
const char *operation)
{
switch (e) {
case EFBIG:
#ifdef EDQUOT
case EDQUOT:
#endif
case ENOSPC:
return KRB5_RC_IO_SPACE;
case EIO:
return KRB5_RC_IO_IO;
case EPERM:
case EACCES:
case EROFS:
case EEXIST:
/* Solaris Kerberos */
"Cannot %s replay cache file %s: %s"),
return KRB5_RC_IO_PERM;
default:
/* Solaris Kerberos */
"Cannot %s replay cache: %s"),
return KRB5_RC_IO_UNKNOWN;
}
}
{
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 {
if (retval)
goto cleanup;
return KRB5_RC_IO_MALLOC;
}
}
}
if (d->fd == -1) {
if (retval == KRB5_RC_IO_PERM)
do_not_unlink = 1;
goto cleanup;
}
set_cloexec_fd(d->fd);
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)
{
#ifndef NO_USERID
#endif
char *dir;
if (full_pathname) {
return KRB5_RC_IO_MALLOC;
} else {
/* Solaris Kerberos */
if (fn[0] == '/') {
return KRB5_RC_IO_MALLOC;
} else {
return KRB5_RC_IO_MALLOC;
}
}
#ifdef NO_USERID
if (d->fd == -1) {
goto cleanup;
}
#else
d->fd = -1;
if (retval != 0) {
goto cleanup;
}
if (d->fd < 0) {
goto cleanup;
}
if (retval < 0) {
goto cleanup;
}
/* check if someone was playing with symlinks */
{
/* Solaris Kerberos */
"and should be removed.", d->fn);
"rcache not a file %s"), d->fn);
goto cleanup;
}
/* Solaris Kerberos */
"Insecure file mode "
"for replay cache file %s"), d->fn);
return KRB5_RC_IO_UNKNOWN;
}
/* owned by me */
/* Solaris Kerberos */
"rcache not owned by %d"),
(int)geteuid());
goto cleanup;
}
#endif
set_cloexec_fd(d->fd);
do_not_unlink = 0;
sizeof(rc_vno));
if (retval)
goto cleanup;
if (retval) {
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:
/* Solaris Kerberos */
"Can't write to replay cache %s: %s"),
return KRB5_RC_IO_SPACE;
case EIO:
/* Solaris Kerberos */
"Can't write to replay cache %s: %s"),
return KRB5_RC_IO_IO;
case EBADF:
default:
/* Solaris Kerberos */
"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:
/* Solaris Kerberos */
"Cannot sync replay cache file %s: %s"),
return KRB5_RC_IO_UNKNOWN;
}
}
return 0;
}
unsigned int num)
{
int count;
switch(errno)
{
case EIO: return KRB5_RC_IO_IO;
case EBADF:
default:
/* Solaris Kerberos */
"Can't read from replay cache %s: %s"),
return KRB5_RC_IO_UNKNOWN;
}
return KRB5_RC_IO_EOF;
return 0;
}
{
}
if (d->fd != -1) {
return KRB5_RC_IO_UNKNOWN;
d->fd = -1;
}
return 0;
}
{
switch(errno)
{
case EIO:
/* Solaris Kerberos */
"Can't destroy replay cache %s: %s"),
return KRB5_RC_IO_IO;
case EPERM:
case EBUSY:
case EROFS:
/* Solaris Kerberos */
"Can't destroy replay cache %s: %s"),
return KRB5_RC_IO_PERM;
case EBADF:
default:
/* Solaris Kerberos */
"Can't destroy replay cache %s: %s"),
return KRB5_RC_IO_UNKNOWN;
}
return 0;
}
{
return 0;
}
{
return 0;
}
long
{
else
return 0;
}