mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-24 22:45:17 +02:00
Moved win specific logging code from each exe to win32iocompat
This commit is contained in:
parent
d94011a37e
commit
65ccbe645c
@ -157,7 +157,6 @@
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\startupneeds.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\strcasecmp.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\stringhelp.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\syslog.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tncon.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tnnet.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\win32auth.c" />
|
||||
@ -197,7 +196,6 @@
|
||||
<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" />
|
||||
|
@ -75,9 +75,6 @@
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\stringhelp.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\syslog.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tncon.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -87,10 +84,10 @@
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\win32auth.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\cng_dh.c">
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\cng_openssl_dh.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\cng_openssl_dh.c">
|
||||
<ClCompile Include="..\win32compat\cng_dh.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
@ -158,9 +155,6 @@
|
||||
<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>
|
||||
|
@ -147,6 +147,7 @@
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\fileio.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\termio.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\misc.c" />
|
||||
<ClCompile Include="..\win32compat\w32log.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\w32fd.h" />
|
||||
@ -162,6 +163,7 @@
|
||||
<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="..\win32compat\inc\syslog.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -7,6 +7,7 @@
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\fileio.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\termio.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\misc.c" />
|
||||
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\log.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\w32fd.h" />
|
||||
@ -46,6 +47,9 @@
|
||||
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\sys\statvfs.h">
|
||||
<Filter>inc\sys</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\win32compat\inc\syslog.h">
|
||||
<Filter>inc</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="inc">
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef COMPAT_SYSLOG_H
|
||||
#define COMPAT_SYSLOG_H 1
|
||||
#pragma once
|
||||
|
||||
|
||||
/* Compatibility header to give us some syslog-like functionality on Win32 */
|
||||
@ -27,4 +26,3 @@ void openlog (char *, unsigned int, int);
|
||||
void closelog (void);
|
||||
void syslog (int, const char *, const char *);
|
||||
|
||||
#endif
|
42
contrib/win32/win32compat/w32log.c
Normal file
42
contrib/win32/win32compat/w32log.c
Normal file
@ -0,0 +1,42 @@
|
||||
|
||||
#include <Windows.h>
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include "inc\syslog.h"
|
||||
|
||||
#define MSGBUFSIZ 1024
|
||||
static int logfd = -1;
|
||||
|
||||
void openlog(char *ident, unsigned int option, int facility) {
|
||||
if ((logfd == -1) && (ident != NULL)) {
|
||||
char path[MAX_PATH];
|
||||
GetModuleFileNameA(NULL, path, MAX_PATH);
|
||||
path[MAX_PATH - 1] = '\0';
|
||||
memcpy(path + strlen(path) - 3, "log", 3);
|
||||
logfd = _open(path, O_WRONLY | O_CREAT | O_APPEND,
|
||||
S_IREAD | S_IWRITE);
|
||||
if (logfd != -1)
|
||||
SetHandleInformation((HANDLE)_get_osfhandle(logfd),
|
||||
HANDLE_FLAG_INHERIT, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void closelog(void) {
|
||||
//NOOP
|
||||
}
|
||||
|
||||
void
|
||||
syslog(int priority, const char *format, const char *formatBuffer) {
|
||||
char msgbufTimestamp[MSGBUFSIZ];
|
||||
SYSTEMTIME st;
|
||||
|
||||
if (logfd == -1)
|
||||
return;
|
||||
|
||||
GetLocalTime(&st);
|
||||
snprintf(msgbufTimestamp, sizeof msgbufTimestamp, "%d %02d:%02d:%02d %03d %s\n",
|
||||
GetCurrentProcessId(), st.wHour, st.wMinute, st.wSecond,
|
||||
st.wMilliseconds, formatBuffer);
|
||||
_write(logfd, msgbufTimestamp, strlen(msgbufTimestamp));
|
||||
}
|
41
log.c
41
log.c
@ -52,15 +52,6 @@
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#ifdef WIN32_FIXME
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <Shlwapi.h>
|
||||
|
||||
int logfd = 0;
|
||||
|
||||
#endif
|
||||
|
||||
static LogLevel log_level = SYSLOG_LEVEL_INFO;
|
||||
static int log_on_stderr = 1;
|
||||
static int log_stderr_fd = STDERR_FILENO;
|
||||
@ -450,43 +441,20 @@ do_log(LogLevel level, const char *fmt, va_list args)
|
||||
log_on_stderr ? LOG_STDERR_VIS : LOG_SYSLOG_VIS);
|
||||
#endif
|
||||
|
||||
#ifndef WIN32_FIXME
|
||||
if (log_handler != NULL) {
|
||||
/* Avoid recursion */
|
||||
tmp_handler = log_handler;
|
||||
log_handler = NULL;
|
||||
tmp_handler(level, fmtbuf, log_handler_ctx);
|
||||
log_handler = tmp_handler;
|
||||
} else
|
||||
#endif
|
||||
if (log_on_stderr) {
|
||||
} else if (log_on_stderr) {
|
||||
snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf);
|
||||
#ifdef WIN32_FIXME
|
||||
_write(STDERR_FILENO, msgbuf, strlen(msgbuf));
|
||||
_write(STDERR_FILENO, msgbuf, strlen(msgbuf));
|
||||
#else
|
||||
(void)write(log_stderr_fd, msgbuf, strlen(msgbuf));
|
||||
#endif
|
||||
|
||||
(void)write(log_stderr_fd, msgbuf, strlen(msgbuf));
|
||||
#endif
|
||||
} else {
|
||||
|
||||
#ifdef WIN32_FIXME
|
||||
|
||||
if (logfd > 0)
|
||||
{
|
||||
char msgbufTimestamp[MSGBUFSIZ];
|
||||
|
||||
SYSTEMTIME st;
|
||||
|
||||
GetLocalTime(&st);
|
||||
|
||||
snprintf(msgbufTimestamp, sizeof msgbufTimestamp, "%d %02d:%02d:%02d %03d %s\n",
|
||||
GetCurrentProcessId(), st.wHour, st.wMinute, st.wSecond,
|
||||
st.wMilliseconds, msgbuf);
|
||||
|
||||
_write(logfd, msgbufTimestamp, strlen(msgbufTimestamp));
|
||||
}
|
||||
|
||||
#else
|
||||
#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
|
||||
openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata);
|
||||
syslog_r(pri, &sdata, "%.500s", fmtbuf);
|
||||
@ -495,7 +463,6 @@ do_log(LogLevel level, const char *fmt, va_list args)
|
||||
openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility);
|
||||
syslog(pri, "%.500s", fmtbuf);
|
||||
closelog();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
errno = saved_errno;
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "test_helper.h"
|
||||
|
||||
extern void log_init(char *av0, int level, int facility, int on_stderr);
|
||||
extern int logfd;
|
||||
|
||||
void socket_tests();
|
||||
void file_tests();
|
||||
@ -18,9 +17,7 @@ void tests(void)
|
||||
{
|
||||
_set_abort_behavior(0, 1);
|
||||
log_init(NULL, 7, 2, 0);
|
||||
logfd = _open("unittests.log", O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE );
|
||||
socket_tests();
|
||||
file_tests();
|
||||
if (logfd > 0) _close(logfd);
|
||||
return;
|
||||
}
|
@ -90,14 +90,6 @@
|
||||
|
||||
#define realpath realpathWin32
|
||||
|
||||
|
||||
/*
|
||||
* Handle to log file.
|
||||
*/
|
||||
|
||||
extern int logfd;
|
||||
extern int sfd_start;
|
||||
|
||||
#endif /* WIN32_FIXME */
|
||||
|
||||
/* Our verbosity */
|
||||
@ -1998,27 +1990,11 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
|
||||
|
||||
extern char *optarg;
|
||||
extern char *__progname;
|
||||
#ifdef WIN32_FIXME
|
||||
|
||||
/*
|
||||
* Initialize Win32 log.
|
||||
*/
|
||||
|
||||
logfd = _open("sftp-server.log", O_WRONLY | O_CREAT | O_APPEND , S_IREAD | S_IWRITE);
|
||||
|
||||
log_level = SYSLOG_LEVEL_INFO;
|
||||
|
||||
__progname = ssh_get_progname(argv[0]);
|
||||
|
||||
log_init(__progname, log_level, log_facility, log_stderr);
|
||||
|
||||
#else
|
||||
|
||||
__progname = ssh_get_progname(argv[0]);
|
||||
log_init(__progname, log_level, log_facility, log_stderr);
|
||||
|
||||
#endif
|
||||
pw = pwcopy(user_pw);
|
||||
pw = pwcopy(user_pw);
|
||||
|
||||
|
||||
while (!skipargs && (ch = getopt(argc, argv,
|
||||
|
32
sshd.c
32
sshd.c
@ -193,8 +193,6 @@ FIXME: GFPZR: Function stat() may be undeclared.
|
||||
|
||||
char *fake_fork_args;
|
||||
|
||||
extern int logfd;
|
||||
extern int sfd_start;
|
||||
#endif
|
||||
|
||||
/* re-exec */
|
||||
@ -1967,33 +1965,6 @@ main(int ac, char **av)
|
||||
SetConsoleCtrlHandler(CtrlHandlerRoutine, TRUE);
|
||||
|
||||
w32posix_initialize();
|
||||
//authctxt -> hTokenLsa_ = NULL;
|
||||
|
||||
/*WSHELPinitialize();
|
||||
|
||||
allocate_standard_descriptor(STDIN_FILENO);
|
||||
allocate_standard_descriptor(STDOUT_FILENO);
|
||||
allocate_standard_descriptor(STDERR_FILENO);
|
||||
|
||||
sfd_start = 3;*/
|
||||
|
||||
/*
|
||||
* Initialize log.
|
||||
*/
|
||||
|
||||
logfd = _open("sshd.log", O_WRONLY | O_CREAT | O_APPEND,
|
||||
S_IREAD | S_IWRITE );
|
||||
|
||||
/*
|
||||
* Forbid to inherit log file handle.
|
||||
*/
|
||||
|
||||
if (SetHandleInformation(_get_osfhandle(logfd),
|
||||
HANDLE_FLAG_INHERIT, 0) == FALSE)
|
||||
{
|
||||
debug("ERROR: Cannot clear inherit flag for logfd handle. "
|
||||
"Error code : %u.", GetLastError());
|
||||
}
|
||||
|
||||
#endif /* WIN32_FIXME */
|
||||
|
||||
@ -2190,9 +2161,6 @@ main(int ac, char **av)
|
||||
/*
|
||||
* Win32 only.
|
||||
*/
|
||||
|
||||
//WSHELPinitialize();
|
||||
w32posix_initialize();
|
||||
|
||||
/*
|
||||
* Handle install and uninstall service options
|
||||
|
Loading…
x
Reference in New Issue
Block a user