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);
48 void PumpMessage (MSG *pmsg);
49 BOOL IsServerInstalled (void);
53 * ROUTINES ___________________________________________________________________
57 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pCmdLine, int nCmdShow)
60 TaLocale_LoadCorrespondingModule (hInst);
62 osi_InitTraceOption();
63 osi_LogEvent0("AFSCreds Main command line",pCmdLine);
64 fs_utils_InitMountRoot();
66 if (InitApp (pCmdLine))
69 while (GetMessage (&msg, NULL, 0, 0) > 0)
81 #define ISHIGHSECURITY(v) ( ((v) & LOGON_OPTION_HIGHSECURITY)==LOGON_OPTION_HIGHSECURITY)
82 #define REG_CLIENT_PROVIDER_KEY "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\NetworkProvider"
84 BOOL InitApp (LPSTR pszCmdLineA)
89 BOOL fInstall = FALSE;
90 BOOL fUninstall = FALSE;
92 // Parse the command-line
94 while (pszCmdLineA && *pszCmdLineA)
96 if ((*pszCmdLineA != '-') && (*pszCmdLineA != '/'))
99 switch (*(++pszCmdLineA))
126 MapShareName(pszCmdLineA);
130 TestAndDoMapShare(SERVICE_START_PENDING);
131 TestAndDoMapShare(SERVICE_RUNNING);
135 while (*pszCmdLineA && (*pszCmdLineA != ' '))
137 if (*pszCmdLineA==' ') ++pszCmdLineA;
141 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = TRUE);
143 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = FALSE);
148 if (RegCreateKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
150 DWORD dwSize = sizeof(g.fStartup);
151 DWORD dwType = REG_DWORD;
152 RegSetValueEx (hk, TEXT("ShowTrayIcon"), NULL, dwType, (PBYTE)&g.fStartup, dwSize);
157 // Only show up if there's not another version of this app around already.
159 for (HWND hSearch = GetWindow (GetDesktopWindow(), GW_CHILD);
160 hSearch && IsWindow(hSearch);
161 hSearch = GetWindow (hSearch, GW_HWNDNEXT))
163 TCHAR szClassName[ cchRESOURCE ];
164 if (GetClassName (hSearch, szClassName, cchRESOURCE))
166 if (!lstrcmpi (szClassName, cszCLASSNAME))
169 PostMessage (hSearch, WM_COMMAND, M_ACTIVATE, 0);
171 PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
173 PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
179 if (fExit || fUninstall || fInstall)
182 // Initialize our global variables and window classes
184 memset (&g, 0x00, sizeof(g));
188 if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
190 DWORD dwSize = sizeof(g.fStartup);
191 DWORD dwType = REG_DWORD;
192 RegQueryValueEx (hk, TEXT("ShowTrayIcon"), NULL, &dwType, (PBYTE)&g.fStartup, &dwSize);
196 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup);
198 // Is this Windows NT?
200 OSVERSIONINFO Version;
201 memset (&Version, 0x00, sizeof(Version));
202 Version.dwOSVersionInfoSize = sizeof(Version);
203 if (GetVersionEx (&Version))
204 g.fIsWinNT = (Version.dwPlatformId == VER_PLATFORM_WIN32_NT) ? TRUE : FALSE;
207 lstrcpy (g.szHelpFile, TEXT("afs-light.hlp"));
209 lstrcpy (g.szHelpFile, TEXT("afs-nt.hlp"));
211 // Initialize winsock etc
214 WSAStartup (0x0101, &Data);
216 InitCommonControls();
217 RegisterCheckListClass();
219 lock_InitializeMutex(&g.expirationCheckLock, "expiration check lock");
220 lock_InitializeMutex(&g.credsLock, "global creds lock");
222 if ( IsDebuggerPresent() ) {
224 OutputDebugString("No Service Present on non-NT systems\n");
226 if ( IsServiceRunning() )
227 OutputDebugString("AFSD Service started\n");
229 OutputDebugString("AFSD Service stopped\n");
230 if ( !IsServiceConfigured() )
231 OutputDebugString("AFSD Service not configured\n");
236 // Create a main window. All further initialization will be done during
237 // processing of WM_INITDIALOG.
240 if (!GetClassInfo (NULL, WC_DIALOG, &wc)) // Get dialog class info
242 wc.hInstance = THIS_HINST;
243 wc.hIcon = TaLocale_LoadIcon (IDI_MAIN);
244 wc.lpszClassName = cszCLASSNAME;
245 wc.style |= CS_GLOBALCLASS;
248 g.hMain = ModelessDialog (IDD_MAIN, NULL, (DLGPROC)Main_DlgProc);
252 // If the service isn't started yet, show our startup wizard.
254 if (!IsServiceRunning() && !fQuiet)
257 Message (MB_ICONHAND, IDS_UNCONFIG_TITLE_95, IDS_UNCONFIG_DESC_95);
258 else if (IsServiceConfigured())
260 else if (!IsServerInstalled())
261 Message (MB_ICONHAND, IDS_UNCONFIG_TITLE, IDS_UNCONFIG_DESC);
263 if (IsServiceRunning()) {
266 if ( IsDebuggerPresent() )
267 OutputDebugString("Displaying Main window\n");
270 } else if ( IsDebuggerPresent() )
271 OutputDebugString("Displaying Main window\n");
282 void PumpMessage (MSG *pmsg)
284 if (!IsMemoryManagerMessage (pmsg))
286 if (!IsDialogMessage (g.hMain, pmsg))
288 TranslateMessage (pmsg);
289 DispatchMessage (pmsg);
297 if (IsWindow (g.hMain))
299 ChangeTrayIcon (NIM_DELETE);
300 DestroyWindow (g.hMain);
306 BOOL IsServerInstalled (void)
308 BOOL fInstalled = FALSE;
310 TCHAR szKey[] = AFSREG_SVR_SVC_KEY;
311 LPCTSTR pch = lstrchr (szKey, TEXT('\\'));
314 if (RegOpenKey (HKEY_LOCAL_MACHINE, &pch[1], &hk) == 0)