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>
18 #include "..\afsreg\afsreg.h" // So we can see if the server's installed
25 * DEFINITIONS ________________________________________________________________
29 const TCHAR cszCLASSNAME[] = TEXT("AfsCreds");
33 * VARIABLES __________________________________________________________________
41 * PROTOTYPES _________________________________________________________________
45 BOOL InitApp (LPSTR pszCmdLineA);
47 void PumpMessage (MSG *pmsg);
48 BOOL IsServerInstalled (void);
52 * ROUTINES ___________________________________________________________________
56 extern "C" int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pCmdLine, int nCmdShow)
59 TaLocale_LoadCorrespondingModule (hInst);
61 osi_InitTraceOption();
62 osi_LogEvent0("AFSCreds Main command line",pCmdLine);
63 fs_utils_InitMountRoot();
65 if (InitApp (pCmdLine))
68 while (GetMessage (&msg, NULL, 0, 0) > 0)
80 #define ISHIGHSECURITY(v) ( ((v) & LOGON_OPTION_HIGHSECURITY)==LOGON_OPTION_HIGHSECURITY)
81 #define REG_CLIENT_PROVIDER_KEY "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\NetworkProvider"
83 BOOL InitApp (LPSTR pszCmdLineA)
88 BOOL fInstall = FALSE;
89 BOOL fUninstall = FALSE;
91 // Parse the command-line
93 while (pszCmdLineA && *pszCmdLineA)
95 if ((*pszCmdLineA != '-') && (*pszCmdLineA != '/'))
98 switch (*(++pszCmdLineA))
125 MapShareName(pszCmdLineA);
129 TestAndDoMapShare(SERVICE_START_PENDING);
130 TestAndDoMapShare(SERVICE_RUNNING);
134 while (*pszCmdLineA && (*pszCmdLineA != ' '))
136 if (*pszCmdLineA==' ') ++pszCmdLineA;
140 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = TRUE);
142 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = FALSE);
147 if (RegCreateKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
149 DWORD dwSize = sizeof(g.fStartup);
150 DWORD dwType = REG_DWORD;
151 RegSetValueEx (hk, TEXT("ShowTrayIcon"), NULL, dwType, (PBYTE)&g.fStartup, dwSize);
156 // Only show up if there's not another version of this app around already.
158 for (HWND hSearch = GetWindow (GetDesktopWindow(), GW_CHILD);
159 hSearch && IsWindow(hSearch);
160 hSearch = GetWindow (hSearch, GW_HWNDNEXT))
162 TCHAR szClassName[ cchRESOURCE ];
163 if (GetClassName (hSearch, szClassName, cchRESOURCE))
165 if (!lstrcmpi (szClassName, cszCLASSNAME))
168 PostMessage (hSearch, WM_COMMAND, M_ACTIVATE, 0);
170 PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
172 PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
178 if (fExit || fUninstall || fInstall)
181 // Initialize our global variables and window classes
183 memset (&g, 0x00, sizeof(g));
187 if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
189 DWORD dwSize = sizeof(g.fStartup);
190 DWORD dwType = REG_DWORD;
191 RegQueryValueEx (hk, TEXT("ShowTrayIcon"), NULL, &dwType, (PBYTE)&g.fStartup, &dwSize);
195 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup);
197 // Is this Windows NT?
199 OSVERSIONINFO Version;
200 memset (&Version, 0x00, sizeof(Version));
201 Version.dwOSVersionInfoSize = sizeof(Version);
202 if (GetVersionEx (&Version))
203 g.fIsWinNT = (Version.dwPlatformId == VER_PLATFORM_WIN32_NT) ? TRUE : FALSE;
206 lstrcpy (g.szHelpFile, TEXT("afs-light.hlp"));
208 lstrcpy (g.szHelpFile, TEXT("afs-nt.hlp"));
210 // Initialize winsock etc
213 WSAStartup (0x0101, &Data);
215 InitCommonControls();
216 RegisterCheckListClass();
218 lock_InitializeMutex(&g.expirationCheckLock, "expiration check lock");
219 lock_InitializeMutex(&g.credsLock, "global creds lock");
221 if ( IsDebuggerPresent() ) {
223 OutputDebugString("No Service Present on non-NT systems\n");
225 if ( IsServiceRunning() )
226 OutputDebugString("AFSD Service started\n");
228 OutputDebugString("AFSD Service stopped\n");
229 if ( !IsServiceConfigured() )
230 OutputDebugString("AFSD Service not configured\n");
235 // Create a main window. All further initialization will be done during
236 // processing of WM_INITDIALOG.
239 if (!GetClassInfo (NULL, WC_DIALOG, &wc)) // Get dialog class info
241 wc.hInstance = THIS_HINST;
242 wc.hIcon = TaLocale_LoadIcon (IDI_MAIN);
243 wc.lpszClassName = cszCLASSNAME;
244 wc.style |= CS_GLOBALCLASS;
247 g.hMain = ModelessDialog (IDD_MAIN, NULL, (DLGPROC)Main_DlgProc);
251 // If the service isn't started yet, show our startup wizard.
253 if (!IsServiceRunning() && !fQuiet)
256 Message (MB_ICONHAND, IDS_UNCONFIG_TITLE_95, IDS_UNCONFIG_DESC_95);
257 else if (IsServiceConfigured())
259 else if (!IsServerInstalled())
260 Message (MB_ICONHAND, IDS_UNCONFIG_TITLE, IDS_UNCONFIG_DESC);
262 if (IsServiceRunning()) {
265 if ( IsDebuggerPresent() )
266 OutputDebugString("Displaying Main window\n");
269 } else if ( IsDebuggerPresent() )
270 OutputDebugString("Displaying Main window\n");
281 void PumpMessage (MSG *pmsg)
283 if (!IsMemoryManagerMessage (pmsg))
285 if (!IsDialogMessage (g.hMain, pmsg))
287 TranslateMessage (pmsg);
288 DispatchMessage (pmsg);
296 if (IsWindow (g.hMain))
298 ChangeTrayIcon (NIM_DELETE);
299 DestroyWindow (g.hMain);
305 BOOL IsServerInstalled (void)
307 BOOL fInstalled = FALSE;
309 TCHAR szKey[] = AFSREG_SVR_SVC_KEY;
310 LPCTSTR pch = lstrchr (szKey, TEXT('\\'));
313 if (RegOpenKey (HKEY_LOCAL_MACHINE, &pch[1], &hk) == 0)