This commit is contained in:
Manoj Ampalam 2017-01-25 14:43:55 -08:00 committed by GitHub
parent e4da8db4d2
commit c6b57c018c
43 changed files with 384 additions and 428 deletions

View File

@ -939,7 +939,7 @@
/* #undef HAVE_STRICT_MKSTEMP */
/* Define to 1 if you have the <strings.h> header file. */
/* #undef HAVE_STRINGS_H
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1

View File

@ -2,7 +2,7 @@ Param($Config_h_vs, $Config_h, $VCIncludePath, $OutCRTHeader)
Copy-Item $Config_h_vs $Config_h -Force
if (Test-Path $OutCRTHeader) {exit}
$headers = ("stdio.h", "string.h")
$headers = ("stdio.h", "string.h", "sys\types.h", "ctype.h", "stdlib.h", "sys\stat.h", "fcntl.h")
$paths = $VCIncludePath.Split(";")
Set-Content -Path $OutCRTHeader -Value "/*`r`n * DO NOT EDIT - AutoGenerated by config.ps1`r`n */`r`n" -Force
foreach ($header in $headers) {
@ -10,7 +10,7 @@ foreach ($header in $headers) {
{
if ($path -and (Test-Path (Join-Path $path $header)))
{
$entry = "#define " + $header.ToUpper().Replace(".","_") + " `"" + (Join-Path $path $header) + "`""
$entry = "#define " + $header.ToUpper().Replace(".","_").Replace("\","_") + " `"" + (Join-Path $path $header) + "`""
Add-Content -Path $OutCRTHeader -Value $entry
break
}

View File

@ -163,7 +163,6 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\w32fd.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\defs.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\fcntl.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\signal.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\sys\select.h" />
@ -172,7 +171,6 @@
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\sys\time.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\sys\wait.h" />
<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" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\dlfcn.h" />
@ -201,6 +199,10 @@
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\misc_internal.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\stdio.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\string.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\strings.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\sys\types.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\ctype.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\stdlib.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -34,9 +34,6 @@
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\sys\time.h">
<Filter>inc\sys</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\defs.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\fcntl.h">
<Filter>inc</Filter>
</ClInclude>
@ -46,9 +43,6 @@
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\unistd.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\w32posix.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\poll.h">
<Filter>inc</Filter>
</ClInclude>
@ -58,8 +52,6 @@
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\sys\statvfs.h">
<Filter>inc\sys</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\dlfcn.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\syslog.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\signal_internal.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\sys\param.h">
<Filter>inc\sys</Filter>
@ -112,11 +104,9 @@
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\termios.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\dirent.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\libgen.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\pwd.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\misc_internal.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\stdio.h">
<Filter>inc</Filter>
@ -124,6 +114,30 @@
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\string.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\pwd.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\dirent.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\dlfcn.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\sys\types.h">
<Filter>inc\sys</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\strings.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\syslog.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\stdlib.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\ctype.h">
<Filter>inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="inc">

View File

@ -33,7 +33,6 @@
#include <sys/types.h>
#include <io.h>
#include "w32fd.h"
#include "inc/defs.h"
#include <errno.h>
#include <stddef.h>
#include "inc\utf.h"
@ -205,9 +204,7 @@ createFile_flags_setup(int flags, int mode, struct createFile_flags* cf_flags) {
switch (rwflags) {
case O_RDONLY:
cf_flags->dwDesiredAccess = GENERIC_READ;
/*todo: need to review to make sure all flags are correct*/
if (flags & O_NONBLOCK)
cf_flags->dwShareMode = FILE_SHARE_READ;
cf_flags->dwShareMode = FILE_SHARE_READ;
break;
case O_WRONLY:
cf_flags->dwDesiredAccess = GENERIC_WRITE;

View File

@ -0,0 +1,5 @@
#include "crtheaders.h"
#include CTYPE_H
#define isascii __isascii

View File

@ -1,97 +0,0 @@
/*
* Author: Manoj Ampalam <manoj.ampalam@microsoft.com>
*
* Redefined and missing POSIX macros
*/
#pragma once
#include <memory.h>
/* total fds that can be allotted */
#define MAX_FDS 256 /* a 2^n number */
#undef FD_ZERO
#define FD_ZERO(set) (memset( (set), 0, sizeof(w32_fd_set)))
#undef FD_SET
#define FD_SET(fd,set) ( (set)->bitmap[(fd) >> 3] |= (0x80 >> ((fd) % 8)))
#undef FD_ISSET
#define FD_ISSET(fd, set) (( (set)->bitmap[(fd) >> 3] & (0x80 >> ((fd) % 8)))?1:0)
#undef FD_CLR
#define FD_CLR(fd, set) ((set)->bitmap[(fd) >> 3] &= (~(0x80 >> ((fd) % 8))))
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
/*fcntl commands*/
#define F_GETFL 0x1
#define F_SETFL 0x2
#define F_GETFD 0x4
#define F_SETFD 0x8
/*fd flags*/
#define FD_CLOEXEC 0x1
/* signal related defs*/
/* supported signal types */
#define W32_SIGINT 0
#define W32_SIGSEGV 1
#define W32_SIGPIPE 2
#define W32_SIGCHLD 3
#define W32_SIGALRM 4
#define W32_SIGTSTP 5
#define W32_SIGHUP 6
#define W32_SIGQUIT 7
#define W32_SIGTERM 8
#define W32_SIGTTIN 9
#define W32_SIGTTOU 10
#define W32_SIGWINCH 11
#define W32_SIGMAX 12
/* these signals are not supposed to be raised on Windows*/
#define W32_SIGSTOP 13
#define W32_SIGABRT 14
#define W32_SIGFPE 15
#define W32_SIGILL 16
#define W32_SIGKILL 17
#define W32_SIGUSR1 18
#define W32_SIGUSR2 19
/* singprocmask "how" codes*/
#define SIG_BLOCK 0
#define SIG_UNBLOCK 1
#define SIG_SETMASK 2
typedef void(*sighandler_t)(int);
typedef int sigset_t;
#define sigemptyset(set) (memset( (set), 0, sizeof(sigset_t)))
#define sigaddset(set, sig) ( (*(set)) |= (0x80000000 >> (sig)))
#define sigismember(set, sig) ( (*(set) & (0x80000000 >> (sig)))?1:0 )
#define sigdelset(set, sig) ( (*(set)) &= (~( 0x80000000 >> (sig)) ) )
/* signal action codes*/
#define W32_SIG_ERR ((sighandler_t)-1)
#define W32_SIG_DFL ((sighandler_t)0)
#define W32_SIG_IGN ((sighandler_t)1)
typedef unsigned short _mode_t;
typedef _mode_t mode_t;
typedef int ssize_t;
/* TODO - investigate if it makes sense to make pid_t a DWORD_PTR.
* Double check usage of pid_t as int */
typedef int pid_t;
/* wait pid options */
#define WNOHANG 1
/*ioctl macros and structs*/
#define TIOCGWINSZ 1
struct winsize {
unsigned short ws_row; /* rows, in characters */
unsigned short ws_col; /* columns, in character */
unsigned short ws_xpixel; /* horizontal size, pixels */
unsigned short ws_ypixel; /* vertical size, pixels */
};

View File

@ -1,23 +1,40 @@
#include "crtheaders.h"
#include FCNTL_H
/*fcntl commands*/
#define F_GETFL 0x1
#define F_SETFL 0x2
#define F_GETFD 0x4
#define F_SETFD 0x8
#pragma once
#define O_RDONLY 0x0000 // open for reading only
#define O_WRONLY 0x0001 // open for writing only
#define O_RDWR 0x0002 // open for reading and writing
#define O_ACCMODE 0x0003
#define O_APPEND 0x0008 // writes done at eof
#define O_CREAT 0x0100 // create and open file
#define O_TRUNC 0x0200 // open and truncate
#define O_EXCL 0x0400 // open only if file doesn't already exist
#define O_TEXT 0x4000 /* file mode is text (translated) */
#define O_BINARY 0x8000 /* file mode is binary (untranslated) */
#define O_WTEXT 0x10000 /* file mode is UTF16 (translated) */
#define O_U16TEXT 0x20000 /* file mode is UTF16 no BOM (translated) */
#define O_U8TEXT 0x40000 /* file mode is UTF8 no BOM (translated) */
#define O_NOCTTY 0x80000 /* TODO - implement this if it makes sense on Windows*/
/*fd flags*/
#define FD_CLOEXEC 0x1
#define F_OK 0
int w32_fcntl(int fd, int cmd, ... /* arg */);
#define fcntl(a,b,...) w32_fcntl((a), (b), __VA_ARGS__)
#define open w32_open
int w32_open(const char *pathname, int flags, ...);
void* w32_fd_to_handle(int fd);
int w32_allocate_fd_for_handle(void* h, int is_sock);
#define O_ACCMODE 0x0003
#define O_RDONLY _O_RDONLY
#define O_WRONLY _O_WRONLY
#define O_RDWR _O_RDWR
#define O_APPEND _O_APPEND
#define O_CREAT _O_CREAT
#define O_TRUNC _O_TRUNC
#define O_EXCL _O_EXCL
#define O_TEXT _O_TEXT
#define O_BINARY _O_BINARY
#define O_RAW _O_BINARY
#define O_TEMPORARY _O_TEMPORARY
#define O_NOINHERIT _O_NOINHERIT
#define O_SEQUENTIAL _O_SEQUENTIAL
#define O_RANDOM _O_RANDOM
#define O_U16TEXT _O_U16TEXT

View File

@ -1,6 +1,7 @@
#pragma once
#include "w32posix.h"
#include "sys\types.h"
#include "sys\socket.h"
/* created to #def out decarations in open-bsd.h (that are defined in winsock2.h) */

View File

@ -10,7 +10,7 @@
#ifndef COMPAT_PWD_H
#define COMPAT_PWD_H 1
#include "sys\param.h"
#include "sys\types.h"
struct passwd {
char *pw_name; /* user's login name */

View File

@ -6,13 +6,62 @@
#ifndef COMPAT_SIGNAL_H
#define COMPAT_SIGNAL_H 1
#include "w32posix.h"
/* signal related defs*/
/* supported signal types */
#define W32_SIGINT 0
#define W32_SIGSEGV 1
#define W32_SIGPIPE 2
#define W32_SIGCHLD 3
#define W32_SIGALRM 4
#define W32_SIGTSTP 5
#define W32_SIGHUP 6
#define W32_SIGQUIT 7
#define W32_SIGTERM 8
#define W32_SIGTTIN 9
#define W32_SIGTTOU 10
#define W32_SIGWINCH 11
#define W32_SIGMAX 12
/* these signals are not supposed to be raised on Windows*/
#define W32_SIGSTOP 13
#define W32_SIGABRT 14
#define W32_SIGFPE 15
#define W32_SIGILL 16
#define W32_SIGKILL 17
#define W32_SIGUSR1 18
#define W32_SIGUSR2 19
/* singprocmask "how" codes*/
#define SIG_BLOCK 0
#define SIG_UNBLOCK 1
#define SIG_SETMASK 2
typedef void(*sighandler_t)(int);
typedef int sigset_t;
#define sigemptyset(set) (memset( (set), 0, sizeof(sigset_t)))
#define sigaddset(set, sig) ( (*(set)) |= (0x80000000 >> (sig)))
#define sigismember(set, sig) ( (*(set) & (0x80000000 >> (sig)))?1:0 )
#define sigdelset(set, sig) ( (*(set)) &= (~( 0x80000000 >> (sig)) ) )
/* signal action codes*/
#define W32_SIG_ERR ((sighandler_t)-1)
#define W32_SIG_DFL ((sighandler_t)0)
#define W32_SIG_IGN ((sighandler_t)1)
sighandler_t w32_signal(int signum, sighandler_t handler);
#define signal(a,b) w32_signal((a), (b))
#define mysignal(a,b) w32_signal((a), (b))
int w32_raise(int sig);
#define raise(a) w32_raise(a)
int w32_kill(int pid, int sig);
#define kill(a,b) w32_kill((a), (b))
#define ftruncate(a, b) w32_ftruncate((a), (b))
int w32_sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
#define sigprocmask(a,b,c) w32_sigprocmask((a), (b), (c))
#define SIGINT W32_SIGINT

View File

@ -2,8 +2,16 @@
#include STDIO_H
/* stdio.h overrides */
FILE* w32_fopen_utf8(const char *, const char *);
#define fopen w32_fopen_utf8
/* stdio.h additional definitions */
#define popen _popen
#define pclose _pclose
FILE* w32_fdopen(int fd, const char *mode);
#define fdopen(a,b) w32_fdopen((a), (b))
int w32_rename(const char *old_name, const char *new_name);
#define rename w32_rename

View File

@ -0,0 +1,4 @@
#include "crtheaders.h"
#include STDLIB_H
#define environ _environ

View File

@ -1,8 +1,10 @@
#include "crtheaders.h"
#include STRING_H
#include "utf.h"
/* string.h overrides */
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
char *w32_strerror(int);
#define strerror w32_strerror
#define strdup _strdup

View File

@ -0,0 +1,6 @@
#pragma once
#define bzero(p,l) memset((void *)(p),0,(size_t)(l))
void
explicit_bzero(void *b, size_t len);

View File

@ -1,8 +1,17 @@
#ifndef COMPAT_IOCTL_H
#define COMPAT_IOCTL_H 1
#include "..\w32posix.h"
/*ioctl macros and structs*/
#define TIOCGWINSZ 1
struct winsize {
unsigned short ws_row; /* rows, in characters */
unsigned short ws_col; /* columns, in character */
unsigned short ws_xpixel; /* horizontal size, pixels */
unsigned short ws_ypixel; /* vertical size, pixels */
};
int w32_ioctl(int d, int request, ...);
#define ioctl w32_ioctl
#endif

View File

@ -1,10 +1 @@
#ifndef COMPAT_PARAM_H
#define COMPAT_PARAM_H 1
typedef unsigned int uid_t;
typedef unsigned int gid_t;
typedef long long off_t;
typedef unsigned int dev_t;
#endif
#pragma once

View File

@ -5,9 +5,30 @@
*/
#pragma once
#include "..\w32posix.h"
/* total fds that can be allotted */
#define MAX_FDS 256 /* a 2^n number */
typedef struct w32_fd_set_ {
unsigned char bitmap[MAX_FDS >> 3];
}w32_fd_set;
#define fd_set w32_fd_set
#undef FD_ZERO
#define FD_ZERO(set) (memset( (set), 0, sizeof(w32_fd_set)))
#undef FD_SET
#define FD_SET(fd,set) ( (set)->bitmap[(fd) >> 3] |= (0x80 >> ((fd) % 8)))
#undef FD_ISSET
#define FD_ISSET(fd, set) (( (set)->bitmap[(fd) >> 3] & (0x80 >> ((fd) % 8)))?1:0)
#undef FD_CLR
#define FD_CLR(fd, set) ((set)->bitmap[(fd) >> 3] &= (~(0x80 >> ((fd) % 8))))
#undef FD_SETSIZE
#define FD_SETSIZE MAX_FDS
int w32_select(int fds, w32_fd_set * , w32_fd_set * , w32_fd_set * ,
const struct timeval *);
#define select(a,b,c,d,e) w32_select((a), (b), (c), (d), (e))

View File

@ -3,22 +3,73 @@
*
* POSIX header and needed function definitions
*/
#pragma once
#include <WinSock2.h>
#include <WS2tcpip.h>
#include "..\w32posix.h"
/* Shutdown constants */
#define SHUT_WR SD_SEND
#define SHUT_RD SD_RECEIVE
#define SHUT_RDWR SD_BOTH
/* Other constants */
#define IN_LOOPBACKNET 127 /* 127.* is the loopback network */
#define MAXHOSTNAMELEN 64
#define EPFNOSUPPORT WSAEPFNOSUPPORT
/*network i/o*/
int w32_socket(int domain, int type, int protocol);
#define socket(a,b,c) w32_socket((a), (b), (c))
int w32_accept(int fd, struct sockaddr* addr, int* addrlen);
#define accept(a,b,c) w32_accept((a), (b), (c))
int w32_setsockopt(int fd, int level, int optname, const void* optval, int optlen);
#define setsockopt(a,b,c,d,e) w32_setsockopt((a), (b), (c), (d), (e))
int w32_getsockopt(int fd, int level, int optname, void* optval, int* optlen);
#define getsockopt(a,b,c,d,e) w32_getsockopt((a), (b), (c), (d), (e))
int w32_getsockname(int fd, struct sockaddr* name, int* namelen);
#define getsockname(a,b,c) w32_getsockname((a), (b), (c))
int w32_getpeername(int fd, struct sockaddr* name, int* namelen);
#define getpeername(a,b,c) w32_getpeername((a), (b), (c))
int w32_listen(int fd, int backlog);
#define listen(a,b) w32_listen((a), (b))
int w32_bind(int fd, const struct sockaddr *name, int namelen);
#define bind(a,b,c) w32_bind((a), (b), (c))
int w32_connect(int fd, const struct sockaddr* name, int namelen);
#define connect(a,b,c) w32_connect((a), (b), (c))
int w32_recv(int fd, void *buf, size_t len, int flags);
#define recv(a,b,c,d) w32_recv((a), (b), (c), (d))
int w32_send(int fd, const void *buf, size_t len, int flags);
#define send(a,b,c,d) w32_send((a), (b), (c), (d))
int w32_shutdown(int fd, int how);
#define shutdown(a,b) w32_shutdown((a), (b))
int w32_socketpair(int domain, int type, int protocol, int sv[2]);
#define socketpair(a,b,c,d) w32_socketpair((a), (b), (c), (d))
void w32_freeaddrinfo(struct addrinfo *);
#define freeaddrinfo w32_freeaddrinfo
int w32_getaddrinfo(const char *, const char *,
const struct addrinfo *, struct addrinfo **);
#define getaddrinfo w32_getaddrinfo
struct w32_pollfd {
int fd;
short events;
short revents;
};
#define pollfd w32_pollfd

View File

@ -1,28 +1,10 @@
/*
* Author: Manoj Ampalam <manoj.ampalam@microsoft.com>
*
* private stat.h (all code relying on POSIX wrapper should include this version
* instead of the one in Windows SDK.
*/
#pragma once
#include "..\fcntl.h"
#include "param.h"
#include "..\crtheaders.h"
#include SYS_STAT_H
/* flags COPIED FROM STAT.H
*/
#define _S_IFMT 0xF000 // File type mask
#define _S_IFDIR 0x4000 // Directory
#define _S_IFCHR 0x2000 // Character special
#define _S_IFIFO 0x1000 // Pipe
#define _S_IFREG 0x8000 // Regular
#define _S_IREAD 0x0100 // Read permission, owner
#define _S_IWRITE 0x0080 // Write permission, owner
#define _S_IEXEC 0x0040 // Execute/search permission, owner
#define _S_IFLNK 0xA000 // symbolic link
#define _S_IFSOCK 0xC000 // socket
#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
#define S_IFMT _S_IFMT
#define S_IFDIR _S_IFDIR
#define S_IFCHR _S_IFCHR
@ -33,13 +15,20 @@
#define S_IFLNK _S_IFLNK
#define S_IFSOCK _S_IFSOCK
/* TODO - is this the right place for these defs ?*/
# define S_ISUID 0x800
# define S_ISGID 0x400
int w32_fstat(int fd, struct w32_stat *buf);
#define fstat(a,b) w32_fstat((a), (b))
int w32_stat(const char *path, struct w32_stat *buf);
#define stat w32_stat
#define lstat w32_stat
int w32_mkdir(const char *pathname, unsigned short mode);
#define mkdir w32_mkdir
int w32_chmod(const char *, mode_t);
#define chmod w32_chmod
struct w32_stat {
@ -56,9 +45,5 @@ struct w32_stat {
__int64 st_ctime; /* time of last status change */
};
typedef unsigned short _mode_t;
typedef _mode_t mode_t;
void strmode(mode_t mode, char *p);
int w32_chmod(const char *, mode_t);
int w32_mkdir(const char *pathname, unsigned short mode);

View File

@ -0,0 +1,14 @@
#include "..\crtheaders.h"
#include SYS_TYPES_H
typedef _dev_t dev_t;
typedef _off_t off_t;
typedef unsigned int uid_t;
typedef unsigned int gid_t;
typedef unsigned short _mode_t;
typedef _mode_t mode_t;
typedef int ssize_t;
typedef int pid_t;
typedef unsigned int nfds_t;

View File

@ -1,7 +1,7 @@
#ifndef COMPAT_UIO_H
#define COMPAT_UIO_H 1
#pragma once
/* Compatibility header to avoid #ifdefs on Win32 */
#endif
struct iovec
{
void *iov_base;
size_t iov_len;
};

View File

@ -1,5 +1,4 @@
#pragma once
#include "..\w32posix.h"
//#define _W_INT(w) (*(int*)&(w)) /* convert union wait to int */
//#define WIFEXITED(w) (!((_W_INT(w)) & 0377))
@ -16,4 +15,7 @@
#define WNOHANG 1
#define WUNTRACED 2
/* wait pid options */
#define WNOHANG 1
int waitpid(int pid, int *status, int options);

View File

@ -3,48 +3,82 @@
*
* POSIX header and needed function definitions
*/
#ifndef COMPAT_UNISTD_H
#define COMPAT_UNISTD_H 1
#pragma once
#include "sys\types.h"
#include "fcntl.h"
#include "w32posix.h"
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
int w32_ftruncate(int, off_t);
#define ftruncate(a, b) w32_ftruncate((a), (b))
#define pipe w32_pipe
#define open w32_open
int w32_pipe(int *pfds);
#define read w32_read
int w32_read(int fd, void *dst, size_t max);
#define write w32_write
int w32_write(int fd, const void *buf, unsigned int max);
#define writev w32_writev
int w32_writev(int fd, const struct iovec *iov, int iovcnt);
int w32_isatty(int fd);
/* can't do this #define isatty w32_isatty
* as there is a variable in code named isatty*/
#define isatty(a) w32_isatty((a))
int w32_close(int fd);
#define close w32_close
int w32_dup(int oldfd);
#define dup w32_dup
int w32_dup2(int oldfd, int newfd);
#define dup2 w32_dup2
#define sleep(sec) Sleep(1000 * sec)
unsigned int w32_alarm(unsigned int seconds);
#define alarm w32_alarm
long w32_lseek(int fd, long offset, int origin);
#define lseek w32_lseek
#define getdtablesize() MAX_FDS
int w32_gethostname(char *, size_t);
#define gethostname w32_gethostname
int w32_fsync(int fd);
#define fsync(a) w32_fsync((a))
#define ftruncate(a, b) w32_ftruncate((a), (b))
int w32_symlink(const char *target, const char *linkpath);
#define symlink w32_symlink
int w32_chown(const char *pathname, unsigned int owner, unsigned int group);
#define chown w32_chown
int w32_unlink(const char *path);
#define unlink w32_unlink
int w32_rmdir(const char *pathname);
#define rmdir w32_rmdir
int w32_chdir(const char *dirname);
#define chdir w32_chdir
char *w32_getcwd(char *buffer, int maxlen);
#define getcwd w32_getcwd
int daemon(int nochdir, int noclose);
char *crypt(const char *key, const char *salt);
int link(const char *oldpath, const char *newpath);
int w32_symlink(const char *target, const char *linkpath);
int w32_chown(const char *pathname, unsigned int owner, unsigned int group);
int w32_unlink(const char *path);
int w32_rmdir(const char *pathname);
int w32_chdir(const char *dirname);
char *w32_getcwd(char *buffer, int maxlen);
int readlink(const char *path, char *link, int linklen);
#endif
int spawn_child(char* cmd, int in, int out, int err, unsigned long flags);

View File

@ -1,155 +0,0 @@
/*
* Author: Manoj Ampalam <manoj.ampalam@microsoft.com>
*
* Win32 renamed POSIX APIs
*/
#pragma once
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <stdio.h>
#include "defs.h"
#include "utf.h"
#include "sys\param.h"
typedef struct w32_fd_set_ {
unsigned char bitmap[MAX_FDS >> 3];
}w32_fd_set;
#define fd_set w32_fd_set
void w32posix_initialize();
void w32posix_done();
/*network i/o*/
int w32_socket(int domain, int type, int protocol);
int w32_accept(int fd, struct sockaddr* addr, int* addrlen);
int w32_setsockopt(int fd, int level, int optname, const void* optval, int optlen);
int w32_getsockopt(int fd, int level, int optname, void* optval, int* optlen);
int w32_getsockname(int fd, struct sockaddr* name, int* namelen);
int w32_getpeername(int fd, struct sockaddr* name, int* namelen);
int w32_listen(int fd, int backlog);
int w32_bind(int fd, const struct sockaddr *name, int namelen);
int w32_connect(int fd, const struct sockaddr* name, int namelen);
int w32_recv(int fd, void *buf, size_t len, int flags);
int w32_send(int fd, const void *buf, size_t len, int flags);
int w32_shutdown(int fd, int how);
int w32_socketpair(int domain, int type, int protocol, int sv[2]);
/*non-network (file) i/o*/
#undef fdopen
#define fdopen(a,b) w32_fdopen((a), (b))
#define fstat(a,b) w32_fstat((a), (b))
#define rename w32_rename
struct w32_stat;
int w32_pipe(int *pfds);
int w32_open(const char *pathname, int flags, ...);
int w32_read(int fd, void *dst, size_t max);
int w32_write(int fd, const void *buf, unsigned int max);
int w32_writev(int fd, const struct iovec *iov, int iovcnt);
int w32_fstat(int fd, struct w32_stat *buf);
int w32_stat(const char *path, struct w32_stat *buf);
long w32_lseek( int fd, long offset, int origin);
int w32_isatty(int fd);
FILE* w32_fdopen(int fd, const char *mode);
int w32_rename(const char *old_name, const char *new_name);
/*common i/o*/
#define fcntl(a,b,...) w32_fcntl((a), (b), __VA_ARGS__)
#define select(a,b,c,d,e) w32_select((a), (b), (c), (d), (e))
int w32_close(int fd);
int w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* exceptfds,
const struct timeval *timeout);
int w32_fcntl(int fd, int cmd, ... /* arg */);
int w32_dup(int oldfd);
int w32_dup2(int oldfd, int newfd);
/* misc */
unsigned int w32_alarm(unsigned int seconds);
sighandler_t w32_signal(int signum, sighandler_t handler);
int w32_sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
int w32_raise(int sig);
int w32_kill(int pid, int sig);
int w32_gethostname(char *, size_t);
void w32_freeaddrinfo(struct addrinfo *);
int w32_getaddrinfo(const char *, const char *,
const struct addrinfo *, struct addrinfo **);
FILE* w32_fopen_utf8(const char *, const char *);
int w32_ftruncate(int fd, off_t length);
char* w32_programdir();
int w32_fsync(int fd);
int w32_ioctl(int d, int request, ...);
/* Shutdown constants */
#define SHUT_WR SD_SEND
#define SHUT_RD SD_RECEIVE
#define SHUT_RDWR SD_BOTH
/* Other constants */
#define IN_LOOPBACKNET 127 /* 127.* is the loopback network */
#define MAXHOSTNAMELEN 64
/* Errno helpers */
#ifndef EXX
#define EXX WSAEMFILE
#endif
#ifndef EXX1
#define EXX1 WSAENOBUFS
#endif
#ifndef ESOCKTNOSUPPORT
#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
#endif
#ifndef ENOTUNREACH
#define ENOTUNREACH WSAENOTUNREACH
#endif
#ifndef EPFNOSUPPORT
#define EPFNOSUPPORT WSAEPFNOSUPPORT
#endif
int spawn_child(char* cmd, int in, int out, int err, DWORD flags);
/*
* these routines are temporarily defined here to allow transition
* from older POSIX wrapper to the newer one. After complete transition
* these should be gone or moved to a internal header.
*/
HANDLE w32_fd_to_handle(int fd);
int w32_allocate_fd_for_handle(HANDLE h, BOOL is_sock);
int sw_add_child(HANDLE child, DWORD pid);
/* temporary definitions to aid in transition */
#define sfd_to_handle(a) w32_fd_to_handle((a))
/* TODO - These defs need to revisited and positioned appropriately */
#define environ _environ
typedef unsigned int nfds_t;
struct w32_pollfd {
int fd;
SHORT events;
SHORT revents;
};
#define pollfd w32_pollfd
struct iovec
{
void *iov_base;
size_t iov_len;
};
#define bzero(p,l) memset((void *)(p),0,(size_t)(l))
void
explicit_bzero(void *b, size_t len);
void convertToBackslash(char *str);
void convertToForwardslash(char *str);

View File

@ -30,7 +30,6 @@
#include <Windows.h>
#include <stdio.h>
#include "inc\defs.h"
#include "sys\stat.h"
#include "inc\sys\statvfs.h"
#include "inc\sys\time.h"
@ -39,6 +38,10 @@
#include "misc_internal.h"
#include "inc\dlfcn.h"
#include "inc\dirent.h"
#include "inc\sys\types.h"
#include "inc\sys\ioctl.h"
#include "inc\fcntl.h"
#include "signal_internal.h"
int usleep(unsigned int useconds)
{
@ -254,7 +257,6 @@ int w32_ioctl(int d, int request, ...) {
}
}
HANDLE w32_fd_to_handle(int fd);
int
spawn_child(char* cmd, int in, int out, int err, DWORD flags) {
PROCESS_INFORMATION pi;
@ -314,7 +316,7 @@ spawn_child(char* cmd, int in, int out, int err, DWORD flags) {
b = CreateProcessW(NULL, cmd_utf16, NULL, NULL, TRUE, flags, NULL, NULL, &si, &pi);
if (b) {
if (sw_add_child(pi.hProcess, pi.dwProcessId) == -1) {
if (register_child(pi.hProcess, pi.dwProcessId) == -1) {
TerminateProcess(pi.hProcess, 0);
CloseHandle(pi.hProcess);
pi.dwProcessId = -1;

View File

@ -2,3 +2,11 @@
/* removes first '/' for Windows paths that are unix styled. Ex: /c:/ab.cd */
char * sanitized_path(const char *);
void w32posix_initialize();
void w32posix_done();
char* w32_programdir();
void convertToBackslash(char *str);
void convertToForwardslash(char *str);

View File

@ -28,7 +28,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "inc\sys\param.h"
#include "inc\sys\types.h"
/* uuidswap.c defs */
void temporarily_use_uid(struct passwd *pw){

View File

@ -45,8 +45,6 @@ static struct passwd pw;
static char* pw_shellpath = NULL;
#define SHELL_HOST "\\ssh-shellhost.exe"
char* w32_programdir();
int
initialize_pw() {
if (pw_shellpath == NULL) {

View File

@ -30,8 +30,21 @@
#include "w32fd.h"
#include <errno.h>
#include <signal.h>
#include "signal_internal.h"
#include "inc\signal.h"
#undef signal
#undef raise
#undef SIGINT
#undef SIGILL
#undef SIGPFE
#undef SIGSEGV
#undef SIGTERM
#undef SIGFPE
#undef SIGABRT
#undef SIG_DFL
#undef SIG_IGN
#undef SIG_ERR
#include <signal.h>
/* pending signals to be processed */
sigset_t pending_signals;
@ -106,14 +119,14 @@ sw_init_signal_handler_table() {
SetConsoleCtrlHandler(native_sig_handler, TRUE);
sigemptyset(&pending_signals);
/* this automatically sets all to SIG_DFL (0)*/
/* this automatically sets all to W32_SIG_DFL (0)*/
memset(sig_handlers, 0, sizeof(sig_handlers));
}
extern struct _children children;
sighandler_t
sw_signal(int signum, sighandler_t handler) {
w32_signal(int signum, sighandler_t handler) {
sighandler_t prev;
debug2("signal() sig:%d, handler:%p", signum, handler);
@ -128,7 +141,7 @@ sw_signal(int signum, sighandler_t handler) {
}
int
sw_sigprocmask(int how, const sigset_t *set, sigset_t *oldset) {
w32_sigprocmask(int how, const sigset_t *set, sigset_t *oldset) {
/* this is only used by sshd to block SIGCHLD while doing waitpid() */
/* our implementation of waidpid() is never interrupted, so no need to implement this for now*/
debug3("sigprocmask() how:%d");
@ -138,7 +151,7 @@ sw_sigprocmask(int how, const sigset_t *set, sigset_t *oldset) {
int
sw_raise(int sig) {
w32_raise(int sig) {
debug("raise sig:%d", sig);
if (sig == W32_SIGSEGV)
return raise(SIGSEGV); /* raise native exception handler*/
@ -196,7 +209,7 @@ sw_process_pending_signals() {
for (i = 0; i < (sizeof(exp) / sizeof(exp[0])); i++) {
if (sigismember(&pending_tmp, exp[i])) {
if (sig_handlers[exp[i]] != W32_SIG_IGN) {
sw_raise(exp[i]);
w32_raise(exp[i]);
/* dont error EINTR for SIG_ALRM, */
/* sftp client is not expecting it */
if (exp[i] != W32_SIGALRM)

View File

@ -1,12 +1,4 @@
#include <Windows.h>
#include "inc\defs.h"
int sw_initialize();
sighandler_t sw_signal(int signum, sighandler_t handler);
int sw_sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
int sw_raise(int sig);
int sw_kill(int pid, int sig);
/* child processes */
#define MAX_CHILDREN 50
@ -25,7 +17,9 @@ struct _children {
DWORD num_zombies;
};
int sw_add_child(HANDLE child, DWORD pid);
int sw_initialize();
int register_child(HANDLE child, DWORD pid);
int sw_remove_child_at_index(DWORD index);
int sw_child_to_zombie(DWORD index);
void sw_cleanup_child_zombies();
@ -36,4 +30,3 @@ struct _timer_info {
__int64 run_time_sec; /* time in seconds, timer is set to go off from ticks_at_start */
};
int sw_init_timer();
unsigned int sw_alarm(unsigned int seconds);

View File

@ -29,6 +29,7 @@
*/
#include "signal_internal.h"
#include "inc\signal.h"
struct _timer_info timer_info;
extern sigset_t pending_signals;
@ -43,7 +44,7 @@ sigalrm_APC(
}
unsigned int
sw_alarm(unsigned int sec) {
w32_alarm(unsigned int sec) {
LARGE_INTEGER due;
ULONGLONG sec_passed;
int ret = 0;

View File

@ -29,11 +29,12 @@
*/
#include "signal_internal.h"
#include "inc\sys\wait.h"
struct _children children;
int
sw_add_child(HANDLE child, DWORD pid) {
register_child(HANDLE child, DWORD pid) {
DWORD first_zombie_index;
debug("Register child %p pid %d, %d zombies of %d", child, pid,
@ -128,10 +129,10 @@ sw_child_to_zombie(DWORD index) {
}
int
sw_kill(int pid, int sig) {
w32_kill(int pid, int sig) {
int child_index, i;
if (pid == GetCurrentProcessId())
return sw_raise(sig);
return w32_raise(sig);
/* for child processes - only SIGTERM supported*/
child_index = -1;

View File

@ -1,7 +1,6 @@
#include <Windows.h>
#include "w32fd.h"
#include "tncon.h"
#include "inc\defs.h"
#include "inc\utf.h"
#define TERM_IO_BUF_SIZE 2048

View File

@ -29,7 +29,13 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "inc\w32posix.h"
#include "inc\sys\socket.h"
#include "inc\sys\select.h"
#include "inc\sys\uio.h"
#include "inc\sys\types.h"
#include "inc\unistd.h"
#include "inc\fcntl.h"
#include "w32fd.h"
#include "signal_internal.h"
#include <stdarg.h>
@ -804,30 +810,6 @@ int w32_allocate_fd_for_handle(HANDLE h, BOOL is_sock) {
}
unsigned int
w32_alarm(unsigned int seconds) {
return sw_alarm(seconds);;
}
sighandler_t
w32_signal(int signum, sighandler_t handler) {
return sw_signal(signum, handler);
}
int
w32_sigprocmask(int how, const sigset_t *set, sigset_t *oldset) {
return sw_sigprocmask(how, set, oldset);
}
int
w32_raise(int sig) {
return sw_raise(sig);
}
int
w32_kill(int pid, int sig) {
return sw_kill(pid, sig);
}
int
w32_ftruncate(int fd, off_t length) {
CHECK_FD(fd);

View File

@ -8,7 +8,6 @@
#include <Windows.h>
#include <stdio.h>
#include "inc\defs.h"
enum w32_io_type {
UNKNOWN_FD = 0,

View File

@ -32,14 +32,14 @@
#include <Windows.h>
#include "inc\utf.h"
#include "misc_internal.h"
int main(int, char **);
void w32posix_initialize();
int
wmain(int argc, wchar_t **wargv) {
char** argv = NULL;
int i;
int i,r;
if (argc) {
if ((argv = malloc(argc * sizeof(char*))) == NULL)
@ -49,5 +49,7 @@ wmain(int argc, wchar_t **wargv) {
}
w32posix_initialize();
return main(argc, argv);
r = main(argc, argv);
w32posix_done();
return r;
}

View File

@ -35,9 +35,9 @@
#include <Windows.h>
#include <wchar.h>
#include "inc\utf.h"
#include "misc_internal.h"
int main(int, char **);
void w32posix_initialize();
extern HANDLE main_thread;
extern int is_child;
@ -97,10 +97,9 @@ static VOID WINAPI service_handler(DWORD dwControl)
ReportSvcStatus(service_status.dwCurrentState, NO_ERROR, 0);
}
char* w32_programdir();
int sshd_main(int argc, wchar_t **wargv) {
char** argv = NULL;
int i;
int i, r;
if (argc) {
if ((argv = malloc(argc * sizeof(char*))) == NULL)
@ -118,7 +117,9 @@ int sshd_main(int argc, wchar_t **wargv) {
_wchdir(path_utf16);
free(path_utf16);
return main(argc, argv);
r = main(argc, argv);
w32posix_done();
return r;
}
int wmain(int argc, wchar_t **wargv) {

View File

@ -239,12 +239,10 @@ void console_io_test()
void
file_tests()
{
w32posix_initialize();
//console_io_test();
//file_simple_fileio();
file_blocking_io_tests();
file_nonblocking_io_tests();
file_select_tests();
w32posix_done();
}

View File

@ -613,12 +613,10 @@ socket_typical_ssh_payload_tests() {
void
socket_tests()
{
w32posix_initialize();
socket_fd_tests();
socket_blocking_io_tests();
socket_nonblocking_io_tests();
socket_select_tests();
socket_typical_ssh_payload_tests();
w32posix_done();
}

4
scp.c
View File

@ -387,14 +387,12 @@ do_cmd2(char *host, char *remuser, char *cmd, int fdin, int fdout)
size_t cmdlen = 0;
char** list = args.list;
cmdlen = strlen(w32_programdir()) + 2;
cmdlen = 1; /* null term */
while (*list)
cmdlen += strlen(*list++) + 1;
full_cmd = xmalloc(cmdlen);
full_cmd[0] = '\0';
strcat(full_cmd, w32_programdir());
strcat(full_cmd, "\\");
list = args.list;
while (*list) {
strcat(full_cmd, *list++);

View File

@ -450,6 +450,9 @@ void setup_session_vars(Session* s)
free(pw_dir_w);
}
char* w32_programdir();
int register_child(void* child, unsigned long pid);
int do_exec_windows(Session *s, const char *command, int pty) {
int pipein[2], pipeout[2], pipeerr[2], r;
char *exec_command = NULL, *progdir = w32_programdir();
@ -548,9 +551,9 @@ int do_exec_windows(Session *s, const char *command, int pty) {
si.cbReserved2 = 0;
si.lpReserved2 = 0;
si.hStdInput = (HANDLE)sfd_to_handle(pipein[0]);
si.hStdOutput = (HANDLE)sfd_to_handle(pipeout[1]);
si.hStdError = (HANDLE)sfd_to_handle(pipeerr[1]);
si.hStdInput = (HANDLE)w32_fd_to_handle(pipein[0]);
si.hStdOutput = (HANDLE)w32_fd_to_handle(pipeout[1]);
si.hStdError = (HANDLE)w32_fd_to_handle(pipeerr[1]);
si.lpDesktop = NULL;
hToken = s->authctxt->methoddata;
@ -605,7 +608,7 @@ int do_exec_windows(Session *s, const char *command, int pty) {
CloseHandle(pi.hThread);
s->pid = pi.dwProcessId;
sw_add_child(pi.hProcess, pi.dwProcessId);
register_child(pi.hProcess, pi.dwProcessId);
}
/*
* Set interactive/non-interactive mode.

4
sshd.c
View File

@ -1302,9 +1302,9 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
if (path_utf8 == NULL)
fatal("Failed to alloc memory");
if (snprintf(fd_handle, sizeof(fd_handle), "%p", sfd_to_handle(*newsock)) == -1
if (snprintf(fd_handle, sizeof(fd_handle), "%p", w32_fd_to_handle(*newsock)) == -1
|| SetEnvironmentVariable("SSHD_REMSOC", fd_handle) == FALSE
|| snprintf(fd_handle, sizeof(fd_handle), "%p", sfd_to_handle(startup_p[1])) == -1
|| snprintf(fd_handle, sizeof(fd_handle), "%p", w32_fd_to_handle(startup_p[1])) == -1
|| SetEnvironmentVariable("SSHD_STARTUPSOC", fd_handle) == FALSE
|| fcntl(startup_p[0], F_SETFD, FD_CLOEXEC) == -1) {
error("unable to set the right environment for child, closing connection ");