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>
21 * PROTOTYPES _________________________________________________________________
25 void Advanced_OnInitDialog (HWND hDlg);
26 void Advanced_StartTimer (HWND hDlg);
27 void Advanced_OnServiceTimer (HWND hDlg);
28 void Advanced_OnOpenCPL (HWND hDlg);
29 void Advanced_OnChangeService (HWND hDlg, WORD wCmd);
30 void Advanced_OnStartup (HWND hDlg);
34 * ROUTINES ___________________________________________________________________
38 BOOL CALLBACK Advanced_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
44 GetClientRect (GetParent(hDlg), &rTab);
45 TabCtrl_AdjustRect (GetParent (hDlg), FALSE, &rTab);
46 SetWindowPos (hDlg, NULL, rTab.left, rTab.top, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
48 Advanced_OnInitDialog (hDlg);
52 Advanced_OnServiceTimer (hDlg);
58 case IDC_SERVICE_STOP:
59 case IDC_SERVICE_START:
60 case IDC_SERVICE_AUTO:
61 Advanced_OnChangeService (hDlg, LOWORD(wp));
65 Advanced_OnOpenCPL (hDlg);
69 Advanced_OnStartup (hDlg);
73 Advanced_DlgProc (hDlg, WM_HELP, 0, 0);
79 WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCREDS_TAB_ADVANCED);
86 void Advanced_OnInitDialog (HWND hDlg)
88 CheckDlgButton (hDlg, IDC_STARTUP, g.fStartup);
89 Advanced_OnServiceTimer (hDlg);
90 Advanced_StartTimer (hDlg);
94 void Advanced_StartTimer (HWND hDlg)
96 KillTimer (hDlg, ID_SERVICE_TIMER);
97 SetTimer (hDlg, ID_SERVICE_TIMER, (ULONG)cmsecSERVICE, NULL);
101 void Advanced_OnServiceTimer (HWND hDlg)
107 QUERY_SERVICE_CONFIG Config;
110 memset (&Config, 0x00, sizeof(Config));
111 Config.Config.dwStartType = SERVICE_DEMAND_START;
113 SERVICE_STATUS Status;
114 memset (&Status, 0x00, sizeof(Status));
115 Status.dwCurrentState = SERVICE_STOPPED;
118 if ((hManager = OpenSCManager (NULL, NULL, GENERIC_READ)) != NULL)
121 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"), GENERIC_READ)) != NULL)
124 DWORD dwSize = sizeof(Config);
125 QueryServiceConfig (hService, (QUERY_SERVICE_CONFIG*)&Config, sizeof(Config), &dwSize);
126 QueryServiceStatus (hService, &Status);
127 TestAndDoMapShare(Status.dwCurrentState);
129 CloseServiceHandle (hService);
132 CloseServiceHandle (hManager);
137 if ((Status.dwCurrentState == SERVICE_STOP_PENDING) ||
138 (Status.dwCurrentState == SERVICE_START_PENDING))
144 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_START), fFound && (Status.dwCurrentState == SERVICE_STOPPED));
145 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_STOP), fFound && (Status.dwCurrentState == SERVICE_RUNNING));
146 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_AUTO), fFound);
147 CheckDlgButton (hDlg, IDC_SERVICE_AUTO, fFound && (Config.Config.dwStartType == SERVICE_AUTO_START));
149 TCHAR szStatus[cchRESOURCE];
151 GetString (szStatus, IDS_SERVICE_BROKEN);
152 else if (Status.dwCurrentState == SERVICE_RUNNING)
153 GetString (szStatus, IDS_SERVICE_RUNNING);
154 else if (Status.dwCurrentState == SERVICE_STOPPED)
155 GetString (szStatus, IDS_SERVICE_STOPPED);
156 else if (Status.dwCurrentState == SERVICE_STOP_PENDING)
157 GetString (szStatus, IDS_SERVICE_STOPPING);
158 else if (Status.dwCurrentState == SERVICE_START_PENDING)
159 GetString (szStatus, IDS_SERVICE_STARTING);
161 GetString (szStatus, IDS_SERVICE_UNKNOWN);
162 TestAndDoMapShare(Status.dwCurrentState);
163 SetDlgItemText (hDlg, IDC_SERVICE_STATUS, szStatus);
165 if (fFinal && GetWindowLong (hDlg, DWL_USER))
167 SetWindowLong (hDlg, DWL_USER, 0);
168 Main_RepopulateTabs (FALSE);
173 KillTimer (hDlg, ID_SERVICE_TIMER);
178 void Advanced_OnChangeService (HWND hDlg, WORD wCmd)
180 BOOL fSuccess = FALSE;
182 SC_HANDLE hManager, hService;
186 case IDC_SERVICE_AUTO:
188 if ((hManager = OpenSCManager (NULL, NULL, SC_MANAGER_CONNECT |
189 SC_MANAGER_ENUMERATE_SERVICE |
190 SC_MANAGER_QUERY_LOCK_STATUS)) != NULL)
192 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"),
193 SERVICE_CHANGE_CONFIG | SERVICE_QUERY_CONFIG |
194 SERVICE_QUERY_STATUS)) != NULL)
196 StartType = (IsDlgButtonChecked (hDlg, wCmd)) ? SERVICE_AUTO_START : SERVICE_DEMAND_START;
197 if (ChangeServiceConfig (hService, SERVICE_NO_CHANGE, StartType,
198 SERVICE_NO_CHANGE, 0, 0, 0, 0, 0, 0, 0))
200 CloseServiceHandle (hService);
202 CloseServiceHandle (hManager);
206 case IDC_SERVICE_START:
207 if ((hManager = OpenSCManager (NULL, NULL, SC_MANAGER_CONNECT |
208 SC_MANAGER_ENUMERATE_SERVICE |
209 SC_MANAGER_QUERY_LOCK_STATUS )) != NULL)
211 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"),
212 SERVICE_QUERY_STATUS | SERVICE_START)) != NULL)
214 if (StartService (hService, 0, 0))
216 TestAndDoMapShare(SERVICE_START_PENDING);
219 CloseServiceHandle (hService);
221 CloseServiceHandle (hManager);
225 case IDC_SERVICE_STOP:
226 if ((hManager = OpenSCManager (NULL, NULL, SC_MANAGER_CONNECT |
227 SC_MANAGER_ENUMERATE_SERVICE |
228 SC_MANAGER_QUERY_LOCK_STATUS )) != NULL)
230 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"),
231 SERVICE_QUERY_STATUS | SERVICE_STOP)) != NULL)
233 SERVICE_STATUS Status;
234 TestAndDoUnMapShare();
235 ControlService (hService, SERVICE_CONTROL_STOP, &Status);
238 CloseServiceHandle (hService);
240 CloseServiceHandle (hManager);
246 if (wCmd == IDC_SERVICE_STOP)
247 SetWindowLong (hDlg, DWL_USER, TRUE);
248 Advanced_OnServiceTimer (hDlg);
249 Advanced_StartTimer (hDlg);
251 if ( wCmd == IDC_SERVICE_START && KRB5_is_available() && KRB5_wait_for_service_start() )
252 KRB5_AFS_renew_tokens_for_all_cells();
258 error = GetLastError();
263 case IDC_SERVICE_START:
264 ids = IDS_SERVICE_FAIL_START;
266 case IDC_SERVICE_STOP:
267 ids = IDS_SERVICE_FAIL_STOP;
270 ids = IDS_SERVICE_FAIL_CONFIG;
274 Message (MB_OK | MB_ICONHAND, IDS_SERVICE_ERROR, ids, TEXT("%08lX"), error);
279 void Advanced_OnOpenCPL (HWND hDlg)
281 WinExec ("afs_config.exe", SW_SHOW);
285 void Advanced_OnStartup (HWND hDlg)
287 g.fStartup = IsDlgButtonChecked (hDlg, IDC_STARTUP);
290 if (RegCreateKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
292 DWORD dwSize = sizeof(g.fStartup);
293 DWORD dwType = REG_DWORD;
294 RegSetValueEx (hk, TEXT("ShowTrayIcon"), NULL, dwType, (PBYTE)&g.fStartup, dwSize);
298 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup);