windows-misc-fix-20061004
[openafs.git] / src / WINNT / afsd / cm_daemon.c
index 7c8d47e..06488f1 100644 (file)
 #include <afs/param.h>
 #include <afs/stds.h>
 
-#ifndef DJGPP
 #include <windows.h>
 #include <winsock2.h>
 #include <iphlpapi.h>
-#else
-#include <netdb.h>
-#endif /* !DJGPP */
 #include <stdlib.h>
 #include <malloc.h>
 #include <string.h>
@@ -48,7 +44,6 @@ cm_bkgRequest_t *cm_bkgListEndp;      /* last elt in the list of requests */
 
 static int daemon_ShutdownFlag = 0;
 
-#ifndef DJGPP
 void cm_IpAddrDaemon(long parm)
 {
     extern void smb_CheckVCs(void);
@@ -66,7 +61,6 @@ void cm_IpAddrDaemon(long parm)
        }       
     }
 }
-#endif
 
 void cm_BkgDaemon(long parm)
 {
@@ -89,9 +83,13 @@ void cm_BkgDaemon(long parm)
         osi_assert(cm_bkgQueueCount-- > 0);
         lock_ReleaseWrite(&cm_daemonLock);
 
+       osi_Log2(afsd_logp,"cm_BkgDaemon (before) scp 0x%x ref %d",rp->scp, rp->scp->refCount);
+
         (*rp->procp)(rp->scp, rp->p1, rp->p2, rp->p3, rp->p4, rp->userp);
                 
-        cm_ReleaseUser(rp->userp);
+       osi_Log2(afsd_logp,"cm_BkgDaemon (after) scp 0x%x ref %d",rp->scp, rp->scp->refCount);
+
+       cm_ReleaseUser(rp->userp);
         cm_ReleaseSCache(rp->scp);
         free(rp);
 
@@ -100,7 +98,7 @@ void cm_BkgDaemon(long parm)
     lock_ReleaseWrite(&cm_daemonLock);
 }
 
-void cm_QueueBKGRequest(cm_scache_t *scp, cm_bkgProc_t *procp, long p1, long p2, long p3, long p4,
+void cm_QueueBKGRequest(cm_scache_t *scp, cm_bkgProc_t *procp, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4,
        cm_user_t *userp)
 {
     cm_bkgRequest_t *rp;
@@ -144,7 +142,13 @@ IsWindowsFirewallPresent(void)
     if (!scm) return FALSE;
 
     /* Open Windows Firewall service */
-    svc = OpenService(scm, "SharedAccess", SERVICE_QUERY_CONFIG);
+    svc = OpenService(scm, "MpsSvc", SERVICE_QUERY_CONFIG);
+    if (!svc) {
+       afsi_log("MpsSvc Service could not be opened for query: 0x%x", GetLastError());
+       svc = OpenService(scm, "SharedAccess", SERVICE_QUERY_CONFIG);
+       if (!svc)
+           afsi_log("SharedAccess Service could not be opened for query: 0x%x", GetLastError());
+    }
     if (!svc)
         goto close_scm;
 
@@ -162,10 +166,13 @@ IsWindowsFirewallPresent(void)
 
     /* Query Windows Firewall service config, this time for real */
     flag = QueryServiceConfig(svc, pConfig, BufSize, &BufSize);
-    if (!flag)
+    if (!flag) {
+       afsi_log("QueryServiceConfig failed: 0x%x", GetLastError());
         goto free_pConfig;
+    }
 
     /* Is it autostart? */
+    afsi_log("AutoStart 0x%x", pConfig->dwStartType);
     if (pConfig->dwStartType < SERVICE_DEMAND_START)
         result = TRUE;
 
@@ -247,6 +254,10 @@ void cm_Daemon(long parm)
     HMODULE hHookDll;
     int configureFirewall = IsWindowsFirewallPresent();
 
+    if (!configureFirewall) {
+       afsi_log("No Windows Firewall detected");
+    }
+
     /* ping all file servers, up or down, with unauthenticated connection,
      * to find out whether we have all our callbacks from the server still.
      * Also, ping down VLDBs.
@@ -278,10 +289,6 @@ void cm_Daemon(long parm)
     lastTokenCacheCheck = now - cm_daemonTokenCheckInterval/2 + (rand() % cm_daemonTokenCheckInterval);
 
     while (daemon_ShutdownFlag == 0) {
-       thrd_Sleep(30 * 1000);          /* sleep 30 seconds */
-        if (daemon_ShutdownFlag == 1)
-            return;
-
        if (configureFirewall) {
            /* Open Microsoft Firewall to allow in port 7001 */
            switch (icf_CheckAndAddAFSPorts(AFS_PORTSET_CLIENT)) {
@@ -301,7 +308,7 @@ void cm_Daemon(long parm)
            default:
                afsi_log("Unknown Windows Firewall Configuration error");
            }
-       }
+       } 
 
         /* find out what time it is */
         now = osi_Time();
@@ -364,6 +371,10 @@ void cm_Daemon(long parm)
                 SetEvent(WaitToTerminate);
             }
         }
+
+       thrd_Sleep(30 * 1000);          /* sleep 30 seconds */
+        if (daemon_ShutdownFlag == 1)
+            return;
     }
 }       
 
@@ -383,13 +394,11 @@ void cm_InitDaemon(int nDaemons)
         lock_InitializeRWLock(&cm_daemonLock, "cm_daemonLock");
         osi_EndOnce(&once);
 
-#ifndef DJGPP
        /* creating IP Address Change monitor daemon */
         phandle = thrd_Create((SecurityAttrib) 0, 0,
                                (ThreadFunc) cm_IpAddrDaemon, 0, 0, &pid, "cm_IpAddrDaemon");
         osi_assert(phandle != NULL);
         thrd_CloseHandle(phandle);
-#endif /* DJGPP */
 
         /* creating pinging daemon */
         phandle = thrd_Create((SecurityAttrib) 0, 0,