Exemplo n.º 1
0
Arquivo: nt.c Projeto: jimmysoda/ogdi
VOID
nt_rpc_report(LPTSTR lpszMsg)
{
    CHAR    chMsg[256];
    HANDLE  hEventSource;
    LPTSTR  lpszStrings[2];

    // Use event logging to log the error.
    //
    hEventSource = RegisterEventSource(NULL,
                            TEXT("rpc.dll"));

    sprintf(chMsg, "sunrpc report: %d", GetLastError());
    lpszStrings[0] = chMsg;
    lpszStrings[1] = lpszMsg;

    if (hEventSource != NULL) {
        ReportEvent(hEventSource, // handle of event source
            EVENTLOG_WARNING_TYPE, // event type
            0,                    // event category
            0,                    // event ID
            NULL,                 // current user's SID
            2,                    // strings in lpszStrings
            0,                    // no bytes of raw data
            lpszStrings,          // array of error strings
            NULL);                // no raw data

        (VOID) DeregisterEventSource(hEventSource);
    }
}
Exemplo n.º 2
0
///////////////////////////////////////////////////////////////////////////////////////
// Logging functions
void CServiceModule::LogEvent(LPCTSTR pFormat, ...)
{
    TCHAR    chMsg[256];
    HANDLE  hEventSource;
    LPTSTR  lpszStrings[1];
    va_list pArg;

    va_start(pArg, pFormat);
    _vstprintf(chMsg, pFormat, pArg);
    va_end(pArg);

    lpszStrings[0] = chMsg;

    if (m_bService)
    {
        /* Get a handle to use with ReportEvent(). */
        hEventSource = RegisterEventSource(NULL, m_szServiceName);
        if (hEventSource != NULL)
        {
            /* Write to event log. */
            ReportEvent(hEventSource, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (LPCTSTR*) &lpszStrings[0], NULL);
            DeregisterEventSource(hEventSource);
        }
    }
    else
    {
        // As we are not running as a service, just write the error to the console.
        _putts(chMsg);
    }
}
Exemplo n.º 3
0
void SvcReportEvent(WORD wType, DWORD dwEventID, LPTSTR msg)
{
	HANDLE hEventSource;
	LPCTSTR lpszStrings[2];

	hEventSource = RegisterEventSource(nullptr, SVCNAME);

	if (hEventSource)
	{
		lpszStrings[0] = SVCNAME;
		lpszStrings[1] = msg;

		ReportEvent(hEventSource,
			wType,
			0,
			dwEventID,
			nullptr,
			2,
			0,
			lpszStrings,
			nullptr);

		DeregisterEventSource(hEventSource);
	}
}
Exemplo n.º 4
0
void svOutput::OpenEventLog(void)
{
#ifdef __WIN32__
    if (el_source == NULL) {
        el_source = RegisterEventSource(NULL, "Suva");
    }
#endif
}
Exemplo n.º 5
0
 explicit  Private( Facility facility_ )
     : KDEncodingLogDevice::Private( QTextCodec::codecForLocale() ),
       facility( facility_ ),
       internal( RegisterEventSource( 0, TEXT("Application") ) )
 {
     if ( !internal )
         fprintf( stderr, "Error in RegisterEventSourceA(): %u\n", static_cast< unsigned int >( GetLastError() ) );
 }
Exemplo n.º 6
0
void openlog(const char *ident, int logopt, int facility)
{

	closelog();

	PW32G(log_source) = RegisterEventSource(NULL, "PHP-" PHP_VERSION);
	spprintf(&PW32G(log_header), 0, (logopt & LOG_PID) ? "%s[%d]" : "%s", ident, getpid());
}
Exemplo n.º 7
0
void openlog (const char *ident,int logopt,int facility)
{
  char tmp[MAILTMPLEN];
  if (!check_nt ()) return;	/* no-op on non-NT system */
  if (loghdl) fatal ("Duplicate openlog()!");
  loghdl = RegisterEventSource (NIL,ident);
  sprintf (tmp,(logopt & LOG_PID) ? "%s[%d]" : "%s",ident,getpid ());
  loghdr = cpystr (tmp);	/* save header for later */
}
Exemplo n.º 8
0
void
logToSystemLog(LogLevel_t level, char *msg)
{
#ifdef WIN32
    HANDLE  eventHandle;
    char    *strings[2];


    eventHandle = RegisterEventSource(NULL, Program);

    strings[0] = msg;
    strings[1] = NULL;

    if (eventHandle != NULL)
    {
	ReportEvent(eventHandle,	    /* Handle of event source */
		    (level == LLOG_SEVERE ? EVENTLOG_ERROR_TYPE :
		     EVENTLOG_INFORMATION_TYPE),  /* Event type */
		    (WORD)level,	    /* Event category */
		    0,			    /* Event ID */
		    NULL,		    /* User SID */
		    1,			    /* Number of message strings */
		    0,			    /* Bytes of binary data */
		    (const char **)strings, /* Array of message strings */
		    NULL);		    /* No binary data */
	DeregisterEventSource(eventHandle);
    }
#else
    int logLevel;

    /*
    ** Messages at level 0 are errors, 1 is notice, 2 informational
    ** and everything else is classed as debug.
    */

    switch (level)
    {
    case LLOG_SEVERE:
	logLevel = LOG_ERR;
	break;

    case LLOG_WARNING:
	logLevel = LOG_NOTICE;
	break;

    case LLOG_INFO:
	logLevel = LOG_INFO;
	break;

    default:
	logLevel = LOG_DEBUG;
	break;
    }

    syslog(logLevel, "%s", msg);
#endif
}
Exemplo n.º 9
0
void mprWriteToOsLog(MprCtx ctx, cchar *message, int flags, int level)
{
    HKEY        hkey;
    void        *event;
    long        errorType;
    ulong       exists;
    char        buf[MPR_MAX_STRING], logName[MPR_MAX_STRING], *lines[9], *cp, *value;
    int         type;
    static int  once = 0;

    mprStrcpy(buf, sizeof(buf), message);
    cp = &buf[strlen(buf) - 1];
    while (*cp == '\n' && cp > buf) {
        *cp-- = '\0';
    }

    type = EVENTLOG_ERROR_TYPE;

    lines[0] = buf;
    lines[1] = 0;
    lines[2] = lines[3] = lines[4] = lines[5] = 0;
    lines[6] = lines[7] = lines[8] = 0;

    if (once == 0) {
        /*  Initialize the registry */
        once = 1;
        mprSprintf(logName, sizeof(logName), "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",
                   mprGetAppName(ctx));
        hkey = 0;

        if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, logName, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, &exists) == ERROR_SUCCESS) {
            value = "%SystemRoot%\\System32\\netmsg.dll";
            if (RegSetValueEx(hkey, "EventMessageFile", 0, REG_EXPAND_SZ,
                              (uchar*) value, (int) strlen(value) + 1) != ERROR_SUCCESS) {
                RegCloseKey(hkey);
                return;
            }

            errorType = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
            if (RegSetValueEx(hkey, "TypesSupported", 0, REG_DWORD, (uchar*) &errorType, sizeof(DWORD)) != ERROR_SUCCESS) {
                RegCloseKey(hkey);
                return;
            }
            RegCloseKey(hkey);
        }
    }

    event = RegisterEventSource(0, mprGetAppName(ctx));
    if (event) {
        /*
         *  3299 is the event number for the generic message in netmsg.dll.
         *  "%1 %2 %3 %4 %5 %6 %7 %8 %9" -- thanks Apache for the tip
         */
        ReportEvent(event, EVENTLOG_ERROR_TYPE, 0, 3299, NULL, sizeof(lines) / sizeof(char*), 0, (LPCSTR*) lines, 0);
        DeregisterEventSource(event);
    }
}
Exemplo n.º 10
0
Arquivo: win32.c Projeto: prasincs/pcp
void
openlog(const char *ident, int option, int facility)
{
    if (eventlog)
	closelog();
    eventlog = RegisterEventSource(NULL, "Application");
    if (ident)
	eventlogPrefix = strdup(ident);
}
Exemplo n.º 11
0
void lutil_LogStoppedEvent( char *svc )
{
	HANDLE hEventLog;
	
	hEventLog = RegisterEventSource( NULL, svc );
	ReportEvent( hEventLog, EVENTLOG_INFORMATION_TYPE, 0,
		MSG_SVC_STOPPED, NULL, 0, 0, NULL, NULL );
	DeregisterEventSource( hEventLog );
}
Exemplo n.º 12
0
PUBLIC void syslog(int priority, char *fmt, ...)
{
    va_list     args;
    HKEY        hkey;
    void        *event;
    long        errorType;
    ulong       exists;
    char        *buf, logName[ME_GOAHEAD_LIMIT_STRING], *lines[9], *cp, *value;
    int         type;
    static int  once = 0;

    va_start(args, fmt);
    buf = sfmtv(fmt, args);
    va_end(args);

    cp = &buf[slen(buf) - 1];
    while (*cp == '\n' && cp > buf) {
        *cp-- = '\0';
    }
    type = EVENTLOG_ERROR_TYPE;
    lines[0] = buf;
    lines[1] = 0;
    lines[2] = lines[3] = lines[4] = lines[5] = 0;
    lines[6] = lines[7] = lines[8] = 0;

    if (once == 0) {
        /*  Initialize the registry */
        once = 1;
        hkey = 0;

        if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, logName, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, &exists) ==
                ERROR_SUCCESS) {
            value = "%SystemRoot%\\System32\\netmsg.dll";
            if (RegSetValueEx(hkey, "EventMessageFile", 0, REG_EXPAND_SZ, 
                    (uchar*) value, (int) slen(value) + 1) != ERROR_SUCCESS) {
                RegCloseKey(hkey);
                wfree(buf);
                return;
            }
            errorType = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
            if (RegSetValueEx(hkey, "TypesSupported", 0, REG_DWORD, (uchar*) &errorType, sizeof(DWORD)) != 
                    ERROR_SUCCESS) {
                RegCloseKey(hkey);
                wfree(buf);
                return;
            }
            RegCloseKey(hkey);
        }
    }
    event = RegisterEventSource(0, ME_NAME);
    if (event) {
        ReportEvent(event, EVENTLOG_ERROR_TYPE, 0, 3299, NULL, sizeof(lines) / sizeof(char*), 0, (LPCSTR*) lines, 0);
        DeregisterEventSource(event);
    }
    wfree(buf);
}
Exemplo n.º 13
0
VOID RplReportEventEx(
    IN  DWORD       MessageId,
    IN  LPWSTR *    aStrings
    )
/*++

Routine Description:

    Writes an event in the event log.
    A related function lives is RplReportEvent() in lib\report.c.
    These two functions should be united.

Arguments:

    MessageId    - Message ID
    aStrings     - a NULL terminated array of strings

Return Value:

    None.

--*/
{
    WORD        cStrings;
    HANDLE      logHandle;

    logHandle = RegisterEventSource( NULL, RPL_EVENTLOG_NAME);

    //  If the event log cannot be opened, just return.

    if ( logHandle == NULL) {
        RplDump( ++RG_Assert, ("Error=%d", GetLastError()));
        return;
    }

    for ( cStrings = 0;  aStrings[ cStrings] != NULL;  cStrings++) {
        NOTHING;
    }

    if ( !ReportEvent(
            logHandle,
            EVENTLOG_ERROR_TYPE,
            0,                      //  event category
            MessageId,              //  event id
            NULL,                   //  user SID. We're local system - uninteresting
            cStrings,               //  number of strings
            0,                      //  raw data size
            aStrings,               //  string array
            NULL                    //  raw data buffer
            )) {
        RplDump( ++RG_Assert, ( "Error=%d", GetLastError()));
    }

    DeregisterEventSource( logHandle);
}
void PrintEvent(const TCHAR* psz)
{
	const TCHAR* rgsz[] = { psz };

	HANDLE hes = RegisterEventSource(0, _T("appserv"));
	if(hes)
	{
		ReportEvent(hes, EVENTLOG_INFORMATION_TYPE, 0, 0, 0, 1, 0, rgsz, 0);
		DeregisterEventSource(hes);
	}
}
Exemplo n.º 15
0
void setupForRun(int argc, char **argv, bool debug, const wxString &executable)
{
	if (!debug)
	{
		eventHandle = RegisterEventSource(0, serviceName.c_str());
		if (!eventHandle)
			LogMessage(_("Couldn't register event handle."), LOG_ERROR);
	}

	setOptions(argc, argv, executable);
}
Exemplo n.º 16
0
void qsrStartUsingLogger( qsrLogMsg * pLog )
{
   PSO_PRE_CONDITION( pLog != NULL );

   pLog->useLog = true;
#if defined ( WIN32 )
   pLog->handle = RegisterEventSource( NULL, pLog->name );
#else
   openlog( pLog->name, LOG_PID, LOG_USER );
#endif
}
Exemplo n.º 17
0
void osi_LogEvent0(char *a,char *b)
{
    HANDLE h;
    char *ptbuf[1];
    if (!ISCLIENTTRACE(osi_TraceOption))
        return;
    h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME);
    ptbuf[0] = b;
    ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL);
    DeregisterEventSource(h);
}
Exemplo n.º 18
0
/* Emulator for BSD openlog() routine
 * Accepts: identity
 *      options
 *      facility
 */
 void openlog(const char *ident, int logopt, int facility)
 {
    char tmp[1024];

    if (loghdl) {
        closelog();
    }
    loghdl = RegisterEventSource(NULL, ident);
    sprintf(tmp, (logopt & WINLOG_PID) ? "%s[%d]" : "%s", ident, getpid());
    loghdr = _strdup(tmp);  /* save header for later */
}
Exemplo n.º 19
0
MIKTEXINTERNALFUNC(bool) ReportMiKTeXEvent(unsigned short eventType, unsigned long eventId, ...)
{
#if ! REPORT_EVENTS
  UNUSED_ALWAYS(eventType);
  UNUSED_ALWAYS(eventId);
  return false;
#else
  vector<const char *> vecStrings;
  va_list marker;
  va_start(marker, eventId);
  for (const char * lpsz = va_arg(marker, const char *);
  lpsz != nullptr;
    lpsz = va_arg(marker, const char *))
  {
    vecStrings.push_back(lpsz);
  }
  va_end(marker);

  HANDLE hEventSource = RegisterEventSource(0, SOURCE);
  if (hEventSource == nullptr)
  {
    return false;
  }

  PSID pSid = 0;
  size_t bufSize = 8192;
  AutoMemoryPointer pBuf(malloc(bufSize));
  if (pBuf.Get() == nullptr)
  {
    OUT_OF_MEMORY("malloc");
  }
  char szAccountName[BufferSizes::MaxPath];
  unsigned long n = BufferSizes::MaxPath;
  if (GetUserName(szAccountName, &n))
  {
    unsigned long sidSize = static_cast<unsigned long>(bufSize);
    pSid = reinterpret_cast<PSID>(pBuf.Get());
    char szDomainName[BufferSizes::MaxPath];
    unsigned long domainNameSize = BufferSizes::MaxPath;
    SID_NAME_USE use;
    if (!LookupAccountName(0, szAccountName, pSid, &sidSize, szDomainName, &domainNameSize, &use))
    {
      pSid = 0;
    }
  }
  BOOL done =
    ReportEvent(hEventSource, eventType, 0, eventId, pSid, static_cast<unsigned short>(vecStrings.size()), 0, &vecStrings[0], 0);
  DeregisterEventSource(hEventSource);

  return done ? true : false;
#endif
}
Exemplo n.º 20
0
int SockListener(unsigned short *servPort)
{
	int servSock; /* Socket descriptor for server */
	int clntSock; /* Socket descriptor for client */
	DWORD threadID; /* Thread ID from CreateThread() */
	WSADATA wsaData; /* Structure for WinSock setup communication */
	wchar_t tmp[TMPBUF];

	if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) /* Load Winsock 2.2 DLL */
	{
		wsprintf(tmp, L"SockListener WSAStartup() failed");
		WriteLog(tmp);
		return(-1);
	}

	servSock = CreateTCPServerSocket(*servPort);

	for (;;)
	{
		clntSock = AcceptTCPConnection(servSock);
		{
			extern TCHAR *ServiceName;
			HANDLE hEventLog = RegisterEventSource(NULL, ServiceName);
			BOOL bSuccess;
			PCTSTR aInsertions [] = { L"call_usermodehelper:", L"Accepted", L"TCP connection" };
			bSuccess = ReportEvent(
				hEventLog,                  // Handle to the eventlog
				EVENTLOG_INFORMATION_TYPE,  // Type of event
				0,                             // Category (could also be 0)
				MSG_ACCEPT_TCP,                // Event id
				NULL,                       // User's sid (NULL for none)
				3,                          // Number of insertion strings
				0,                          // Number of additional bytes
				aInsertions,                // Array of insertion strings
				NULL                        // Pointer to additional bytes
				);

			DeregisterEventSource(hEventLog);
		}

		/* Create separate memory for client argument */

		HANDLE h;
		if ((h = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) ThreadMain, &clntSock, 0, (LPDWORD) &threadID)) == NULL)
		{
			wsprintf(tmp, L"call_usermodehelper: CreateThread failed. err(%d)", GetLastError());
			WriteLog(tmp);
			return -1;
		}
	}
	/* NOT REACHED */
}
Exemplo n.º 21
0
BOOL LogEvent(
    LPCSTR  lpUNCServerName,
    WORD  wType,
    DWORD  dwEventID,
    PSID  lpUserSid,
    LPCSTR  message)
{
    LPCSTR  messages[] = {message, NULL};
    
    HANDLE hElog = RegisterEventSource(lpUNCServerName, "Shibboleth Daemon");
    BOOL res = ReportEvent(hElog, wType, 0, dwEventID, lpUserSid, 1, 0, messages, NULL);
    return (DeregisterEventSource(hElog) && res);
}
Exemplo n.º 22
0
void log_init_platform(void) {
	int rc;

	_event_log = RegisterEventSource(NULL, "Brick Daemon");

	if (_event_log == NULL) {
		rc = ERRNO_WINAPI_OFFSET + GetLastError();

		// this will go to the logfile if it is enabled via --debug
		log_error("Could not open Windows event log: %s (%d)",
		          get_errno_name(rc), rc);
	}
}
Exemplo n.º 23
0
void DebugEvent0(char *a) 
{
    HANDLE h; char *ptbuf[1];
    
    if (!ISLOGONTRACE(TraceOption))
        return;
    
    h = RegisterEventSource(NULL, AFS_LOGON_EVENT_NAME);
    if (h != INVALID_HANDLE_VALUE) {
        ptbuf[0] = a;
        ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 1008, NULL, 1, 0, (const char **)ptbuf, NULL);
        DeregisterEventSource(h);
    }
}
Exemplo n.º 24
0
/*
 * This function is for reporting errors to the application
 * event log in case the regular syslog is not available
 * mainly during startup. It should not be used under normal
 * circumstances.
 */
void
NTReportError(const char *name, const char *str) {
	HANDLE hNTAppLog = NULL;
	const char *buf[1];

	buf[0] = str;

	hNTAppLog = RegisterEventSource(NULL, name);

	ReportEvent(hNTAppLog, EVENTLOG_ERROR_TYPE, 0,
		    NTP_ERROR, NULL, 1, 0, buf, NULL);

	DeregisterEventSource(hNTAppLog);
}
Exemplo n.º 25
0
void osi_LogEvent(char *a,char *b,char *c,...) 
{
	HANDLE h; char *ptbuf[1],buf[MAXBUF_+1];
	va_list marker;
	if (!ISCLIENTTRACE(osi_TraceOption))
		return;
    h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME);
	va_start(marker,c);
	StringCbVPrintfA(buf,MAXBUF_,c,marker);
	ptbuf[0] = buf;
	ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL);\
	DeregisterEventSource(h);
	va_end(marker);
}
void EventLogChannel::open()
{
	setUpRegistry();
#if defined(POCO_WIN32_UTF8)
	std::wstring uhost;
	UnicodeConverter::toUTF16(_host, uhost);
	std::wstring uname;
	UnicodeConverter::toUTF16(_name, uname);
	_h = 0;//RegisterEventSourceW(uhost.empty() ? NULL : uhost.c_str(), uname.c_str());
#else
	_h = RegisterEventSource(_host.empty() ? NULL : _host.c_str(), _name.c_str());
#endif
	if (!_h) throw SystemException("cannot register event source");
}
Exemplo n.º 27
0
void
rpcapd_log_init(const char *argv0, int also_stderr)
{
#ifdef WIN32
    event_source = RegisterEventSource(NULL, "rpcapd");
#else
    int flags = LOG_CONS | LOG_PID;
    if (also_stderr) {
        flags |= LOG_PERROR;
    }
    setlogmask(LOG_UPTO(LOG_NOTICE));
    openlog("rpcapd", flags, LOG_DAEMON);
#endif
}
Exemplo n.º 28
0
ERL_NIF_TERM
register_event_source(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    char event_source[_MAX_PATH];
    HANDLE handle;

    NIF_GET_STRING(env, argv[0], event_source, _MAX_PATH);

    NIF_ERR( add_registry_info(env, event_source) );

    WINAPI_LASTERR(env, handle = RegisterEventSource(NULL, event_source));

    return enif_make_tuple2(env, atom_ok, enif_make_int(env, (int)handle));
}
Exemplo n.º 29
0
	//记录日志事件到系统中
	void LogErrorEvent(LPCTSTR pFormat,...)
	{
		_TCHAR pMsg[MAX_PATH];

		va_list pArg;
		va_start(pArg,pFormat);
		_vstprintf(pMsg,pFormat,pArg);
		va_end(pArg);

		LPCTSTR pStr[1] = {pMsg};
		if (hEventSource == NULL)
			hEventSource = RegisterEventSource(NULL,PServiceManage::Instance()->ServiceName());
		ReportEvent(hEventSource,EVENTLOG_ERROR_TYPE,0,EVENTID,NULL,1,0,pStr,NULL);
	}
Exemplo n.º 30
0
void ReportError(BOOL bError, LPCTSTR szError)
{
	static BOOL bEventSourceAdded = FALSE;
	if(!bEventSourceAdded)
	{
		TCHAR szModule[MAX_PATH];
		GetModuleFileName(g_hInstance,szModule,MAX_PATH);
		AddEventSource(L"CVSNT",szModule);
		bEventSourceAdded=TRUE;
	}

	HANDLE hEvent = RegisterEventSource(NULL,  L"CVSNT");
	ReportEvent(hEvent,bError?EVENTLOG_ERROR_TYPE:EVENTLOG_INFORMATION_TYPE,0,MSG_STRING,NULL,1,0,&szError,NULL);
	DeregisterEventSource(hEvent);
}