DWORD dwDisp;
TCHAR value = TEXT("7001:UDP:*:Enabled:AFS Cache Manager Callback");
if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
- "SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\DomainProfile\GloballyOpenP",
+ "SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\DomainProfile\\GloballyOpenP",
0, TEXT("container"), 0, KEY_SET_VALUE, NULL, &hk, &dwDisp) == ERROR_SUCCESS)
{
RegSetValueEx (hk, TEXT("7001:UDP"), NULL, REG_SZ, (PBYTE)value, sizeof(TCHAR) * (1+lstrlen(value)));
RegCloseKey (hk);
}
if (RegCreateKeyEx (HKEY_LOCAL_MACHINE,
- "SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\GloballyOpenP",
+ "SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\\GloballyOpenP",
0, TEXT("container"), 0, KEY_SET_VALUE, NULL, &hk, &dwDisp) == ERROR_SUCCESS)
{
RegSetValueEx (hk, TEXT("7001:UDP"), NULL, REG_SZ, (PBYTE)value, sizeof(TCHAR) * (1+lstrlen(value)));
return dwRet;
}
-#if 1
-/* This code was moved to Drivemap.cpp*/
-/* Mount a drive into AFS if the user wants us to */
+/* There is similar code in client_config\drivemap.cpp GlobalMountDrive()
+ *
+ * Mount a drive into AFS if there global mapping
+ */
/* DEE Could check first if we are run as SYSTEM */
-void CheckMountDrive()
+static void MountGlobalDrives()
{
- char szAfsPath[_MAX_PATH];
- char szDriveToMapTo[5];
- DWORD dwResult;
- char szKeyName[256];
- HKEY hKey;
- DWORD dwIndex = 0;
- DWORD dwDriveSize;
- DWORD dwSubMountSize;
- char szSubMount[256];
- DWORD dwType;
-
- sprintf(szKeyName, "%s\\GlobalAutoMapper", AFSConfigKeyName);
+ char szAfsPath[_MAX_PATH];
+ char szDriveToMapTo[5];
+ DWORD dwResult;
+ char szKeyName[256];
+ HKEY hKey;
+ DWORD dwIndex = 0;
+ DWORD dwDriveSize;
+ DWORD dwSubMountSize;
+ char szSubMount[256];
+ DWORD dwType;
+
+ sprintf(szKeyName, "%s\\GlobalAutoMapper", AFSConfigKeyName);
dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_QUERY_VALUE, &hKey);
if (dwResult != ERROR_SUCCESS)
- return;
-
- while (1) {
- dwDriveSize = sizeof(szDriveToMapTo);
- dwSubMountSize = sizeof(szSubMount);
- dwResult = RegEnumValue(hKey, dwIndex++, szDriveToMapTo, &dwDriveSize, 0, &dwType, szSubMount, &dwSubMountSize);
- if (dwResult != ERROR_MORE_DATA) {
- if (dwResult != ERROR_SUCCESS) {
- if (dwResult != ERROR_NO_MORE_ITEMS)
- afsi_log("Failed to read GlobalAutoMapper values: %d\n", dwResult);
- break;
- }
- }
-
-#if 0
- sprintf(szAfsPath, "\\Device\\LanmanRedirector\\%s\\%s-AFS\\%s", szDriveToMapTo, cm_HostName, szSubMount);
-
- dwResult = DefineDosDevice(DDD_RAW_TARGET_PATH, szDriveToMapTo, szAfsPath);
-#else
+ return;
+
+ while (1) {
+ dwDriveSize = sizeof(szDriveToMapTo);
+ dwSubMountSize = sizeof(szSubMount);
+ dwResult = RegEnumValue(hKey, dwIndex++, szDriveToMapTo, &dwDriveSize, 0, &dwType, szSubMount, &dwSubMountSize);
+ if (dwResult != ERROR_MORE_DATA) {
+ if (dwResult != ERROR_SUCCESS) {
+ if (dwResult != ERROR_NO_MORE_ITEMS)
+ afsi_log("Failed to read GlobalAutoMapper values: %d\n", dwResult);
+ break;
+ }
+ }
+
{
NETRESOURCE nr;
memset (&nr, 0x00, sizeof(NETRESOURCE));
- sprintf(szAfsPath,"\\\\%s-AFS\\%s",cm_HostName,szSubMount);
+ sprintf(szAfsPath,"\\\\%s\\%s",cm_NetbiosName,szSubMount);
nr.dwScope = RESOURCE_GLOBALNET;
nr.dwType=RESOURCETYPE_DISK;
dwResult = WNetAddConnection2(&nr,NULL,NULL,FALSE);
}
-#endif
- afsi_log("GlobalAutoMap of %s to %s %s", szDriveToMapTo, szSubMount, dwResult ? "succeeded" : "failed");
- }
+ afsi_log("GlobalAutoMap of %s to %s %s", szDriveToMapTo, szSubMount, dwResult ? "succeeded" : "failed");
+ }
- RegCloseKey(hKey);
+ RegCloseKey(hKey);
+}
+
+static void DismountGlobalDrives()
+{
+ char szAfsPath[_MAX_PATH];
+ char szDriveToMapTo[5];
+ DWORD dwResult;
+ char szKeyName[256];
+ HKEY hKey;
+ DWORD dwIndex = 0;
+ DWORD dwDriveSize;
+ DWORD dwSubMountSize;
+ char szSubMount[256];
+ DWORD dwType;
+
+ sprintf(szKeyName, "%s\\GlobalAutoMapper", AFSConfigKeyName);
+
+ dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_QUERY_VALUE, &hKey);
+ if (dwResult != ERROR_SUCCESS)
+ return;
+
+ while (1) {
+ dwDriveSize = sizeof(szDriveToMapTo);
+ dwSubMountSize = sizeof(szSubMount);
+ dwResult = RegEnumValue(hKey, dwIndex++, szDriveToMapTo, &dwDriveSize, 0, &dwType, szSubMount, &dwSubMountSize);
+ if (dwResult != ERROR_MORE_DATA) {
+ if (dwResult != ERROR_SUCCESS) {
+ if (dwResult != ERROR_NO_MORE_ITEMS)
+ afsi_log("Failed to read GlobalAutoMapper values: %d\n", dwResult);
+ break;
+ }
+ }
+
+ sprintf(szAfsPath,"\\\\%s\\%s",cm_NetbiosName,szSubMount);
+
+ dwResult = WNetCancelConnection(szAfsPath, TRUE);
+
+ afsi_log("Disconnect from GlobalAutoMap of %s to %s %s", szDriveToMapTo, szSubMount, dwResult ? "succeeded" : "failed");
+ }
+
+ RegCloseKey(hKey);
}
-#endif
typedef BOOL ( APIENTRY * AfsdInitHook )(void);
#define AFSD_INIT_HOOK "AfsdInitHook"
_CRTDBG_CHECK_CRT_DF /* | _CRTDBG_DELAY_FREE_MEM_DF */ );
#endif
- osi_InitPanic(afsd_notifier);
+ osi_InitPanic(afsd_notifier);
osi_InitTraceOption();
GlobalStatus = 0;
afsi_log("Event Object Already Exists: %s", TEXT("afsd_service_WaitToTerminate"));
#ifndef NOTSERVICE
- StatusHandle = RegisterServiceCtrlHandlerEx(AFS_DAEMON_SERVICE_NAME,
+ StatusHandle = RegisterServiceCtrlHandlerEx(argv[0] /* AFS_DAEMON_SERVICE_NAME */,
(LPHANDLER_FUNCTION_EX) afsd_ServiceControlHandlerEx,
NULL /* user context */
);
osi_panic(reason, __FILE__, __LINE__);
}
+ MountGlobalDrives();
+
#ifndef NOTSERVICE
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
ServiceStatus.dwWin32ExitCode = NO_ERROR;
}
}
- /* Check if we should mount a drive into AFS */
- CheckMountDrive();
-
WaitForSingleObject(WaitToTerminate, INFINITE);
{
DeregisterEventSource(h);
}
+ DismountGlobalDrives();
+ smb_Shutdown();
+ rx_Finalize();
+
#ifdef REGISTER_POWER_NOTIFICATIONS
/* terminate thread used to flush cache */
PowerNotificationThreadExit();
if ( hInitHookDll )
FreeLibrary(hInitHookDll);
+ Sleep(5000);
+
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
ServiceStatus.dwWin32ExitCode = GlobalStatus ? ERROR_EXCEPTION_IN_SERVICE : NO_ERROR;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
ServiceStatus.dwControlsAccepted = 0;
SetServiceStatus(StatusHandle, &ServiceStatus);
+
}
DWORD __stdcall afsdMain_thread(void* notUsed)
{
afsd_Main(0, (LPTSTR*)NULL);
- exit(0);
+ return(0);
}
int
hAFSDMainThread = CreateThread(NULL, 0, afsdMain_thread, 0, 0, &tid);
printf("Hit <Enter> to terminate OpenAFS Client Service\n");
- getchar();
+ getchar();
SetEvent(WaitToTerminate);
}
}
smb_user_t *loggedOutUserp = NULL;
unsigned long loggedOutTime;
int loggedOut = 0;
-#ifdef DJGPP
int smbShutdownFlag = 0;
-#endif /* DJGPP */
int smb_LogoffTokenTransfer;
unsigned long smb_LogoffTransferTimeout;
smb_ioctl_t *ioctlp;
if (!fidp)
- return NULL;
+ return;
scp = NULL;
lock_ObtainWrite(&smb_rctLock);
while (1) {
memset(ncbp, 0, sizeof(NCB));
flags = 0;
-#ifdef DJGPP
- /* terminate if shutdown flag is set */
- if (smbShutdownFlag == 1)
- thrd_Exit(1);
-#endif /* DJGPP */
#ifndef NOEXPIRE
/* check for demo expiration */
(*smb_MBfunc)(NULL, "AFS demo expiration",
"afsd listener",
MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
- ExitThread(1);
+#ifndef DJGPP
+ ExitThread(1);
+#else
+ thrd_Exit(1);
+#endif
}
}
#endif /* !NOEXPIRE */
code = Netbios(ncbp);
#else /* DJGPP */
code = Netbios(ncbp, dos_ncb);
+#endif
if (code != 0)
{
+ /* terminate if shutdown flag is set */
+ if (smbShutdownFlag == 1) {
+#ifndef DJGPP
+ ExitThread(1);
+#else
+ thrd_Exit(1);
+#endif
+ }
+
+#ifndef DJGPP
+ osi_assert(0);
+#else
fprintf(stderr, "NCBLISTEN lana=%d failed with code %d\n",
ncbp->ncb_lana_num, code);
osi_Log2(0, "NCBLISTEN lana=%d failed with code %d",
"(possibly due to power-saving mode)\n");
fprintf(stderr, "Please restart client.\n");
afs_exit(AFS_EXITCODE_NETWORK_FAILURE);
- }
#endif /* !DJGPP */
-
- osi_assert(code == 0);
+ }
/* check for remote conns */
/* first get remote name and insert null terminator */
/* unlock */
lock_ReleaseMutex(&smb_ListenerLock);
- } /* dispatch while loop */
+ } /* dispatch while loop */
}
/* initialize Netbios */
return;
}
-#ifdef DJGPP
void smb_Shutdown(void)
{
NCB *ncbp;
+#ifdef DJGPP
dos_ptr dos_ncb;
+#endif
long code;
int i;
/* setup the NCB system */
ncbp = GetNCB();
+#ifdef DJGPP
dos_ncb = ((smb_ncb_t *)ncbp)->dos_ncb;
+#endif
/* Block new sessions by setting shutdown flag */
- /*smbShutdownFlag = 1;*/
+ smbShutdownFlag = 1;
/* Hang up all sessions */
+ memset((char *)ncbp, 0, sizeof(NCB));
for (i = 1; i < numSessions; i++)
{
if (dead_sessions[i])
continue;
-
+
/*fprintf(stderr, "NCBHANGUP session %d LSN %d\n", i, LSNs[i]);*/
ncbp->ncb_command = NCBHANGUP;
ncbp->ncb_lana_num = lanas[i]; /*smb_LANadapter;*/
ncbp->ncb_lsn = LSNs[i];
- code = Netbios(ncbp, dos_ncb);
+#ifndef DJGPP
+ code = Netbios(ncbp);
+#else
+ code = Netbios(ncbp, dos_ncb);
+#endif
/*fprintf(stderr, "returned from NCBHANGUP session %d LSN %d\n", i, LSNs[i]);*/
if (code == 0) code = ncbp->ncb_retcode;
if (code != 0) {
+ osi_Log1(afsd_logp, "Netbios NCBHANGUP error code %d", code);
fprintf(stderr, "Session %d Netbios NCBHANGUP error code %d", i, code);
}
- }
+ }
-#if 1
/* Delete Netbios name */
+ memset((char *)ncbp, 0, sizeof(NCB));
for (i = 0; i < lana_list.length; i++) {
if (lana_list.lana[i] == 255) continue;
ncbp->ncb_command = NCBDELNAME;
ncbp->ncb_lana_num = lana_list.lana[i];
memcpy(ncbp->ncb_name,smb_sharename,NCBNAMSZ);
+#ifndef DJGPP
+ code = Netbios(ncbp);
+#else
code = Netbios(ncbp, dos_ncb);
+#endif
if (code == 0) code = ncbp->ncb_retcode;
if (code != 0) {
fprintf(stderr, "Netbios NCBDELNAME lana %d error code %d",
}
fflush(stderr);
}
-#endif
}
-#endif /* DJGPP */
/* Get the UNC \\<servername>\<sharename> prefix. */
char *smb_GetSharename()