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
14 #include <afs/param.h>
17 #include <afs/fs_utils.h>
19 #include <afs/afskfw.h>
20 #include "ipaddrchg.h"
24 #include <WINNT\afsreg.h> // So we can see if the server's installed
30 * DEFINITIONS ________________________________________________________________
34 const TCHAR cszCLASSNAME
[] = TEXT("AfsCreds");
38 * VARIABLES __________________________________________________________________
46 * PROTOTYPES _________________________________________________________________
50 BOOL
InitApp (LPSTR pszCmdLineA
);
53 void PumpMessage (MSG
*pmsg
);
54 BOOL
IsServerInstalled (void);
58 * ROUTINES ___________________________________________________________________
62 extern "C" int WINAPI
WinMain (HINSTANCE hInst
, HINSTANCE hPrev
, LPSTR pCmdLine
, int nCmdShow
)
65 TaLocale_LoadCorrespondingModule (hInst
);
67 osi_InitTraceOption();
68 osi_LogEvent0("AFSCreds Main command line",pCmdLine
);
69 fs_utils_InitMountRoot();
72 if (InitApp (pCmdLine
))
75 while (GetMessage (&msg
, NULL
, 0, 0) > 0)
87 #define ISHIGHSECURITY(v) ( ((v) & LOGON_OPTION_HIGHSECURITY)==LOGON_OPTION_HIGHSECURITY)
88 #define REG_CLIENT_PROVIDER_KEY "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\NetworkProvider"
90 BOOL
InitApp (LPSTR pszCmdLineA
)
95 BOOL fInstall
= FALSE
;
96 BOOL fUninstall
= FALSE
;
97 BOOL fAutoInit
= FALSE
;
98 BOOL fNetDetect
= FALSE
;
99 BOOL fRenewMaps
= FALSE
;
101 // Initialize our global variables and window classes
103 memset (&g
, 0x00, sizeof(g
));
106 // Parse the command-line
108 while (pszCmdLineA
&& *pszCmdLineA
)
110 if ((*pszCmdLineA
!= '-') && (*pszCmdLineA
!= '/'))
113 switch (*(++pszCmdLineA
))
156 CopyAnsiToString(g
.SmbName
,pszCmdLineA
);
157 MapShareName(pszCmdLineA
);
167 TestAndDoMapShare(SERVICE_START_PENDING
);
168 TestAndDoMapShare(SERVICE_RUNNING
);
172 while (*pszCmdLineA
&& (*pszCmdLineA
!= ' '))
174 if (*pszCmdLineA
==' ') ++pszCmdLineA
;
178 Shortcut_FixStartup (cszSHORTCUT_NAME
, g
.fStartup
= TRUE
);
180 Shortcut_FixStartup (cszSHORTCUT_NAME
, g
.fStartup
= FALSE
);
182 if (fInstall
|| fUninstall
)
185 if (RegCreateKeyEx (HKEY_CURRENT_USER
, AFSREG_USER_OPENAFS_SUBKEY
, 0, NULL
, 0,
186 (IsWow64()?KEY_WOW64_64KEY
:0)|KEY_WRITE
, NULL
, &hk
, NULL
) == 0)
188 DWORD dwSize
= sizeof(g
.fStartup
);
189 DWORD dwType
= REG_DWORD
;
190 RegSetValueEx (hk
, TEXT("ShowTrayIcon"), NULL
, dwType
, (PBYTE
)&g
.fStartup
, dwSize
);
195 // Only show up if there's not another version of this app around already.
197 for (HWND hSearch
= GetWindow (GetDesktopWindow(), GW_CHILD
);
198 hSearch
&& IsWindow(hSearch
);
199 hSearch
= GetWindow (hSearch
, GW_HWNDNEXT
))
201 TCHAR szClassName
[ cchRESOURCE
];
202 if (GetClassName (hSearch
, szClassName
, cchRESOURCE
))
204 if (!lstrcmpi (szClassName
, cszCLASSNAME
))
207 PostMessage (hSearch
, WM_COMMAND
, M_ACTIVATE
, 0);
209 PostMessage (hSearch
, WM_COMMAND
, M_TERMINATE_NOW
, 0);
211 PostMessage (hSearch
, WM_COMMAND
, M_TERMINATE_NOW
, 0);
217 if (fExit
|| fUninstall
|| fInstall
)
221 if (RegOpenKeyEx (HKEY_CURRENT_USER
, AFSREG_USER_OPENAFS_SUBKEY
, 0,
222 (IsWow64()?KEY_WOW64_64KEY
:0)|KEY_QUERY_VALUE
, &hk
) == 0)
224 DWORD dwSize
= sizeof(g
.fStartup
);
225 DWORD dwType
= REG_DWORD
;
226 RegQueryValueEx (hk
, TEXT("ShowTrayIcon"), NULL
, &dwType
, (PBYTE
)&g
.fStartup
, &dwSize
);
229 else if (RegOpenKeyEx (HKEY_LOCAL_MACHINE
, AFSREG_CLT_OPENAFS_SUBKEY
, 0,
230 (IsWow64()?KEY_WOW64_64KEY
:0)|KEY_QUERY_VALUE
, &hk
) == 0)
232 DWORD dwSize
= sizeof(g
.fStartup
);
233 DWORD dwType
= REG_DWORD
;
234 RegQueryValueEx (hk
, TEXT("ShowTrayIcon"), NULL
, &dwType
, (PBYTE
)&g
.fStartup
, &dwSize
);
238 Shortcut_FixStartup (cszSHORTCUT_NAME
, g
.fStartup
);
240 // Is this Windows NT?
242 OSVERSIONINFO Version
;
243 memset (&Version
, 0x00, sizeof(Version
));
244 Version
.dwOSVersionInfoSize
= sizeof(Version
);
245 if (GetVersionEx (&Version
))
246 g
.fIsWinNT
= (Version
.dwPlatformId
== VER_PLATFORM_WIN32_NT
) ? TRUE
: FALSE
;
249 lstrcpy (g
.szHelpFile
, TEXT("afs-light.hlp"));
251 lstrcpy (g
.szHelpFile
, TEXT("afs-nt.hlp"));
253 // Initialize winsock etc
256 WSAStartup (0x0101, &Data
);
258 InitCommonControls();
259 RegisterCheckListClass();
261 lock_InitializeMutex(&g
.expirationCheckLock
, "expiration check lock", 0);
262 lock_InitializeMutex(&g
.credsLock
, "global creds lock", 0);
264 KFW_AFS_wait_for_service_start();
266 if ( IsDebuggerPresent() ) {
268 OutputDebugString("No Service Present on non-NT systems\n");
270 if ( IsServiceRunning() )
271 OutputDebugString("AFSD Service started\n");
273 OutputDebugString("AFSD Service stopped\n");
274 if ( !IsServiceConfigured() )
275 OutputDebugString("AFSD Service not configured\n");
276 else if ( fAutoInit
)
277 OutputDebugString("AFSD Service will be started\n");
282 // If the service isn't started yet, and autoInit start the service
283 if ( g
.fIsWinNT
&& !IsServiceRunning() && IsServiceConfigured() && fAutoInit
) {
286 if ((hManager
= OpenSCManager( NULL
, NULL
,
288 SC_MANAGER_ENUMERATE_SERVICE
|
289 SC_MANAGER_QUERY_LOCK_STATUS
)) != NULL
)
292 if ((hService
= OpenService( hManager
, TEXT("TransarcAFSDaemon"),
293 SERVICE_QUERY_STATUS
| SERVICE_START
) ) != NULL
)
295 if (StartService(hService
, 0, 0)) {
296 if ( IsDebuggerPresent() )
297 OutputDebugString("AFSD Service start successful\n");
299 } else if ( IsDebuggerPresent() )
300 OutputDebugString("AFSD Service start failed\n");
302 CloseServiceHandle (hService
);
305 CloseServiceHandle (hManager
);
307 KFW_AFS_wait_for_service_start();
312 // Create a main window. All further initialization will be done during
313 // processing of WM_INITDIALOG.
316 if (!GetClassInfo (NULL
, WC_DIALOG
, &wc
)) // Get dialog class info
318 wc
.hInstance
= THIS_HINST
;
319 wc
.hIcon
= TaLocale_LoadIcon (IDI_MAIN
);
320 wc
.lpszClassName
= cszCLASSNAME
;
321 wc
.style
|= CS_GLOBALCLASS
;
324 g
.hMain
= ModelessDialog (IDD_MAIN
, NULL
, (DLGPROC
)Main_DlgProc
);
328 // If the service isn't started yet, show our startup wizard.
330 if (!IsServiceRunning() && !fQuiet
)
333 Message (MB_ICONHAND
, IDS_UNCONFIG_TITLE_95
, IDS_UNCONFIG_DESC_95
);
334 else if (IsServiceConfigured())
336 else if (!IsServerInstalled())
337 Message (MB_ICONHAND
, IDS_UNCONFIG_TITLE
, IDS_UNCONFIG_DESC
);
339 if (IsServiceRunning()) {
342 if ( IsDebuggerPresent() )
343 OutputDebugString("Renewing Drive Maps\n");
344 DoMapShareChange(FALSE
);
348 if ( IsDebuggerPresent() )
349 OutputDebugString("Displaying Main window\n");
352 // If the root cell is reachable and we have no tokens
353 // display the Obtain Tokens dialog to the user
355 if ( IsDebuggerPresent() )
356 OutputDebugString("Obtaining Tokens (if needed)\n");
357 ObtainTokensFromUserIfNeeded(g
.hMain
);
359 } else if ( IsDebuggerPresent() )
360 OutputDebugString("AFSD Service Stopped\n");
363 // Start IP Address Change Monitor
364 if ( IsDebuggerPresent() )
365 OutputDebugString("Activating Network Change Monitor\n");
366 IpAddrChangeMonitorInit(g
.hMain
);
368 Main_EnableRemindTimer(TRUE
);
380 void PumpMessage (MSG
*pmsg
)
382 if (!IsMemoryManagerMessage (pmsg
))
384 if (!IsDialogMessage (g
.hMain
, pmsg
))
386 TranslateMessage (pmsg
);
387 DispatchMessage (pmsg
);
395 if (IsWindow (g
.hMain
))
397 ChangeTrayIcon (NIM_DELETE
);
398 DestroyWindow (g
.hMain
);
404 BOOL
IsServerInstalled (void)
406 BOOL fInstalled
= FALSE
;
409 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE
, AFSREG_SVR_SVC_SUBKEY
, 0,
410 (IsWow64()?KEY_WOW64_64KEY
:0)|KEY_QUERY_VALUE
, &hk
) == 0)