2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #include <afs/param.h>
14 #include <afs/fs_utils.h>
16 #include <afs/afskfw.h>
17 #include "ipaddrchg.h"
21 #include <WINNT\afsreg.h> // So we can see if the server's installed
27 * DEFINITIONS ________________________________________________________________
31 const TCHAR cszCLASSNAME[] = TEXT("AfsCreds");
35 * VARIABLES __________________________________________________________________
43 * PROTOTYPES _________________________________________________________________
47 BOOL InitApp (LPSTR pszCmdLineA);
50 void PumpMessage (MSG *pmsg);
51 BOOL IsServerInstalled (void);
55 * ROUTINES ___________________________________________________________________
59 extern "C" int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pCmdLine, int nCmdShow)
62 TaLocale_LoadCorrespondingModule (hInst);
64 osi_InitTraceOption();
65 osi_LogEvent0("AFSCreds Main command line",pCmdLine);
66 fs_utils_InitMountRoot();
68 if (InitApp (pCmdLine))
71 while (GetMessage (&msg, NULL, 0, 0) > 0)
83 #define ISHIGHSECURITY(v) ( ((v) & LOGON_OPTION_HIGHSECURITY)==LOGON_OPTION_HIGHSECURITY)
84 #define REG_CLIENT_PROVIDER_KEY "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\NetworkProvider"
86 BOOL InitApp (LPSTR pszCmdLineA)
91 BOOL fInstall = FALSE;
92 BOOL fUninstall = FALSE;
93 BOOL fAutoInit = FALSE;
94 BOOL fNetDetect = FALSE;
95 BOOL fRenewMaps = FALSE;
97 // Initialize our global variables and window classes
99 memset (&g, 0x00, sizeof(g));
102 // Parse the command-line
104 while (pszCmdLineA && *pszCmdLineA)
106 if ((*pszCmdLineA != '-') && (*pszCmdLineA != '/'))
109 switch (*(++pszCmdLineA))
152 CopyAnsiToString(g.SmbName,pszCmdLineA);
153 MapShareName(pszCmdLineA);
163 TestAndDoMapShare(SERVICE_START_PENDING);
164 TestAndDoMapShare(SERVICE_RUNNING);
168 while (*pszCmdLineA && (*pszCmdLineA != ' '))
170 if (*pszCmdLineA==' ') ++pszCmdLineA;
174 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = TRUE);
176 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = FALSE);
181 if (RegCreateKey (HKEY_CURRENT_USER, AFSREG_USER_OPENAFS_SUBKEY, &hk) == 0)
183 DWORD dwSize = sizeof(g.fStartup);
184 DWORD dwType = REG_DWORD;
185 RegSetValueEx (hk, TEXT("ShowTrayIcon"), NULL, dwType, (PBYTE)&g.fStartup, dwSize);
190 // Only show up if there's not another version of this app around already.
192 for (HWND hSearch = GetWindow (GetDesktopWindow(), GW_CHILD);
193 hSearch && IsWindow(hSearch);
194 hSearch = GetWindow (hSearch, GW_HWNDNEXT))
196 TCHAR szClassName[ cchRESOURCE ];
197 if (GetClassName (hSearch, szClassName, cchRESOURCE))
199 if (!lstrcmpi (szClassName, cszCLASSNAME))
202 PostMessage (hSearch, WM_COMMAND, M_ACTIVATE, 0);
204 PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
206 PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
212 if (fExit || fUninstall || fInstall)
216 if (RegOpenKey (HKEY_CURRENT_USER, AFSREG_USER_OPENAFS_SUBKEY, &hk) == 0)
218 DWORD dwSize = sizeof(g.fStartup);
219 DWORD dwType = REG_DWORD;
220 RegQueryValueEx (hk, TEXT("ShowTrayIcon"), NULL, &dwType, (PBYTE)&g.fStartup, &dwSize);
223 else if (RegOpenKey (HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY, &hk) == 0)
225 DWORD dwSize = sizeof(g.fStartup);
226 DWORD dwType = REG_DWORD;
227 RegQueryValueEx (hk, TEXT("ShowTrayIcon"), NULL, &dwType, (PBYTE)&g.fStartup, &dwSize);
231 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup);
233 // Is this Windows NT?
235 OSVERSIONINFO Version;
236 memset (&Version, 0x00, sizeof(Version));
237 Version.dwOSVersionInfoSize = sizeof(Version);
238 if (GetVersionEx (&Version))
239 g.fIsWinNT = (Version.dwPlatformId == VER_PLATFORM_WIN32_NT) ? TRUE : FALSE;
242 lstrcpy (g.szHelpFile, TEXT("afs-light.hlp"));
244 lstrcpy (g.szHelpFile, TEXT("afs-nt.hlp"));
246 // Initialize winsock etc
249 WSAStartup (0x0101, &Data);
251 InitCommonControls();
252 RegisterCheckListClass();
254 lock_InitializeMutex(&g.expirationCheckLock, "expiration check lock");
255 lock_InitializeMutex(&g.credsLock, "global creds lock");
257 KFW_AFS_wait_for_service_start();
259 if ( IsDebuggerPresent() ) {
261 OutputDebugString("No Service Present on non-NT systems\n");
263 if ( IsServiceRunning() )
264 OutputDebugString("AFSD Service started\n");
266 OutputDebugString("AFSD Service stopped\n");
267 if ( !IsServiceConfigured() )
268 OutputDebugString("AFSD Service not configured\n");
269 else if ( fAutoInit )
270 OutputDebugString("AFSD Service will be started\n");
275 // If the service isn't started yet, and autoInit start the service
276 if ( g.fIsWinNT && !IsServiceRunning() && IsServiceConfigured() && fAutoInit ) {
279 if ((hManager = OpenSCManager( NULL, NULL,
281 SC_MANAGER_ENUMERATE_SERVICE |
282 SC_MANAGER_QUERY_LOCK_STATUS)) != NULL )
285 if ((hService = OpenService( hManager, TEXT("TransarcAFSDaemon"),
286 SERVICE_QUERY_STATUS | SERVICE_START) ) != NULL)
288 if (StartService(hService, 0, 0)) {
289 if ( IsDebuggerPresent() )
290 OutputDebugString("AFSD Service start successful\n");
292 } else if ( IsDebuggerPresent() )
293 OutputDebugString("AFSD Service start failed\n");
295 CloseServiceHandle (hService);
298 CloseServiceHandle (hManager);
300 KFW_AFS_wait_for_service_start();
305 // Create a main window. All further initialization will be done during
306 // processing of WM_INITDIALOG.
309 if (!GetClassInfo (NULL, WC_DIALOG, &wc)) // Get dialog class info
311 wc.hInstance = THIS_HINST;
312 wc.hIcon = TaLocale_LoadIcon (IDI_MAIN);
313 wc.lpszClassName = cszCLASSNAME;
314 wc.style |= CS_GLOBALCLASS;
317 g.hMain = ModelessDialog (IDD_MAIN, NULL, (DLGPROC)Main_DlgProc);
321 // If the service isn't started yet, show our startup wizard.
323 if (!IsServiceRunning() && !fQuiet)
326 Message (MB_ICONHAND, IDS_UNCONFIG_TITLE_95, IDS_UNCONFIG_DESC_95);
327 else if (IsServiceConfigured())
329 else if (!IsServerInstalled())
330 Message (MB_ICONHAND, IDS_UNCONFIG_TITLE, IDS_UNCONFIG_DESC);
332 if (IsServiceRunning()) {
335 if ( IsDebuggerPresent() )
336 OutputDebugString("Renewing Drive Maps\n");
341 if ( IsDebuggerPresent() )
342 OutputDebugString("Displaying Main window\n");
345 // If the root cell is reachable and we have no tokens
346 // display the Obtain Tokens dialog to the user
348 if ( IsDebuggerPresent() )
349 OutputDebugString("Obtaining Tokens (if needed)\n");
350 ObtainTokensFromUserIfNeeded(g.hMain);
352 } else if ( IsDebuggerPresent() )
353 OutputDebugString("AFSD Service Stopped\n");
356 // Start IP Address Change Monitor
357 if ( IsDebuggerPresent() )
358 OutputDebugString("Activating Network Change Monitor\n");
359 IpAddrChangeMonitorInit(g.hMain);
361 Main_EnableRemindTimer(TRUE);
373 void PumpMessage (MSG *pmsg)
375 if (!IsMemoryManagerMessage (pmsg))
377 if (!IsDialogMessage (g.hMain, pmsg))
379 TranslateMessage (pmsg);
380 DispatchMessage (pmsg);
388 if (IsWindow (g.hMain))
390 ChangeTrayIcon (NIM_DELETE);
391 DestroyWindow (g.hMain);
397 BOOL IsServerInstalled (void)
399 BOOL fInstalled = FALSE;
402 if (RegOpenKey (HKEY_LOCAL_MACHINE, AFSREG_SVR_SVC_SUBKEY, &hk) == 0)