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>
13 #include <afs/afskfw.h>
22 * PROTOTYPES _________________________________________________________________
26 void Advanced_OnInitDialog (HWND hDlg);
27 void Advanced_StartTimer (HWND hDlg);
28 void Advanced_OnServiceTimer (HWND hDlg);
29 void Advanced_OnOpenCPL (HWND hDlg);
30 void Advanced_OnChangeService (HWND hDlg, WORD wCmd);
31 void Advanced_OnStartup (HWND hDlg);
35 * ROUTINES ___________________________________________________________________
39 BOOL CALLBACK Advanced_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
45 GetClientRect (GetParent(hDlg), &rTab);
46 TabCtrl_AdjustRect (GetParent (hDlg), FALSE, &rTab);
47 SetWindowPos (hDlg, NULL, rTab.left, rTab.top, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
49 Advanced_OnInitDialog (hDlg);
53 Advanced_OnServiceTimer (hDlg);
59 case IDC_SERVICE_STOP:
60 case IDC_SERVICE_START:
61 case IDC_SERVICE_AUTO:
62 Advanced_OnChangeService (hDlg, LOWORD(wp));
66 Advanced_OnOpenCPL (hDlg);
70 Advanced_OnStartup (hDlg);
74 Advanced_DlgProc (hDlg, WM_HELP, 0, 0);
80 WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCREDS_TAB_ADVANCED);
87 void Advanced_OnInitDialog (HWND hDlg)
89 CheckDlgButton (hDlg, IDC_STARTUP, g.fStartup);
90 Advanced_OnServiceTimer (hDlg);
91 Advanced_StartTimer (hDlg);
95 void Advanced_StartTimer (HWND hDlg)
97 KillTimer (hDlg, ID_SERVICE_TIMER);
98 SetTimer (hDlg, ID_SERVICE_TIMER, (ULONG)cmsecSERVICE, NULL);
102 void Advanced_OnServiceTimer (HWND hDlg)
108 QUERY_SERVICE_CONFIG Config;
111 memset (&Config, 0x00, sizeof(Config));
112 Config.Config.dwStartType = SERVICE_DEMAND_START;
114 SERVICE_STATUS Status;
115 memset (&Status, 0x00, sizeof(Status));
116 Status.dwCurrentState = SERVICE_STOPPED;
119 if ((hManager = OpenSCManager (NULL, NULL, GENERIC_READ)) != NULL)
122 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"), GENERIC_READ)) != NULL)
125 DWORD dwSize = sizeof(Config);
126 QueryServiceConfig (hService, (QUERY_SERVICE_CONFIG*)&Config, sizeof(Config), &dwSize);
127 QueryServiceStatus (hService, &Status);
128 TestAndDoMapShare(Status.dwCurrentState);
130 CloseServiceHandle (hService);
133 CloseServiceHandle (hManager);
138 if ((Status.dwCurrentState == SERVICE_STOP_PENDING) ||
139 (Status.dwCurrentState == SERVICE_START_PENDING))
145 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_START), fFound && (Status.dwCurrentState == SERVICE_STOPPED));
146 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_STOP), fFound && (Status.dwCurrentState == SERVICE_RUNNING));
147 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_AUTO), fFound);
148 CheckDlgButton (hDlg, IDC_SERVICE_AUTO, fFound && (Config.Config.dwStartType == SERVICE_AUTO_START));
150 TCHAR szStatus[cchRESOURCE];
152 GetString (szStatus, IDS_SERVICE_BROKEN);
153 else if (Status.dwCurrentState == SERVICE_RUNNING)
154 GetString (szStatus, IDS_SERVICE_RUNNING);
155 else if (Status.dwCurrentState == SERVICE_STOPPED)
156 GetString (szStatus, IDS_SERVICE_STOPPED);
157 else if (Status.dwCurrentState == SERVICE_STOP_PENDING)
158 GetString (szStatus, IDS_SERVICE_STOPPING);
159 else if (Status.dwCurrentState == SERVICE_START_PENDING)
160 GetString (szStatus, IDS_SERVICE_STARTING);
162 GetString (szStatus, IDS_SERVICE_UNKNOWN);
163 TestAndDoMapShare(Status.dwCurrentState);
164 SetDlgItemText (hDlg, IDC_SERVICE_STATUS, szStatus);
166 if (fFinal && GetWindowLong (hDlg, DWL_USER))
168 SetWindowLong (hDlg, DWL_USER, 0);
169 Main_RepopulateTabs (FALSE);
174 KillTimer (hDlg, ID_SERVICE_TIMER);
179 void Advanced_OnChangeService (HWND hDlg, WORD wCmd)
181 BOOL fSuccess = FALSE;
183 SC_HANDLE hManager, hService;
187 case IDC_SERVICE_AUTO:
189 if ((hManager = OpenSCManager (NULL, NULL, SC_MANAGER_CONNECT |
190 SC_MANAGER_ENUMERATE_SERVICE |
191 SC_MANAGER_QUERY_LOCK_STATUS)) != NULL)
193 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"),
194 SERVICE_CHANGE_CONFIG | SERVICE_QUERY_CONFIG |
195 SERVICE_QUERY_STATUS)) != NULL)
197 StartType = (IsDlgButtonChecked (hDlg, wCmd)) ? SERVICE_AUTO_START : SERVICE_DEMAND_START;
198 if (ChangeServiceConfig (hService, SERVICE_NO_CHANGE, StartType,
199 SERVICE_NO_CHANGE, 0, 0, 0, 0, 0, 0, 0))
201 CloseServiceHandle (hService);
203 CloseServiceHandle (hManager);
207 case IDC_SERVICE_START:
208 if ((hManager = OpenSCManager (NULL, NULL, SC_MANAGER_CONNECT |
209 SC_MANAGER_ENUMERATE_SERVICE |
210 SC_MANAGER_QUERY_LOCK_STATUS )) != NULL)
212 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"),
213 SERVICE_QUERY_STATUS | SERVICE_START)) != NULL)
215 if (StartService (hService, 0, 0))
217 TestAndDoMapShare(SERVICE_START_PENDING);
218 if ( KFW_is_available() && KFW_AFS_wait_for_service_start() ) {
220 KFW_import_windows_lsa();
221 #endif /* USE_MS2MIT */
222 KFW_AFS_renew_tokens_for_all_cells();
226 CloseServiceHandle (hService);
228 CloseServiceHandle (hManager);
232 case IDC_SERVICE_STOP:
233 if ((hManager = OpenSCManager (NULL, NULL, SC_MANAGER_CONNECT |
234 SC_MANAGER_ENUMERATE_SERVICE |
235 SC_MANAGER_QUERY_LOCK_STATUS )) != NULL)
237 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"),
238 SERVICE_QUERY_STATUS | SERVICE_STOP)) != NULL)
240 SERVICE_STATUS Status;
241 TestAndDoUnMapShare();
242 ControlService (hService, SERVICE_CONTROL_STOP, &Status);
245 CloseServiceHandle (hService);
247 CloseServiceHandle (hManager);
253 if (wCmd == IDC_SERVICE_STOP)
254 SetWindowLong (hDlg, DWL_USER, TRUE);
255 Advanced_OnServiceTimer (hDlg);
256 Advanced_StartTimer (hDlg);
258 if ( wCmd == IDC_SERVICE_START && KRB5_is_available() && KRB5_wait_for_service_start() )
259 KRB5_AFS_renew_tokens_for_all_cells();
265 error = GetLastError();
270 case IDC_SERVICE_START:
271 ids = IDS_SERVICE_FAIL_START;
273 case IDC_SERVICE_STOP:
274 ids = IDS_SERVICE_FAIL_STOP;
277 ids = IDS_SERVICE_FAIL_CONFIG;
281 Message (MB_OK | MB_ICONHAND, IDS_SERVICE_ERROR, ids, TEXT("%08lX"), error);
286 void Advanced_OnOpenCPL (HWND hDlg)
288 WinExec ("afs_config.exe", SW_SHOW);
292 void Advanced_OnStartup (HWND hDlg)
294 g.fStartup = IsDlgButtonChecked (hDlg, IDC_STARTUP);
297 if (RegCreateKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
299 DWORD dwSize = sizeof(g.fStartup);
300 DWORD dwType = REG_DWORD;
301 RegSetValueEx (hk, TEXT("ShowTrayIcon"), NULL, dwType, (PBYTE)&g.fStartup, dwSize);
305 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup);