Windows: log SMB or RDR in use at startup
[openafs.git] / src / WINNT / afsd / afsd_eventlog.c
index 065ec5a..03357f7 100644 (file)
@@ -1,12 +1,16 @@
 ////////////////////////////////////////////////////////////////////
 //
 //
-//             E V E N T   L O G G I N G   F U N C T I O N S 
+//             E V E N T   L O G G I N G   F U N C T I O N S
 //
 //
 ////////////////////////////////////////////////////////////////////
 
 
+#include <afsconfig.h>
+#include <afs/param.h>
+#include <roken.h>
+
 #include <windows.h>
 #include <stdarg.h>
 #include <string.h>
@@ -14,6 +18,8 @@
 #include <WINNT/afsreg.h>
 #include "afsd.h"
 #include "afsd_eventlog.h"
+#define AFS_VERSION_STRINGS
+#include "afs_component_version_number.h"
 
 static BOOL    GetServicePath(LPTSTR lpPathBuf, PDWORD pdwPathBufSize);
 static BOOL    AddEventSource(void);
@@ -21,14 +27,14 @@ static BOOL AddEventSource(void);
 static BOOL
 GetServicePath(LPTSTR lpPathBuf, PDWORD pdwPathBufSize)
 {
-    HKEY       hKey = NULL; 
+    HKEY       hKey = NULL;
     DWORD      dwData = 0;
     BOOL       bRet = TRUE;
 
     do {
        // Open key
        if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_SUBKEY, 0, KEY_QUERY_VALUE, &hKey ) )
-       {               
+       {
            bRet = FALSE;
            break;
        }
@@ -42,20 +48,20 @@ GetServicePath(LPTSTR lpPathBuf, PDWORD pdwPathBufSize)
                              NULL,                     // type buffer
                              (LPBYTE) lpPathBuf,       // data buffer
                              &dwData))         // size of data buffer
-       {       
+       {
            bRet = FALSE;
            break;
        }
-               
+
        *pdwPathBufSize = dwData;
 
     } while (0);
-                               
+
     if (hKey != NULL)
-       RegCloseKey(hKey); 
+       RegCloseKey(hKey);
 
     return bRet;
-} 
+}
 
 //
 // Ensure name for message file is in proper location in Registry.
@@ -63,9 +69,9 @@ GetServicePath(LPTSTR lpPathBuf, PDWORD pdwPathBufSize)
 static BOOL
 AddEventSource()
 {
-    HKEY       hKey = NULL, hLogKey; 
-    UCHAR      szBuf[MAX_PATH] = "afsd_service.exe"; 
-    DWORD      dwData, dwDisposition; 
+    HKEY       hKey = NULL, hLogKey;
+    UCHAR      szBuf[MAX_PATH] = "afsd_service.exe";
+    DWORD      dwData, dwDisposition;
     static BOOL        bRet = TRUE;
     static BOOL bOnce = TRUE;
 
@@ -74,71 +80,71 @@ AddEventSource()
 
     if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, AFSREG_APPLOG_SUBKEY, 0,
                        KEY_SET_VALUE, &hLogKey ) )
-    {                          
-        // nope - create it            
+    {
+        // nope - create it
         if ( RegCreateKeyEx(HKEY_LOCAL_MACHINE, AFSREG_APPLOG_SUBKEY, 0,
                              NULL, REG_OPTION_NON_VOLATILE,
                              KEY_ALL_ACCESS, NULL, &hLogKey,
-                             &dwDisposition)) 
-        {      
+                             &dwDisposition))
+        {
             bRet = FALSE;
             goto done;
         }
     }
 
-    // Let's see if key already exists as a subkey under the 
+    // Let's see if key already exists as a subkey under the
     // Application key in the EventLog registry key.  If not,
     // create it.
     if ( RegOpenKeyEx( hLogKey, AFSREG_CLT_APPLOG_SUBKEY, 0,
                        KEY_SET_VALUE, &hKey ) )
-    {                          
-        // nope - create it            
+    {
+        // nope - create it
         if ( RegCreateKeyEx(hLogKey, AFSREG_CLT_APPLOG_SUBKEY, 0,
                              NULL, REG_OPTION_NON_VOLATILE,
                              KEY_ALL_ACCESS, NULL, &hKey,
-                             &dwDisposition)) 
-        {              
+                             &dwDisposition))
+        {
             bRet = FALSE;
             goto done;
         }
     }
 
