fcc_maybe.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* Copyright 1990, 1991 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
*
*/
#include <syslog.h> /* SUNW */
#define NEED_SOCKETS /* Only for ntohs, etc. */
#define NEED_LOWLEVEL_IO
#include <k5-int.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "fcc.h"
/* How long to block if flock fails with EAGAIN */
#define LOCK_RETRIES 100
#ifdef HAVE_NETINET_IN_H
#if !defined(_WINSOCKAPI_) && !defined(HAVE_MACSOCK_H)
#endif
#else
/*error find some way to use net-byte-order file version numbers.*/
#endif
{
int ret;
return KRB5_FCC_INTERNAL;
if (retval)
return retval;
else
}
static krb5_error_code
{
int error;
int fd;
int newfile = 0;
*ret_fd = -1;
/*
* SUNW
* If we are opening in NOUNLINK mode, we have to check that the
* existing file, if any, is not a symlink. If it is, we try to
* delete and re-create it.
*/
return (-1);
}
return (-1);
}
}
if (fd == -1) {
if (fd != -1) {
newfile = 1;
} else {
/* If the file got created after the open we must retry */
return (0);
}
/*
* We failed since the file existed with wrong permissions.
* Let's try to unlink it and if that succeeds retry.
*/
filename);
return (-1);
}
return (0);
}
}
/* If we still don't have a valid fd, we stop trying */
if (fd == -1)
return (-1);
/*
* SUNW
* If the file was not created now with a O_CREAT | O_EXCL open,
* we have opened an existing file. We should check if the file
* owner is us, if not, unlink and retry. If unlink fails we log
* the error and return.
*/
if (!newfile) {
return (-1);
}
/* Check if this is the same file we lstat'd earlier */
return (-1);
}
/*
* Some apps (gssd, via a priv version of getuid())
* "set" the real uid only, others
*/
"%s owned by %d instead of %d (euid=%d, uid=%d)",
return (-1);
}
return (0);
}
}
return (0);
}
int mode;
{
int fd;
krb5_error_code retval = 0;
int retries;
int newfile = 0;
/* Don't know what state it's in; shut down and start anew. */
}
switch(mode) {
break;
case FCC_OPEN_AND_ERASE:
break;
case FCC_OPEN_RDWR:
break;
case FCC_OPEN_RDONLY:
default:
break;
}
retries = 0;
/*
* SUNW
* If we are opening in NOUNLINK mode, check whether we are opening a
* symlink or a file owned by some other user and take preventive action.
*/
newfile = 0;
if (mode == FCC_OPEN_AND_ERASE_NOUNLINK) {
goto fcc_retry;
} else {
}
if (fd == -1)
else
/* wait some time before retrying */
goto fcc_retry;
}
return retval;
}
int cnt;
/*
* SUNW
* If this file was not created, we have to flush existing data.
* This will happen only if we are doing an ERASE_NOUNLINK open.
*/
}
/* write the version number */
sizeof(fcc_fvno)) {
goto done;
}
/* V4 of the credentials cache format allows for header tags */
fcc_flen = 0;
/* Write header length */
/* Write time offset tag */
}
}
goto done;
}
/* verify a valid version number is there */
sizeof(fcc_fvno)) {
goto done;
}
{
goto done;
}
char buf[1024];
{
goto done;
}
while (fcc_flen) {
{
goto done;
}
switch (fcc_tag) {
case FCC_TAG_DELTATIME:
goto done;
}
{
goto done;
}
break;
}
{
goto done;
}
break;
default:
goto done;
}
break;
}
}
}
done:
if (retval) {
}
return retval;
}