file.c revision 24231e53a5c3079431f84dcddfee1e761fec7329
/*
* Copyright (C) 2000-2002, 2004, 2007, 2009, 2011-2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id$ */
#include <config.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <io.h>
#include <process.h>
#include <fcntl.h>
#include "errno2result.h"
static const char alphnum[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
/*
* Emulate UNIX mkstemp, which returns an open FD to the new file
*
*/
static int
if (binary)
trv++;
/* extra X's get set to 0's */
while (*--trv == 'X') {
}
/*
* check the target directory; if you have six X's and it
* doesn't exist this runs for a *very* long time.
*/
break;
if (*trv == '\\') {
*trv = '\0';
return (0);
return (0);
}
*trv = '\\';
break;
}
}
for (;;) {
if (doopen) {
if ((*doopen =
return (1);
return (0);
/* tricky little algorithm for backward compatibility */
if (!*trv)
return (0);
if (*trv == 'z')
*trv++ = 'a';
else {
*trv = 'a';
else
++*trv;
break;
}
}
}
/*NOTREACHED*/
}
static int
int fd;
}
/*
* XXXDCL As the API for accessing file statistics undoubtedly gets expanded,
* it might be good to provide a mechanism that allows for the results
* of a previous stat() to be used again without having to do another stat,
* such as perl's mechanism of using "_" in place of a file name to indicate
* that the results of the last stat should be used. But then you get into
* annoying MP issues. BTW, Win32 has stat().
*/
static isc_result_t
return (result);
}
static isc_result_t
return (result);
}
if (result == ISC_R_SUCCESS)
return (result);
}
if (result == ISC_R_SUCCESS)
return (result);
}
/*
* isc_file_safemovefile is needed to be defined here to ensure that
* any file with the new name is renamed to a backup name and then the
* rename is done. If all goes well then the backup can be deleted,
* otherwise it gets renamed back.
*/
int
char buf[512];
int tmpfd;
/*
* Make sure we have something to do
*/
return (-1);
}
/*
* Rename to a backup the new file if it still exists
*/
if (tmpfd > 0)
(void)DeleteFile(buf);
}
/* Now rename the file to the new name
*/
if (filestatus == 0) {
/*
* Try to rename the backup back to the original name
* if the backup got created
*/
if (filestatus == 0)
}
return (-1);
}
/*
* Delete the backup file if it got created
*/
(void)DeleteFile(buf);
return (0);
}
int fh;
return (isc__errno2result(errno));
NULL,
NULL,
{
return (isc__errno2result(errno));
}
return (ISC_R_SUCCESS);
}
if (result == ISC_R_SUCCESS)
return (result);
}
int fh;
return (isc__errno2result(errno));
/*
* Set the date via the filedate system call and return. Failing
* this call implies the new file times are not supported by the
* underlying file system.
*/
NULL,
{
return (isc__errno2result(errno));
}
return (ISC_R_SUCCESS);
}
}
{
char *s;
if (s != NULL)
templet = s + 1;
if (s != NULL) {
return (ISC_R_NOSPACE);
/* Copy 'prefixlen' bytes and NUL terminate. */
} else {
return (ISC_R_NOSPACE);
}
return (ISC_R_SUCCESS);
}
int fd;
int res = 0;
if (fd == -1)
else
if (result == ISC_R_SUCCESS) {
if (res != 0) {
}
}
return (result);
}
static isc_result_t
int fd;
FILE *f;
/*
* Win32 does not have mkstemp. Using emulation above.
*/
if (fd == -1)
if (result == ISC_R_SUCCESS) {
#if 1
#else
#endif
if (f == NULL) {
} else
*fp = f;
}
return (result);
}
}
}
}
}
}
}
isc_file_remove(const char *filename) {
int r;
if (r == 0)
return (ISC_R_SUCCESS);
else
return (isc__errno2result(errno));
}
int r;
if (r == 0)
return (ISC_R_SUCCESS);
else
return (isc__errno2result(errno));
}
isc_file_exists(const char *pathname) {
}
isc_file_isplainfile(const char *filename) {
/*
* This function returns success if filename is a plain file.
*/
return(isc__errno2result(errno));
return(ISC_R_INVALIDFILE);
return(ISC_R_SUCCESS);
}
isc_file_isplainfilefd(int fd) {
/*
* This function returns success if filename is a plain file.
*/
return(isc__errno2result(errno));
return(ISC_R_INVALIDFILE);
return(ISC_R_SUCCESS);
}
isc_file_isdirectory(const char *filename) {
/*
* This function returns success if filename is a directory.
*/
return(isc__errno2result(errno));
return(ISC_R_INVALIDFILE);
return(ISC_R_SUCCESS);
}
isc_file_isabsolute(const char *filename) {
/*
* Look for c:\path\... style, c:/path/... or \\computer\shar\path...
* the UNC style file specs
*/
return (ISC_TRUE);
return (ISC_TRUE);
return (ISC_TRUE);
return (ISC_FALSE);
}
isc_file_iscurrentdir(const char *filename) {
}
isc_file_ischdiridempotent(const char *filename) {
if (isc_file_isabsolute(filename))
return (ISC_TRUE);
if (filename[0] == '\\')
return (ISC_TRUE);
if (filename[0] == '/')
return (ISC_TRUE);
return (ISC_TRUE);
return (ISC_FALSE);
}
const char *
isc_file_basename(const char *filename) {
char *s;
if (s == NULL)
return (filename);
return (s + 1);
}
const char *s;
const char *p;
/*
* Strip the path from the name
*/
s = isc_file_basename(filename);
if (s == NULL) {
return (ISC_R_NOSPACE);
}
/*
* Strip any and all suffixes
*/
p = strchr(s, '.');
if (p == NULL) {
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
/*
* Copy the result to the buffer
*/
len = p - s;
return (ISC_R_NOSPACE);
/* Copy up to 'len' bytes and NUL terminate. */
return (ISC_R_SUCCESS);
}
char *ptrname;
/* Something went wrong in getting the path */
if (retval == 0)
return (ISC_R_NOTFOUND);
/* Caller needs to provide a larger buffer to contain the string */
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
int fh;
return (isc__errno2result(errno));
return (isc__errno2result(errno));
}
return (ISC_R_SUCCESS);
}
int flags;
FILE *f;
int fd;
if (result == ISC_R_SUCCESS) {
return (ISC_R_INVALIDFILE);
} else if (result == ISC_R_FILENOTFOUND) {
} else
return (result);
if (fd == -1)
return (isc__errno2result(errno));
if (f == NULL) {
return (result);
}
*fp = f;
return (ISC_R_SUCCESS);
}
char const ** basename)
{
char *dir;
char *backslash;
} else {
}
return (ISC_R_NOMEMORY);
if (*file == '\0') {
return (ISC_R_INVALIDFILE);
}
return (ISC_R_SUCCESS);
}
void *
{
void *buf;
return (NULL);
}
return (buf);
}
int
return (0);
}
#define DISALLOW "\\/:ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
{
size_t l = 0;
/*
* allow room for a full sha256 hash (64 chars
* plus null terminator)
*/
if (l < 65)
l = 65;
return (ISC_R_NOSPACE);
/* Check whether the full-length SHA256 hash filename exists */
if (isc_file_exists(buf)) {
return (ISC_R_SUCCESS);
}
/* Check for a truncated SHA256 hash filename */
if (isc_file_exists(buf)) {
return (ISC_R_SUCCESS);
}
/*
* If neither hash filename already exists, then we'll use
* the original base name if it has no disallowed characters,
* or the truncated hash name if it does.
*/
return (ISC_R_SUCCESS);
}
return (ISC_R_SUCCESS);
}
/*
*/
isc_file_isdirwritable(const char *path) {
return (answer);
}
/*
* Figure out buffer size. GetFileSecurity() should not succeed.
*/
{
return (answer);
}
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
return (answer);
}
return (answer);
}
/*
* GetFileSecurity() should succeed.
*/
{
return (answer);
}
{
{
PRIVILEGE_SET privileges = { 0 };
DWORD grantedAccess = 0;
&grantedAccess, &result))
{
}
}
}
return (answer);
}