#endif /* SYS_WINNT */
extern char *progname;
+/*
+ * This routine adds the contents of a buffer to the log
+ */
+void
+addto_syslog(int level, char * buf)
+{
+ char *prog;
+ FILE *out_file;
+
+#if !defined(VMS) && !defined (SYS_VXWORKS)
+ if (syslogit)
+ syslog(level, "%s", buf);
+ else
+#endif /* VMS && SYS_VXWORKS*/
+ {
+ out_file = syslog_file ? syslog_file: level <= LOG_ERR ? stderr : stdout;
+ /* syslog() provides the timestamp, so if we're not using
+ syslog, we must provide it. */
+ prog = strrchr(progname, separator);
+ if (prog == NULL)
+ prog = progname;
+ else
+ prog++;
+ (void) fprintf(out_file, "%s ", humanlogtime ());
+ (void) fprintf(out_file, "%s[%d]: %s", prog, (int)getpid(), buf);
+ fflush (out_file);
+ }
+}
+void
+format_errmsg(char *nfmt, int lennfmt, const char *fmt, int errval)
+{
+ register char c;
+ register char *n, *prog;
+ register const char *f;
+
+ char *err;
+
+ n = nfmt;
+ f = fmt;
+ while ((c = *f++) != '\0' && n < (nfmt+lennfmt - 2)) {
+ if (c != '%') {
+ *n++ = c;
+ continue;
+ }
+ if ((c = *f++) != 'm') {
+ *n++ = '%';
+ *n++ = c;
+ continue;
+ }
+ err = 0;
+ err = strerror(errval);
+ /* Make sure we have enough space for the error message */
+ if ((n + strlen(err)) < (nfmt + lennfmt -2)) {
+ strcpy(n, err);
+ n += strlen(err);
+ }
+ }
+#if !defined(VMS)
+ if (!syslogit)
+#endif /* VMS */
+ *n++ = '\n';
+ *n = '\0';
+}
+
+/*
+ * The externally called functions are defined here
+ * but share the internal function above to fetch
+ * any error message strings, This is done so that we can
+ * have two different functions to perform the logging
+ * since Windows gets it's error information from different
+ * places depending on whether or not it's network I/O.
+ * msyslog() is for general use while netsyslog() is for
+ * network I/O functions. They are virtually identical
+ * in implementation.
+ */
+
#if defined(__STDC__) || defined(HAVE_STDARG_H)
void msyslog(int level, const char *fmt, ...)
#else /* defined(__STDC__) || defined(HAVE_STDARG_H) */
#endif
va_list ap;
char buf[1025], nfmt[256];
- register char c;
- register char *n, *prog;
- register const char *f;
+ register char *prog;
/*
* Save the error value as soon as possible
*/
#ifdef SYS_WINNT
- int olderrno = GetLastError();
+ int errval = GetLastError();
#else
- int olderrno = errno;
+ int errval = errno;
#endif
char *err;
level = va_arg(ap, int);
fmt = va_arg(ap, char *);
#endif
-
- n = nfmt;
- f = fmt;
- while ((c = *f++) != '\0' && c != '\n' && n < &nfmt[252]) {
- if (c != '%') {
- *n++ = c;
- continue;
- }
- if ((c = *f++) != 'm') {
- *n++ = '%';
- *n++ = c;
- continue;
- }
- err = 0;
- err = strerror(olderrno);
- if ((n + strlen(err)) < &nfmt[254]) {
- strcpy(n, err);
- n += strlen(err);
- }
- }
-#if !defined(VMS)
- if (!syslogit)
-#endif /* VMS */
- *n++ = '\n';
- *n = '\0';
+ format_errmsg(nfmt, sizeof(nfmt), fmt, errval);
vsnprintf(buf, sizeof(buf), nfmt, ap);
#if DEBUG
if (debug)
printf("msyslog: %s\n", buf);
#endif
-#if !defined(VMS) && !defined (SYS_VXWORKS)
- if (syslogit)
- syslog(level, "%s", buf);
- else
-#endif /* VMS && SYS_VXWORKS*/
- {
- FILE *out_file = syslog_file ? syslog_file
- : level <= LOG_ERR ? stderr : stdout;
- /* syslog() provides the timestamp, so if we're not using
- syslog, we must provide it. */
- prog = strrchr(progname, separator);
- if (prog == NULL)
- prog = progname;
- else
- prog++;
- (void) fprintf(out_file, "%s ", humanlogtime ());
- (void) fprintf(out_file, "%s[%d]: %s", prog, (int)getpid(), buf);
- fflush (out_file);
- }
+ addto_syslog(level, buf);
+ va_end(ap);
+}
+#if defined(__STDC__) || defined(HAVE_STDARG_H)
+void netsyslog(int level, const char *fmt, ...)
+#else /* defined(__STDC__) || defined(HAVE_STDARG_H) */
+ /*VARARGS*/
+ void netsyslog(va_alist)
+ va_dcl
+#endif /* defined(__STDC__) || defined(HAVE_STDARG_H) */
+{
+#if defined(__STDC__) || defined(HAVE_STDARG_H)
+#else
+ int level;
+ const char *fmt;
+#endif
+ va_list ap;
+ char buf[1025], nfmt[256];
+ register char *prog;
+
+ /*
+ * Save the error value as soon as possible
+ */
+#ifdef SYS_WINNT
+ int errval = WSAGetLastError();
+#else
+ int errval = errno;
+#endif
+ char *err;
+
+#if defined(__STDC__) || defined(HAVE_STDARG_H)
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+
+ level = va_arg(ap, int);
+ fmt = va_arg(ap, char *);
+#endif
+ format_errmsg(nfmt, sizeof(nfmt), fmt, errval);
+
+ vsnprintf(buf, sizeof(buf), nfmt, ap);
+#if DEBUG
+ if (debug)
+ printf("netsyslog: %s\n", buf);
+#endif
+ addto_syslog(level, buf);
va_end(ap);
}
--- /dev/null
+/* Microsoft Developer Support Copyright (c) 1993 Microsoft Corporation. */
+
+/* Skip asynch rpc inclusion */
+#ifndef __RPCASYNC_H__
+#define __RPCASYNC_H__
+#endif
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "messages.h"
+#include "log.h"
+
+#define PERR(bSuccess, api) {if(!(bSuccess)) printf("%s: Error %d from %s \
+ on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
+
+
+/*********************************************************************
+* FUNCTION: addSourceToRegistry(LPSTR pszAppname, LPSTR pszMsgDLL) *
+* *
+* PURPOSE: Add a source name key, message DLL name value, and *
+* message type supported value to the registry *
+* *
+* INPUT: source name, path of message DLL *
+* *
+* RETURNS: none *
+*********************************************************************/
+
+void addSourceToRegistry(LPSTR pszAppname, LPSTR pszMsgDLL)
+{
+ HKEY hk; /* registry key handle */
+ DWORD dwData;
+ BOOL bSuccess;
+ char regarray[200];
+ char *lpregarray = regarray;
+
+ /* When an application uses the RegisterEventSource or OpenEventLog
+ function to get a handle of an event log, the event loggging service
+ searches for the specified source name in the registry. You can add a
+ new source name to the registry by opening a new registry subkey
+ under the Application key and adding registry values to the new
+ subkey. */
+
+ strcpy(lpregarray, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\");
+ strcat(lpregarray, pszAppname);
+
+ /* Create a new key for our application */
+ bSuccess = RegCreateKey(HKEY_LOCAL_MACHINE,lpregarray, &hk);
+ PERR(bSuccess == ERROR_SUCCESS, "RegCreateKey");
+
+ /* Add the Event-ID message-file name to the subkey. */
+ bSuccess = RegSetValueEx(hk, /* subkey handle */
+ "EventMessageFile", /* value name */
+ 0, /* must be zero */
+ REG_EXPAND_SZ, /* value type */
+ (LPBYTE) pszMsgDLL, /* address of value data */
+ strlen(pszMsgDLL) + 1); /* length of value data */
+ PERR(bSuccess == ERROR_SUCCESS, "RegSetValueEx");
+
+ /* Set the supported types flags and addit to the subkey. */
+ dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
+ EVENTLOG_INFORMATION_TYPE;
+ bSuccess = RegSetValueEx(hk, /* subkey handle */
+ "TypesSupported", /* value name */
+ 0, /* must be zero */
+ REG_DWORD, /* value type */
+ (LPBYTE) &dwData, /* address of value data */
+ sizeof(DWORD)); /* length of value data */
+ PERR(bSuccess == ERROR_SUCCESS, "RegSetValueEx");
+ RegCloseKey(hk);
+ return;
+}
+
+/*********************************************************************
+* FUNCTION: reportAnEvent(DWORD dwIdEvent, WORD cStrings, *
+* LPTSTR *ppszStrings); *
+* *
+* PURPOSE: add the event to the event log *
+* *
+* INPUT: the event ID to report in the log, the number of insert *
+* strings, and an array of null-terminated insert strings *
+* *
+* RETURNS: none *
+*********************************************************************/
+
+void reportAnIEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
+{
+ HANDLE hAppLog;
+ BOOL bSuccess;
+
+ /* Get a handle to the Application event log */
+ hAppLog = RegisterEventSource(NULL, /* use local machine */
+ "NTP"); /* source name */
+ PERR(hAppLog, "RegisterEventSource");
+
+ /* Now report the event, which will add this event to the event log */
+ bSuccess = ReportEvent(hAppLog, /* event-log handle */
+ EVENTLOG_INFORMATION_TYPE, /* event type */
+ 0, /* category zero */
+ dwIdEvent, /* event ID */
+ NULL, /* no user SID */
+ cStrings, /* number of substitution strings */
+ 0, /* no binary data */
+ pszStrings, /* string array */
+ NULL); /* address of data */
+ PERR(bSuccess, "ReportEvent");
+ DeregisterEventSource(hAppLog);
+ return;
+}
+
+void reportAnWEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
+{
+ HANDLE hAppLog;
+ BOOL bSuccess;
+
+ /* Get a handle to the Application event log */
+ hAppLog = RegisterEventSource(NULL, /* use local machine */
+ "NTP"); /* source name */
+ PERR(hAppLog, "RegisterEventSource");
+
+ /* Now report the event, which will add this event to the event log */
+ bSuccess = ReportEvent(hAppLog, /* event-log handle */
+ EVENTLOG_WARNING_TYPE, /* event type */
+ 0, /* category zero */
+ dwIdEvent, /* event ID */
+ NULL, /* no user SID */
+ cStrings, /* number of substitution strings */
+ 0, /* no binary data */
+ pszStrings, /* string array */
+ NULL); /* address of data */
+ PERR(bSuccess, "ReportEvent");
+ DeregisterEventSource(hAppLog);
+ return;
+}
+
+void reportAnEEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
+{
+ HANDLE hAppLog;
+ BOOL bSuccess;
+
+ /* Get a handle to the Application event log */
+ hAppLog = RegisterEventSource(NULL, /* use local machine */
+ "NTP"); /* source name */
+ PERR(hAppLog, "RegisterEventSource");
+
+ /* Now report the event, which will add this event to the event log */
+ bSuccess = ReportEvent(hAppLog, /* event-log handle */
+ EVENTLOG_ERROR_TYPE, /* event type */
+ 0, /* category zero */
+ dwIdEvent, /* event ID */
+ NULL, /* no user SID */
+ cStrings, /* number of substitution strings */
+ 0, /* no binary data */
+ pszStrings, /* string array */
+ NULL); /* address of data */
+ PERR(bSuccess, "ReportEvent");
+ DeregisterEventSource(hAppLog);
+ return;
+}