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 * INCLUDES _________________________________________________________________
18 #include <afs/param.h>
23 #include "partition_utils.h"
27 #include "afs_vosAdmin.h"
28 #include "afs\vlserver.h"
33 * DEFINITIONS _________________________________________________________________
36 static LPPROGRESSDISPLAY pProg;
37 static const int MAX_STEPS = 10;
39 static BOOL bBakConfigured;
40 static vos_vldbEntry_t vldbRootAfsEntry;
41 static vos_vldbEntry_t vldbRootCellEntry;
45 * PROTOTYPES _________________________________________________________________
48 BOOL CALLBACK GetCurConfigDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
49 static DWORD CALLBACK GetCurrentConfigState(LPPROGRESSDISPLAY ppd, LPARAM lp);
50 static void ShowMsg(UINT uiMsgID);
51 static void NextStep(UINT uiMsgID);
55 * EXPORTED FUNCTIONS _________________________________________________________________
58 int GetCurrentConfig(HWND hParent, BOOL& bCanceled)
62 bBakConfigured = FALSE;
64 pProg = New2 (PROGRESSDISPLAY,(hParent, IDD_GET_CURRENT_CONFIG, (DLGPROC)GetCurConfigDlgProc));
65 pProg->SetProgressRange(0, MAX_STEPS);
67 HWND hLogo = GetDlgItem(pProg->GetWindow(), IDC_LOGO);
68 AfsAppLib_StartAnimation(hLogo);
70 pProg->Show(GetCurrentConfigState, 0);
72 AfsAppLib_StopAnimation(hLogo);
74 int dwResult = pProg->GetStatus();
85 * STATIC FUNCTIONS _________________________________________________________________
91 * Dialog Proc _________________________________________________________________
94 static BOOL CALLBACK GetCurConfigDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
106 case IDCANCEL: if (QueryCancelWiz()) {
108 ShowMsg(IDS_CANCEL_GET_CONFIG);
118 static BOOL IsClientConfigured(BOOL& bConfigured, afs_status_t& nStatus)
125 NextStep(IDS_CHECK_AFS_CLIENT);
128 afs_status_t configStatus;
129 char *pszCellName = 0;
131 g_LogFile.Write("Is the AFS Client installed on this machine: ");
132 if (!cfg_ClientQueryStatus(GetHostnameA(), &isInstalled, &g_CfgData.nClientVersion, &configStatus, &pszCellName, &nStatus)) {
133 ImmediateErrorDialog(nStatus, IDS_ERROR_AFS_CLIENT_CHECK);
137 g_LogFile.WriteBoolResult((BOOL)isInstalled);
139 bConfigured = (BOOL)(configStatus == 0);
141 lstrncpy(g_CfgData.szClientCellName, A2S(pszCellName), MAX_CELL_NAME_LEN);
143 g_LogFile.WriteError("The client configuration information on this host is not valid", configStatus);
146 g_LogFile.Write("ERROR: AFS Client is not installed. The AFS Server requires the AFS Client.\r\n");
147 ImmediateErrorDialog(0, IDS_ERROR_AFS_CLIENT_NOT_INSTALLED);
148 nStatus = -1; // Just need something nonzero
156 * NOTE: This function has an important side effect. If this machine
157 * is not the first in a new cell, then this function will get the
158 * cell name from the config info. The cell name may be needed in
159 * config calls that come later, and so this function must be called
162 static int IsConfigInfoValid(BOOL& bValid, afs_status_t& nStatus)
167 afs_status_t configStatus;
168 char *pszCellName = 0;
170 NextStep(IDS_CHECK_CONFIG_INFO);
174 g_LogFile.Write("Is there valid configuration information on this machine: ");
175 int nResult = cfg_HostQueryStatus(GetHostnameA(), &configStatus, &pszCellName, &nStatus);
179 g_LogFile.WriteBoolResult((configStatus == 0));
181 if (configStatus == 0)
182 lstrncpy(g_CfgData.szCellName, A2S(pszCellName), MAX_CELL_NAME_LEN);
184 g_LogFile.WriteError("The configuration information on this host is not valid", configStatus);
186 bValid = (BOOL)(configStatus == 0);
191 static int StartBosServer(afs_status_t& nStatus)
196 g_LogFile.Write("Checking if bos server is running.\r\n");
197 int nResult = cfg_BosServerQueryStatus(g_hServer, &isStarted, &isBosProc, &nStatus);
202 g_LogFile.Write("Starting the bos server in %s mode.\r\n", g_CfgData.bValidServerInfo ? "auth" : "no auth");
203 nResult = cfg_BosServerStart(g_hServer, !g_CfgData.bValidServerInfo, BOSSERVER_START_TIMEOUT, &nStatus);
209 static BOOL AreWeLastDBServer(BOOL& bLast, afs_status_t& nStatus)
211 ASSERT(g_CfgData.szHostname[0]);
213 char *pszCellname = 0;
214 char *pszCellServDB = 0;
218 g_LogFile.Write("Checking if this machine is the last DB server in the cell.\r\n");
220 g_LogFile.Write("Getting CellServDB from host %s.\r\n", GetHostnameA());
221 int nResult = cfg_CellServDbEnumerate(GetHostnameA(), &pszCellname, &pszCellServDB, &nStatus);
225 if (!pszCellServDB) {
226 g_LogFile.Write("There are no DB servers in CellServDB!!!!!");
227 ASSERT(FALSE); // This should not be possible
231 char *psz = pszCellServDB;
234 for (i = 0; *psz; psz += strlen(psz) + 1)
238 ASSERT(lstrcmp(g_CfgData.szHostname, A2S(pszCellServDB)) == 0);
239 g_LogFile.Write("This machine IS the last DB server in the cell.\r\n");
242 g_LogFile.Write("This machine is NOT the last DB server in the cell.\r\n");
247 static afs_status_t IsFSConfigured(BOOL& bConfigured)
249 g_LogFile.Write("Is this machine a file server: ");
254 afs_status_t nStatus;
256 int nResult = cfg_FileServerQueryStatus(g_hServer, &isStarted, &nStatus);
260 bConfigured = isStarted;
262 g_LogFile.WriteBoolResult(bConfigured);
267 static afs_status_t IsDBConfigured(BOOL& bConfigured)
269 g_LogFile.Write("Is this machine a db (or bak) server: ");
273 short isStarted, isBakStarted;
274 afs_status_t nStatus;
276 int nResult = cfg_DbServersQueryStatus(g_hServer, &isStarted, &isBakStarted, 0, &nStatus);
280 bConfigured = isStarted;
281 bBakConfigured = isBakStarted;
283 g_LogFile.Write(bConfigured ? "Yes DB" : "No DB");
284 g_LogFile.Write(", %s.\r\n", bBakConfigured ? "Yes Bak" : "No Bak");
289 static afs_status_t IsBakConfigured(BOOL& bConfigured)
291 bConfigured = bBakConfigured;
296 static afs_status_t DoesAPartitionExist(BOOL& bExists)
298 g_LogFile.Write("Does a partition exist on this machine: ");
302 afs_status_t nStatus;
304 int nResult = ReadPartitionTable(&nStatus);
308 int nNumPartitions = 0;
310 cfg_partitionEntry_t *pTable = GetPartitionTable(nNumPartitions);
312 bExists = nNumPartitions > 0;
314 g_CfgData.chDeviceName = pTable->deviceName[0];
315 lstrcpy(g_CfgData.szPartitionName, ((TCHAR *)A2S(pTable->partitionName)) + lstrlen(TEXT("/vicep")));
318 g_LogFile.WriteBoolResult(bExists);
323 afs_status_t DoRootVolumesExist(BOOL& bExists)
327 afs_status_t nStatus;
329 g_LogFile.Write("Do the root volumes exist: ");
331 // Does root.afs exist? If it does not, the call will fail with the VL_NOENT
332 // status. Any other error causes this function to fail.
333 int nResult = vos_VLDBGet(g_hCell, 0, 0, "root.afs", &vldbRootAfsEntry, &nStatus);
335 g_CfgData.bRootAfsExists = TRUE;
336 g_CfgData.nRootAfsID = vldbRootAfsEntry.volumeId[0];
337 } else if (nStatus != VL_NOENT)
340 // Does root.cell exist?
341 nResult = vos_VLDBGet(g_hCell, 0, 0, "root.cell", &vldbRootCellEntry, &nStatus);
343 g_CfgData.bRootCellExists = TRUE;
344 g_CfgData.nRootCellID = vldbRootCellEntry.volumeId[0];
345 } else if (nStatus != VL_NOENT)
348 bExists = g_CfgData.bRootAfsExists && g_CfgData.bRootCellExists;
350 g_LogFile.WriteBoolResult(bExists);
355 static BOOL IsVolumeReplicated(vos_vldbEntry_t& vldbEntry)
357 if (vldbEntry.numServers <= 1)
360 for (int i = 0; i < vldbEntry.numServers; i++) {
361 if ((vldbEntry.volumeSites[i].serverFlags & VOS_VLDB_READ_ONLY) ||
362 (vldbEntry.volumeSites[i].serverFlags & VOS_VLDB_NEW_REPSITE))
369 afs_status_t AreRootVolumesReplicated(BOOL& bReplicated)
371 g_LogFile.Write("Are the root volumes replicated: ");
373 // Is root.afs replicated?
374 g_CfgData.bRootAfsReplicated = IsVolumeReplicated(vldbRootAfsEntry);
376 // Is root.cell replicated?
377 g_CfgData.bRootCellReplicated = IsVolumeReplicated(vldbRootCellEntry);
379 bReplicated = g_CfgData.bRootAfsReplicated && g_CfgData.bRootCellReplicated;
381 g_LogFile.WriteBoolResult(bReplicated);
386 static afs_status_t IsSCSConfigured(BOOL& bConfigured)
388 g_LogFile.Write("Is this machine a System Control Server: ");
392 short isUpserver, isSC, isBin;
393 afs_status_t nStatus;
395 int nResult = cfg_UpdateServerQueryStatus(g_hServer, &isUpserver, &isSC, &isBin, &nStatus);
399 bConfigured = isUpserver && isSC;
401 g_LogFile.WriteBoolResult(bConfigured);
406 static afs_status_t IsSCCConfigured(BOOL& bConfigured)
408 g_LogFile.Write("Is this machine a System Control Client: ");
412 short isUpclient, isSCC, isBin;
413 afs_status_t nStatus;
415 int nResult = cfg_UpdateClientQueryStatus(g_hServer, &isUpclient, &isSCC, &isBin, &nStatus);
419 bConfigured = isUpclient && isSCC;
421 g_LogFile.WriteBoolResult(bConfigured);
426 static void ShowMsg(UINT uiMsgID)
428 TCHAR szMsg[cchRESOURCE];
430 GetString(szMsg, uiMsgID);
432 pProg->SetOperation(szMsg);
435 static void NextStep(UINT uiMsgID)
437 static int nCurStep = 1;
444 pProg->SetProgress(nCurStep++);
449 static BOOL CheckConfigState(afs_status_t (*ConfigCheckFunc)(BOOL&), CONFIG_STATE& state, afs_status_t& nStatus, UINT uiMsgID)
458 nStatus = ConfigCheckFunc(bState);
460 g_LogFile.WriteError("Config check failed", nStatus);
464 state = bState ? CS_ALREADY_CONFIGURED : CS_NULL;
469 static DWORD CALLBACK GetCurrentConfigState(LPPROGRESSDISPLAY ppd, LPARAM lp)
471 afs_status_t nStatus = 0;
475 g_LogFile.Write("Checking this machine's current configuration...\r\n");
477 if (!IsClientConfigured(g_CfgData.bValidClientInfo, nStatus))
480 if (!IsConfigInfoValid(g_CfgData.bValidServerInfo, nStatus))
483 // If the server and client have good config info, and the client is in a
484 // different cell than the server, then the config routines will want to
485 // reconfigure the client. To do so they need information that we already
486 // know and don't have to ask the user for. Prefill this information here.
487 if (g_CfgData.bValidClientInfo && g_CfgData.bValidServerInfo &&
488 (lstrcmp(g_CfgData.szCellName, g_CfgData.szClientCellName) != 0))
490 lstrcpy(g_CfgData.szCellServDbHostname, g_CfgData.szHostname);
493 if (!GetLibHandles(&nStatus))
496 if (!CheckConfigState(DoesAPartitionExist, g_CfgData.configPartition, nStatus, IDS_CHECK_PARTITION))
499 if (g_CfgData.bValidServerInfo) {
500 // Must check if bos server is running, and start it if it isn't. We can't determine
501 // if the services are running except by asking the bosserver.
502 if (!StartBosServer(nStatus))
505 if (!CheckConfigState(IsFSConfigured, g_CfgData.configFS, nStatus, IDS_CHECK_FS_CONFIG))
508 if (!CheckConfigState(IsDBConfigured, g_CfgData.configDB, nStatus, IDS_CHECK_DB_CONFIG))
511 if (g_CfgData.configDB == CS_ALREADY_CONFIGURED) {
512 if (!AreWeLastDBServer(g_CfgData.bLastDBServer, nStatus))
516 if (!CheckConfigState(IsBakConfigured, g_CfgData.configBak, nStatus, IDS_CHECK_BAK_CONFIG))
519 if (!CheckConfigState(DoRootVolumesExist, g_CfgData.configRootVolumes, nStatus, IDS_CHECK_ROOT_AFS))
522 g_CfgData.bRootVolumesExistanceKnown = TRUE;
524 if (!CheckConfigState(AreRootVolumesReplicated, g_CfgData.configRep, nStatus, IDS_CHECK_REP))
527 g_CfgData.bRootVolumesReplicationKnown = TRUE;
529 if (!CheckConfigState(IsSCSConfigured, g_CfgData.configSCS, nStatus, IDS_CHECK_SCS))
532 if (!CheckConfigState(IsSCCConfigured, g_CfgData.configSCC, nStatus, IDS_CHECK_SCC))
537 pProg->SetProgress(MAX_STEPS);