-    // Add the name to the EventMessageFile subkey. 
-    if ( RegSetValueEx( hKey,                  // subkey handle 
-                        AFSREG_APPLOG_MSGFILE_VALUE,   // value name 
-                        0,                     // must be zero 
-                        REG_SZ,                        // value type 
-                        (LPBYTE) szBuf,                // pointer to value data 
+    // Add the name to the EventMessageFile subkey.
+    if ( RegSetValueEx( hKey,                  // subkey handle
+                        AFSREG_APPLOG_MSGFILE_VALUE,   // value name
+                        0,                     // must be zero
+                        REG_SZ,                        // value type
+                        (LPBYTE) szBuf,                // pointer to value data
                         (DWORD)strlen(szBuf) + 1))     // length of value data
-    {          
+    {
         bRet = FALSE;
         goto done;
     }
 
-    // Set the supported event types in the TypesSupported subkey. 
-    dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | 
-        EVENTLOG_INFORMATION_TYPE; 
+    // Set the supported event types in the TypesSupported subkey.
+    dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
+        EVENTLOG_INFORMATION_TYPE;
 
-    if ( RegSetValueEx( hKey,                  // subkey handle 
-                        AFSREG_APPLOG_MSGTYPE_VALUE,   // value name 
-                        0,                     // must be zero 
-                        REG_DWORD,             // value type 
-                        (LPBYTE) &dwData,      // pointer to value data 
+    if ( RegSetValueEx( hKey,                  // subkey handle
+                        AFSREG_APPLOG_MSGTYPE_VALUE,   // value name
+                        0,                     // must be zero
+                        REG_DWORD,             // value type
+                        (LPBYTE) &dwData,      // pointer to value data
                         sizeof(DWORD)))                // length of value data
-    {          
+    {
         bRet = FALSE;
        goto done;
     }
-           
+
   done:
     if (hKey != NULL)
-       RegCloseKey(hKey); 
+       RegCloseKey(hKey);
 
     if (hLogKey != NULL)
-       RegCloseKey(hLogKey); 
+       RegCloseKey(hLogKey);
 
     return bRet;
-}      
+}
 
 // Log an event with a formatted system message as the (only) substitution
 // string, from the given message ID.
@@ -197,14 +203,28 @@ LogEvent(WORD wEventType, DWORD dwEventID, ...)
     case MSG_FLUSH_UNEXPECTED_EVENT:
     case MSG_UNHANDLED_EXCEPTION:
     case MSG_SMB_ZERO_TRANSACTION_COUNT:
-    case MSG_SERVICE_START_PENDING:
     case MSG_SERVICE_INCORRECT_VERSIONS:
-    case MSG_SERVICE_RUNNING:
     case MSG_SERVICE_STOPPING:
+    case MSG_SERVICE_STOPPED:
     case MSG_SERVICE_ERROR_STOP:
     case MSG_CRYPT_OFF:
     case MSG_CRYPT_ON:
        break;
+    case MSG_SERVICE_START_PENDING:
+        wNumArgs = 1;
+        lpArgs[0] = AFSVersion;
+        break;
+    case MSG_SERVICE_RUNNING:
+        wNumArgs = 1;
+        if (smb_Enabled && RDR_Initialized)
+            lpArgs[0] = "SMB and RDR interfaces";
+        else if (smb_Enabled)
+            lpArgs[0] = "SMB interface";
+        else if (RDR_Initialized)
+            lpArgs[0] = "RDR interface";
+        else
+            lpArgs[0] = "No active interface";
+        break;
     case MSG_FLUSH_BAD_SHARE_NAME:
     case MSG_FLUSH_OPEN_ENUM_ERROR:
     case MSG_FLUSH_ENUM_ERROR:
@@ -214,6 +234,7 @@ LogEvent(WORD wEventType, DWORD dwEventID, ...)
     case MSG_SMB_SEND_PACKET_FAILURE:
     case MSG_UNEXPECTED_SMB_SESSION_CLOSE:
     case MSG_RX_MSGSIZE_EXCEEDED:
+    case MSG_RX_BUSY_CALL_CHANNEL:
        wNumArgs = 1;
        lpArgs[0] = va_arg(listArgs, LPTSTR);
        break;
@@ -233,6 +254,12 @@ LogEvent(WORD wEventType, DWORD dwEventID, ...)
     case MSG_SERVER_REPORTS_VIO:
     case MSG_SERVER_REPORTS_VBUSY:
     case MSG_SERVER_REPORTS_VRESTARTING:
+       wNumArgs = 3;
+       lpArgs[0] = va_arg(listArgs, LPTSTR);
+       StringCbPrintf(lpStrings[1],STRLEN,"%d",va_arg(listArgs,afs_int32));
+       lpArgs[1] = lpStrings[1];
+       lpArgs[2] = va_arg(listArgs, LPTSTR);
+        break;
     case MSG_ALL_SERVERS_BUSY:
     case MSG_ALL_SERVERS_OFFLINE:
     case MSG_ALL_SERVERS_DOWN:
@@ -381,6 +408,6 @@ LogEvent(WORD wEventType, DWORD dwEventID, ...)
         CloseHandle(hMutex);
 
     DeregisterEventSource(hEventSource);
-}      
+}