aboutsummaryrefslogtreecommitdiffstats
path: root/SoftHSMv2/src/lib/win32
diff options
context:
space:
mode:
Diffstat (limited to 'SoftHSMv2/src/lib/win32')
-rw-r--r--SoftHSMv2/src/lib/win32/dllmain.cc18
-rw-r--r--SoftHSMv2/src/lib/win32/setenv.cpp20
-rw-r--r--SoftHSMv2/src/lib/win32/setenv.h12
-rw-r--r--SoftHSMv2/src/lib/win32/syslog.cpp69
-rw-r--r--SoftHSMv2/src/lib/win32/syslog.h46
5 files changed, 165 insertions, 0 deletions
diff --git a/SoftHSMv2/src/lib/win32/dllmain.cc b/SoftHSMv2/src/lib/win32/dllmain.cc
new file mode 100644
index 0000000..359227d
--- /dev/null
+++ b/SoftHSMv2/src/lib/win32/dllmain.cc
@@ -0,0 +1,18 @@
+#include <windows.h>
+
+__declspec(dllexport) BOOL WINAPI
+DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpvReserved)
+{
+ hModule = hModule;
+ lpvReserved = lpvReserved;
+
+ switch (ul_reason_for_call) {
+ case DLL_PROCESS_ATTACH:
+ case DLL_THREAD_ATTACH:
+ case DLL_THREAD_DETACH:
+ case DLL_PROCESS_DETACH:
+ default:
+ break;
+ }
+ return (TRUE);
+}
diff --git a/SoftHSMv2/src/lib/win32/setenv.cpp b/SoftHSMv2/src/lib/win32/setenv.cpp
new file mode 100644
index 0000000..da41a62
--- /dev/null
+++ b/SoftHSMv2/src/lib/win32/setenv.cpp
@@ -0,0 +1,20 @@
+#include <config.h>
+#include <stdlib.h>
+#include <string>
+
+#ifdef _WIN32
+
+int
+setenv(const char *name, const char *value, int overwrite)
+{
+ std::string vv = name;
+ vv += "=";
+ vv += value;
+
+ if (overwrite != 1)
+ return false;
+
+ return _putenv(vv.c_str()) == 0;
+}
+
+#endif
diff --git a/SoftHSMv2/src/lib/win32/setenv.h b/SoftHSMv2/src/lib/win32/setenv.h
new file mode 100644
index 0000000..e199227
--- /dev/null
+++ b/SoftHSMv2/src/lib/win32/setenv.h
@@ -0,0 +1,12 @@
+#include <config.h>
+
+#ifdef _WIN32
+
+#ifndef _SETENV_H
+#define _SETENV_H
+
+int setenv(const char *name, const char *value, int overwrite);
+
+#endif
+
+#endif \ No newline at end of file
diff --git a/SoftHSMv2/src/lib/win32/syslog.cpp b/SoftHSMv2/src/lib/win32/syslog.cpp
new file mode 100644
index 0000000..927592e
--- /dev/null
+++ b/SoftHSMv2/src/lib/win32/syslog.cpp
@@ -0,0 +1,69 @@
+#include <config.h>
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+
+#ifdef _WIN32
+
+static HANDLE hEventLog = NULL;
+
+/*
+ * Close the Handle to the application Event Log
+ */
+void
+closelog() {
+ DeregisterEventSource(hEventLog);
+}
+
+/*
+ * Initialize event logging
+ */
+void
+openlog(const char *ident, int logopt, int facility) {
+ /* Get a handle to the Application event log */
+ hEventLog = RegisterEventSourceA(NULL, ident);
+}
+
+/*
+ * Log to the NT Event Log
+ */
+void
+syslog(int priority, const char *message, ...) {
+ va_list ap;
+ char buf[1024];
+ LPCSTR str[1];
+
+ str[0] = buf;
+
+ va_start(ap, message);
+ vsprintf(buf, message, ap);
+ va_end(ap);
+
+ /* Make sure that the channel is open to write the event */
+ if (hEventLog == NULL) {
+ openlog("SoftHSM", 0, 0);
+ }
+ if (hEventLog != NULL) {
+ switch (priority) {
+ case LOG_INFO:
+ case LOG_NOTICE:
+ case LOG_DEBUG:
+ ReportEventA(hEventLog, EVENTLOG_INFORMATION_TYPE, 0,
+ 0x40000003, NULL, 1, 0, str, NULL);
+ break;
+ case LOG_WARNING:
+ ReportEventA(hEventLog, EVENTLOG_WARNING_TYPE, 0,
+ 0x80000002, NULL, 1, 0, str, NULL);
+ break;
+ default:
+ ReportEventA(hEventLog, EVENTLOG_ERROR_TYPE, 0,
+ 0xc0000001, NULL, 1, 0, str, NULL);
+ break;
+ }
+ }
+}
+
+#endif
diff --git a/SoftHSMv2/src/lib/win32/syslog.h b/SoftHSMv2/src/lib/win32/syslog.h
new file mode 100644
index 0000000..1ed207c
--- /dev/null
+++ b/SoftHSMv2/src/lib/win32/syslog.h
@@ -0,0 +1,46 @@
+#ifndef _SYSLOG_H
+#define _SYSLOG_H
+
+#include <stdio.h>
+
+/* priorities */
+#define LOG_EMERG 0 /* system is unusable */
+#define LOG_ALERT 1 /* action must be taken immediately */
+#define LOG_CRIT 2 /* critical conditions */
+#define LOG_ERR 3 /* error conditions */
+#define LOG_WARNING 4 /* warning conditions */
+#define LOG_NOTICE 5 /* normal but signification condition */
+#define LOG_INFO 6 /* informational */
+#define LOG_DEBUG 7 /* debug-level messages */
+
+/* NT event log does not support facility level */
+#define LOG_KERN 0
+#define LOG_USER 0
+#define LOG_MAIL 0
+#define LOG_DAEMON 0
+#define LOG_AUTH 0
+#define LOG_SYSLOG 0
+#define LOG_LPR 0
+#define LOG_LOCAL0 0
+#define LOG_LOCAL1 0
+#define LOG_LOCAL2 0
+#define LOG_LOCAL3 0
+#define LOG_LOCAL4 0
+#define LOG_LOCAL5 0
+#define LOG_LOCAL6 0
+#define LOG_LOCAL7 0
+
+/* Constant definitions for openlog() */
+#define LOG_PID 1
+#define LOG_CONS 2
+
+void
+closelog(void);
+
+void
+openlog(const char *ident, int logopt, int facility);
+
+void
+syslog(int priority, const char *message, ...);
+
+#endif