mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-23 05:55:41 +02:00
pwd and statvfs functions moved out from openbsd
This commit is contained in:
parent
976eb6ee3b
commit
3ffe279bf7
@ -390,7 +390,7 @@
|
||||
/* #undef HAVE_FSFILCNT_T */
|
||||
|
||||
/* Define to 1 if you have the `fstatvfs' function. */
|
||||
/* #undef HAVE_FSTATVFS */
|
||||
#define HAVE_FSTATVFS 1
|
||||
|
||||
/* Define to 1 if you have the `futimes' function. */
|
||||
/* #undef HAVE_FUTIMES */
|
||||
@ -770,7 +770,7 @@
|
||||
/* #undef HAVE_READPASSPHRASE_H */
|
||||
|
||||
/* Define to 1 if you have the `realpath' function. */
|
||||
/* #undef HAVE_REALPATH */
|
||||
#define HAVE_REALPATH 1
|
||||
|
||||
/* Define to 1 if you have the `recvmsg' function. */
|
||||
/* #undef HAVE_RECVMSG */
|
||||
@ -915,7 +915,7 @@
|
||||
/* #undef HAVE_STATFS */
|
||||
|
||||
/* Define to 1 if you have the `statvfs' function. */
|
||||
/* #undef HAVE_STATVFS */
|
||||
#define HAVE_STATVFS 1
|
||||
|
||||
/* Define to 1 if you have the <stddef.h> header file. */
|
||||
#define HAVE_STDDEF_H 1
|
||||
@ -1050,7 +1050,7 @@
|
||||
#define HAVE_SYS_SELECT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/statvfs.h> header file. */
|
||||
/* #undef HAVE_SYS_STATVFS_H */
|
||||
#define HAVE_SYS_STATVFS_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
@ -1152,7 +1152,7 @@
|
||||
/* #undef HAVE_USERSEC_H */
|
||||
|
||||
/* Define to 1 if you have the `user_from_uid' function. */
|
||||
/* #undef HAVE_USER_FROM_UID */
|
||||
#define HAVE_USER_FROM_UID 1
|
||||
|
||||
/* Define to 1 if you have the <util.h> header file. */
|
||||
/* #undef HAVE_UTIL_H */
|
||||
@ -1619,7 +1619,6 @@
|
||||
#undef HAVE_PTY_H
|
||||
#define HAVE_NANOSLEEP 1
|
||||
#define HAVE_READPASSPHRASE 1
|
||||
#define HAVE_REALPATH 1
|
||||
#undef HAVE_SIG_ATOMIC_T
|
||||
#define HAVE_SIZE_T 1
|
||||
#undef HAVE_STRERROR
|
||||
|
@ -62,10 +62,8 @@
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\port-solaris.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\port-tun.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\port-uw.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\pwcache.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\readpassphrase.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\reallocarray.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\realpath.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\rmd160.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\rresvport.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\setenv.c" />
|
||||
|
@ -141,18 +141,12 @@
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\port-uw.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\pwcache.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\readpassphrase.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\reallocarray.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\realpath.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)openbsd-compat\rmd160.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -185,6 +185,25 @@
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tnnet.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\win32auth.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\cng_kex.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\arpa\inet.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\arpa\nameser.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\grp.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\kfwfix.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\netdb.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\netinet\in.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\netinet\in_systm.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\netinet\ip.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\netinet\tcp.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\process.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\pwd.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\resolv.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\syslog.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\sys\ioctl.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\sys\param.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\sys\resource.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\sys\uio.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\sys\un.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\termios.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -13,6 +13,18 @@
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="includes">
|
||||
<UniqueIdentifier>{7eee54fc-3739-4ebb-b15e-9558c1ec91d3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="includes\sys">
|
||||
<UniqueIdentifier>{17007d09-bf66-4728-8780-b9a89f427dc8}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="includes\netinet">
|
||||
<UniqueIdentifier>{a6170aac-573e-4d21-90ac-d55b2bcb2dde}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="includes\arpa">
|
||||
<UniqueIdentifier>{4491864e-2a50-49ad-a8a6-0e4f822a45e9}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\ansiprsr.c">
|
||||
@ -75,7 +87,7 @@
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\win32auth.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\win32compat\cng_dh.c">
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\cng_dh.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\cng_openssl_dh.c">
|
||||
@ -128,5 +140,62 @@
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\cng_kex.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\grp.h">
|
||||
<Filter>includes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\kfwfix.h">
|
||||
<Filter>includes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\netdb.h">
|
||||
<Filter>includes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\process.h">
|
||||
<Filter>includes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\pwd.h">
|
||||
<Filter>includes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\resolv.h">
|
||||
<Filter>includes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\syslog.h">
|
||||
<Filter>includes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\termios.h">
|
||||
<Filter>includes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\sys\ioctl.h">
|
||||
<Filter>includes\sys</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\sys\param.h">
|
||||
<Filter>includes\sys</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\sys\resource.h">
|
||||
<Filter>includes\sys</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\sys\uio.h">
|
||||
<Filter>includes\sys</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\sys\un.h">
|
||||
<Filter>includes\sys</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\arpa\inet.h">
|
||||
<Filter>includes\arpa</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\arpa\nameser.h">
|
||||
<Filter>includes\arpa</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\netinet\in.h">
|
||||
<Filter>includes\netinet</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\netinet\in_systm.h">
|
||||
<Filter>includes\netinet</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\netinet\ip.h">
|
||||
<Filter>includes\netinet</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\includes\netinet\tcp.h">
|
||||
<Filter>includes\netinet</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -161,6 +161,7 @@
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\unistd.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\w32posix.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\poll.h" />
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\sys\statvfs.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -43,6 +43,9 @@
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\sys\wait.h">
|
||||
<Filter>inc\sys</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\sys\statvfs.h">
|
||||
<Filter>inc\sys</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="inc">
|
||||
|
26
contrib/win32/win32compat/inc/sys/statvfs.h
Normal file
26
contrib/win32/win32compat/inc/sys/statvfs.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#define ST_RDONLY 1
|
||||
#define ST_NOSUID 2
|
||||
typedef unsigned long fsblkcnt_t;
|
||||
typedef unsigned long fsfilcnt_t;
|
||||
|
||||
struct statvfs {
|
||||
unsigned long f_bsize; /* File system block size. */
|
||||
unsigned long f_frsize; /* Fundamental file system block size. */
|
||||
fsblkcnt_t f_blocks; /* Total number of blocks on file system in */
|
||||
/* units of f_frsize. */
|
||||
fsblkcnt_t f_bfree; /* Total number of free blocks. */
|
||||
fsblkcnt_t f_bavail; /* Number of free blocks available to */
|
||||
/* non-privileged process. */
|
||||
fsfilcnt_t f_files; /* Total number of file serial numbers. */
|
||||
fsfilcnt_t f_ffree; /* Total number of free file serial numbers. */
|
||||
fsfilcnt_t f_favail; /* Number of file serial numbers available to */
|
||||
/* non-privileged process. */
|
||||
unsigned long f_fsid; /* File system ID. */
|
||||
unsigned long f_flag; /* BBit mask of f_flag values. */
|
||||
unsigned long f_namemax;/* Maximum filename length. */
|
||||
};
|
||||
|
||||
int statvfs(const char *, struct statvfs *);
|
||||
int fstatvfs(int, struct statvfs *);
|
@ -28,4 +28,8 @@ void endpwent(void);
|
||||
|
||||
typedef int PWD_USER_TOKEN; /* This is really just a HANDLE, but we might not have windows.h included */
|
||||
PWD_USER_TOKEN PwdCreateUserToken(const char *pUserName, const char *pDomainName, const char *pSourceName);
|
||||
|
||||
const char *
|
||||
user_from_uid(uid_t uid, int nouser);
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <Windows.h>
|
||||
#include "inc\defs.h"
|
||||
#include "inc\sys\statvfs.h"
|
||||
|
||||
int usleep(unsigned int useconds)
|
||||
{
|
||||
@ -15,4 +16,48 @@ pid_t waitpid(pid_t pid, int *status, int options) {
|
||||
void
|
||||
explicit_bzero(void *b, size_t len) {
|
||||
SecureZeroMemory(b, len);
|
||||
}
|
||||
|
||||
int statvfs(const char *path, struct statvfs *buf) {
|
||||
DWORD sectorsPerCluster;
|
||||
DWORD bytesPerSector;
|
||||
DWORD freeClusters;
|
||||
DWORD totalClusters;
|
||||
|
||||
if (GetDiskFreeSpace(path, §orsPerCluster, &bytesPerSector,
|
||||
&freeClusters, &totalClusters) == TRUE)
|
||||
{
|
||||
debug3("path : [%s]", path);
|
||||
debug3("sectorsPerCluster : [%lu]", sectorsPerCluster);
|
||||
debug3("bytesPerSector : [%lu]", bytesPerSector);
|
||||
debug3("bytesPerCluster : [%lu]", sectorsPerCluster * bytesPerSector);
|
||||
debug3("freeClusters : [%lu]", freeClusters);
|
||||
debug3("totalClusters : [%lu]", totalClusters);
|
||||
|
||||
buf->f_bsize = sectorsPerCluster * bytesPerSector;
|
||||
buf->f_frsize = sectorsPerCluster * bytesPerSector;
|
||||
buf->f_blocks = totalClusters;
|
||||
buf->f_bfree = freeClusters;
|
||||
buf->f_bavail = freeClusters;
|
||||
buf->f_files = -1;
|
||||
buf->f_ffree = -1;
|
||||
buf->f_favail = -1;
|
||||
buf->f_fsid = 0;
|
||||
buf->f_flag = 0;
|
||||
buf->f_namemax = MAX_PATH - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
debug3("ERROR: Cannot get free space for [%s]. Error code is : %d.\n",
|
||||
path, GetLastError());
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int fstatvfs(int fd, struct statvfs *buf) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
@ -411,6 +411,38 @@ void endpwent(void)
|
||||
*/
|
||||
}
|
||||
|
||||
#define NCACHE 64 /* power of 2 */
|
||||
#define MASK (NCACHE - 1) /* bits to store with */
|
||||
|
||||
const char *
|
||||
user_from_uid(uid_t uid, int nouser)
|
||||
{
|
||||
static struct ncache {
|
||||
uid_t uid;
|
||||
char *name;
|
||||
} c_uid[NCACHE];
|
||||
static int pwopen;
|
||||
static char nbuf[15]; /* 32 bits == 10 digits */
|
||||
struct passwd *pw;
|
||||
struct ncache *cp;
|
||||
|
||||
cp = c_uid + (uid & MASK);
|
||||
if (cp->uid != uid || cp->name == NULL) {
|
||||
if (pwopen == 0) {
|
||||
pwopen = 1;
|
||||
}
|
||||
if ((pw = getpwuid(uid)) == NULL) {
|
||||
if (nouser)
|
||||
return (NULL);
|
||||
(void)snprintf(nbuf, sizeof(nbuf), "%u", uid);
|
||||
}
|
||||
cp->uid = uid;
|
||||
if (cp->name != NULL)
|
||||
free(cp->name);
|
||||
cp->name = strdup(pw ? pw->pw_name : nbuf);
|
||||
}
|
||||
return (cp->name);
|
||||
}
|
||||
|
||||
#ifdef USE_NTCREATETOKEN
|
||||
|
||||
@ -426,3 +458,81 @@ PWD_USER_TOKEN PwdCreateUserToken(const char *pUserName,
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* TODO - this is moved from realpath.c in openbsdcompat. Review and finalize its position*/
|
||||
|
||||
#include <Shlwapi.h>
|
||||
|
||||
void backslashconvert(char *str)
|
||||
{
|
||||
while (*str) {
|
||||
if (*str == '/')
|
||||
*str = '\\'; // convert forward slash to back slash
|
||||
str++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// convert back slash to forward slash
|
||||
void slashconvert(char *str)
|
||||
{
|
||||
while (*str) {
|
||||
if (*str == '\\')
|
||||
*str = '/'; // convert back slash to forward slash
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
char *realpathWin32(const char *path, char resolved[PATH_MAX])
|
||||
{
|
||||
char realpath[PATH_MAX];
|
||||
|
||||
strlcpy(resolved, path + 1, sizeof(realpath));
|
||||
backslashconvert(resolved);
|
||||
PathCanonicalizeA(realpath, resolved);
|
||||
slashconvert(realpath);
|
||||
|
||||
/*
|
||||
* Store terminating slash in 'X:/' on Windows.
|
||||
*/
|
||||
|
||||
if (realpath[1] == ':' && realpath[2] == 0)
|
||||
{
|
||||
realpath[2] = '/';
|
||||
realpath[3] = 0;
|
||||
}
|
||||
|
||||
resolved[0] = *path; // will be our first slash in /x:/users/test1 format
|
||||
strncpy(resolved + 1, realpath, sizeof(realpath));
|
||||
return resolved;
|
||||
}
|
||||
|
||||
// like realpathWin32() but takes out the first slash so that windows systems can work on the actual file or directory
|
||||
char *realpathWin32i(const char *path, char resolved[PATH_MAX])
|
||||
{
|
||||
char realpath[PATH_MAX];
|
||||
|
||||
if (path[0] != '/') {
|
||||
// absolute form x:/abc/def given, no first slash to take out
|
||||
strlcpy(resolved, path, sizeof(realpath));
|
||||
}
|
||||
else
|
||||
strlcpy(resolved, path + 1, sizeof(realpath));
|
||||
|
||||
backslashconvert(resolved);
|
||||
PathCanonicalizeA(realpath, resolved);
|
||||
slashconvert(realpath);
|
||||
|
||||
/*
|
||||
* Store terminating slash in 'X:/' on Windows.
|
||||
*/
|
||||
|
||||
if (realpath[1] == ':' && realpath[2] == 0)
|
||||
{
|
||||
realpath[2] = '/';
|
||||
realpath[3] = 0;
|
||||
}
|
||||
|
||||
strncpy(resolved, realpath, sizeof(realpath));
|
||||
return resolved;
|
||||
}
|
||||
|
@ -30,9 +30,6 @@
|
||||
static void
|
||||
copy_statfs_to_statvfs(struct statvfs *to, struct statfs *from)
|
||||
{
|
||||
#ifdef WIN32_FIXME
|
||||
//PRAGMA:TODO
|
||||
#else /* WIN32_FIXME */
|
||||
|
||||
to->f_bsize = from->f_bsize;
|
||||
to->f_frsize = from->f_bsize; /* no exact equivalent */
|
||||
@ -45,53 +42,11 @@ copy_statfs_to_statvfs(struct statvfs *to, struct statfs *from)
|
||||
to->f_fsid = 0; /* XXX fix me */
|
||||
to->f_flag = from->f_flags;
|
||||
to->f_namemax = MNAMELEN;
|
||||
#endif /* !WIN32_FIXME */
|
||||
}
|
||||
|
||||
# ifndef HAVE_STATVFS
|
||||
int statvfs(const char *path, struct statvfs *buf)
|
||||
{
|
||||
#ifdef WIN32_FIXME
|
||||
|
||||
DWORD sectorsPerCluster;
|
||||
DWORD bytesPerSector;
|
||||
DWORD freeClusters;
|
||||
DWORD totalClusters;
|
||||
|
||||
if (GetDiskFreeSpace(path, §orsPerCluster, &bytesPerSector,
|
||||
&freeClusters, &totalClusters) == TRUE)
|
||||
{
|
||||
debug3("path : [%s]", path);
|
||||
debug3("sectorsPerCluster : [%lu]", sectorsPerCluster);
|
||||
debug3("bytesPerSector : [%lu]", bytesPerSector);
|
||||
debug3("bytesPerCluster : [%lu]", sectorsPerCluster * bytesPerSector);
|
||||
debug3("freeClusters : [%lu]", freeClusters);
|
||||
debug3("totalClusters : [%lu]", totalClusters);
|
||||
|
||||
buf -> f_bsize = sectorsPerCluster * bytesPerSector;
|
||||
buf -> f_frsize = sectorsPerCluster * bytesPerSector;
|
||||
buf -> f_blocks = totalClusters;
|
||||
buf -> f_bfree = freeClusters;
|
||||
buf -> f_bavail = freeClusters;
|
||||
buf -> f_files = -1;
|
||||
buf -> f_ffree = -1;
|
||||
buf -> f_favail = -1;
|
||||
buf -> f_fsid = 0;
|
||||
buf -> f_flag = 0;
|
||||
buf -> f_namemax = MAX_PATH - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
debug3("ERROR: Cannot get free space for [%s]. Error code is : %d.\n",
|
||||
path, GetLastError());
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#else /* WIN32_FIXME */
|
||||
|
||||
# ifdef HAVE_STATFS
|
||||
struct statfs fs;
|
||||
|
||||
@ -104,7 +59,6 @@ int statvfs(const char *path, struct statvfs *buf)
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
# endif
|
||||
#endif /* !WIN32_FIXME */
|
||||
}
|
||||
# endif
|
||||
|
||||
|
@ -82,7 +82,6 @@ user_from_uid(uid_t uid, int nouser)
|
||||
char *
|
||||
group_from_gid(gid_t gid, int nogroup)
|
||||
{
|
||||
#ifndef WIN32_FIXME
|
||||
static struct ncache {
|
||||
gid_t gid;
|
||||
char *name;
|
||||
@ -119,6 +118,5 @@ group_from_gid(gid_t gid, int nogroup)
|
||||
|
||||
return NULL;
|
||||
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
@ -31,8 +31,6 @@
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#ifndef WIN32_FIXME
|
||||
|
||||
#if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH)
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -199,83 +197,4 @@ realpath(const char *path, char resolved[PATH_MAX])
|
||||
resolved[resolved_len - 1] = '\0';
|
||||
return (resolved);
|
||||
}
|
||||
#endif /* !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) */
|
||||
|
||||
#else
|
||||
|
||||
#include <Shlwapi.h>
|
||||
|
||||
void backslashconvert(char *str)
|
||||
{
|
||||
while (*str) {
|
||||
if (*str == '/')
|
||||
*str = '\\'; // convert forward slash to back slash
|
||||
str++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// convert back slash to forward slash
|
||||
void slashconvert(char *str)
|
||||
{
|
||||
while (*str) {
|
||||
if (*str == '\\')
|
||||
*str = '/'; // convert back slash to forward slash
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
char *realpathWin32(const char *path, char resolved[PATH_MAX])
|
||||
{
|
||||
char realpath[PATH_MAX];
|
||||
|
||||
strlcpy(resolved, path + 1, sizeof(realpath));
|
||||
backslashconvert(resolved);
|
||||
PathCanonicalizeA(realpath, resolved);
|
||||
slashconvert(realpath);
|
||||
|
||||
/*
|
||||
* Store terminating slash in 'X:/' on Windows.
|
||||
*/
|
||||
|
||||
if (realpath[1] == ':' && realpath[2] == 0)
|
||||
{
|
||||
realpath[2] = '/';
|
||||
realpath[3] = 0;
|
||||
}
|
||||
|
||||
resolved[0] = *path; // will be our first slash in /x:/users/test1 format
|
||||
strncpy(resolved + 1, realpath, sizeof(realpath));
|
||||
return resolved;
|
||||
}
|
||||
|
||||
// like realpathWin32() but takes out the first slash so that windows systems can work on the actual file or directory
|
||||
char *realpathWin32i(const char *path, char resolved[PATH_MAX])
|
||||
{
|
||||
char realpath[PATH_MAX];
|
||||
|
||||
if (path[0] != '/') {
|
||||
// absolute form x:/abc/def given, no first slash to take out
|
||||
strlcpy(resolved, path, sizeof(realpath));
|
||||
}
|
||||
else
|
||||
strlcpy(resolved, path + 1, sizeof(realpath));
|
||||
|
||||
backslashconvert(resolved);
|
||||
PathCanonicalizeA(realpath, resolved);
|
||||
slashconvert(realpath);
|
||||
|
||||
/*
|
||||
* Store terminating slash in 'X:/' on Windows.
|
||||
*/
|
||||
|
||||
if (realpath[1] == ':' && realpath[2] == 0)
|
||||
{
|
||||
realpath[2] = '/';
|
||||
realpath[3] = 0;
|
||||
}
|
||||
|
||||
strncpy(resolved, realpath, sizeof(realpath));
|
||||
return resolved;
|
||||
}
|
||||
#endif /* WIN32_FIXME */
|
||||
#endif /* !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) */
|
Loading…
x
Reference in New Issue
Block a user