Windows: afslogon network provider debug registry value
[openafs.git] / src / WINNT / afsd / afslogon.c
index e2c89c0..ccac524 100644 (file)
@@ -40,6 +40,7 @@
 #include <WINNT\afsreg.h>
 
 DWORD TraceOption = 0;
+DWORD Debug = 0;
 
 HANDLE hDLL;
 
@@ -49,7 +50,7 @@ void DebugEvent0(char *a)
 {
     HANDLE h; char *ptbuf[1];
 
-    if (!ISLOGONTRACE(TraceOption))
+    if (!Debug && !ISLOGONTRACE(TraceOption))
         return;
 
     h = RegisterEventSource(NULL, AFS_LOGON_EVENT_NAME);
@@ -66,7 +67,7 @@ void DebugEvent(char *b,...)
     HANDLE h; char *ptbuf[1],buf[MAXBUF_+1];
     va_list marker;
 
-    if (!ISLOGONTRACE(TraceOption))
+    if (!Debug && !ISLOGONTRACE(TraceOption))
         return;
 
     h = RegisterEventSource(NULL, AFS_LOGON_EVENT_NAME);
@@ -224,8 +225,17 @@ DWORD APIENTRY NPGetCaps(DWORD index)
 {
     switch (index) {
     case WNNC_NET_TYPE:
-        /* Don't have our own type; use somebody else's. */
-        return WNNC_NET_OPENAFS;
+        /*
+         * The purpose of this response is to let the system
+         * know which file system the network provider is associated with
+         * Microsoft issues these values starting from 1 with the exception
+         * of WNNC_CRED_MANAGER which is 0xFFFF.  The provider type is
+         * stored in the hiword.  Pick a value that is unused.
+         */
+        return 0x1FFF0000;
+
+    case WNNC_SPEC_VERSION:
+        return WNNC_SPEC_VERSION51;
 
     case WNNC_START:
         /* Say we are already started, even though we might wait after we receive NPLogonNotify */
@@ -315,6 +325,28 @@ BOOL IsServiceStartPending (void)
     return (Status.dwCurrentState == SERVICE_START_PENDING);
 }
 
+BOOL StartTheService (void)
+{
+    SC_HANDLE hManager;
+    DWORD gle = 0;
+
+    if ((hManager = OpenSCManager (NULL, NULL, GENERIC_READ|SERVICE_START)) != NULL)
+    {
+        SC_HANDLE hService;
+        if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"), GENERIC_READ|SERVICE_START)) != NULL)
+        {
+            StartService (hService, 0, NULL);
+            gle = GetLastError();
+            CloseServiceHandle (hService);
+        } else
+            gle = GetLastError();
+
+        CloseServiceHandle (hManager);
+    }
+    DebugEvent("AFS AfsLogon - Service Start Return Code[0x%x]",gle);
+    return (gle == 0);
+}
+
 /* LOOKUPKEYCHAIN: macro to look up the value in the list of keys in order until it's found
    v:variable to receive value (reference type)
    t:type
@@ -835,6 +867,14 @@ DWORD APIENTRY NPLogonNotify(
 
     RegCloseKey (NPKey);
 
+    (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PROVIDER_SUBKEY,
+                         0, KEY_QUERY_VALUE, &NPKey);
+    LSPsize=sizeof(Debug);
+    RegQueryValueEx(NPKey, REG_CLIENT_DEBUG_PARM, NULL,
+                     &LSPtype, (LPBYTE)&Debug, &LSPsize);
+
+    RegCloseKey (NPKey);
+
     DebugEvent("NPLogonNotify - LoginId(%d,%d)", lpLogonId->HighPart, lpLogonId->LowPart);
 
     /* Make sure the AFS Libraries are initialized */
@@ -918,9 +958,9 @@ DWORD APIENTRY NPLogonNotify(
             DebugEvent0("Unable to obtain Root Cell");
             code = KTC_NOCELL;
             reason = "unknown cell";
-            code=0;
         } else {
             DebugEvent("Default cell is %s", cell);
+            code = 0;
         }
 
         /* We get the user's home directory path, if applicable, though we can't lookup the
@@ -934,8 +974,20 @@ DWORD APIENTRY NPLogonNotify(
 
     /* loop until AFS is started. */
     if (afsWillAutoStart) {
-       while (IsServiceRunning() || IsServiceStartPending()) {
-           DebugEvent("while(autostart) LogonOption[%x], Service AutoStart[%d]",
+        /*
+         * If the service is configured for auto start but hasn't started yet,
+         * give it a shove.
+         */
+        if (!(IsServiceRunning() || IsServiceStartPending()))
+            StartTheService();
+
+        while ( IsServiceStartPending() ) {
+            Sleep(10);
+        }
+
+        while (IsServiceRunning() && code != KTC_NOCM && code != KTC_NOCMRPC && code != KTC_NOCELL) {
+
+            DebugEvent("while(autostart) LogonOption[%x], Service AutoStart[%d]",
                        opt.LogonOption,afsWillAutoStart);
 
            if (ISADREALM(opt.flags)) {