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 _________________________________________________________________
15 #include <afs/param.h>
20 #include "partition_utils.h"
24 #include "afs_vosAdmin.h"
25 #include "afs\vlserver.h"
30 * DEFINITIONS _________________________________________________________________
33 static LPPROGRESSDISPLAY pProg;
34 static const int MAX_STEPS = 10;
36 static BOOL bBakConfigured;
37 static vos_vldbEntry_t vldbRootAfsEntry;
38 static vos_vldbEntry_t vldbRootCellEntry;
42 * PROTOTYPES _________________________________________________________________
45 BOOL CALLBACK GetCurConfigDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
46 static DWORD CALLBACK GetCurrentConfigState(LPPROGRESSDISPLAY ppd, LPARAM lp);
47 static void ShowMsg(UINT uiMsgID);
48 static void NextStep(UINT uiMsgID);
52 * EXPORTED FUNCTIONS _________________________________________________________________
55 int GetCurrentConfig(HWND hParent, BOOL& bCanceled)
59 bBakConfigured = FALSE;
61 pProg = New2 (PROGRESSDISPLAY,(hParent, IDD_GET_CURRENT_CONFIG, (DLGPROC)GetCurConfigDlgProc));
62 pProg->SetProgressRange(0, MAX_STEPS);
64 HWND hLogo = GetDlgItem(pProg->GetWindow(), IDC_LOGO);
65 AfsAppLib_StartAnimation(hLogo);
67 pProg->Show(GetCurrentConfigState, 0);
69 AfsAppLib_StopAnimation(hLogo);
71 int dwResult = pProg->GetStatus();
82 * STATIC FUNCTIONS _________________________________________________________________
88 * Dialog Proc _________________________________________________________________
91 static BOOL CALLBACK GetCurConfigDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
103 case IDCANCEL: if (QueryCancelWiz()) {
105 ShowMsg(IDS_CANCEL_GET_CONFIG);
115 static BOOL IsClientConfigured(BOOL& bConfigured, afs_status_t& nStatus)
122 NextStep(IDS_CHECK_AFS_CLIENT);
125 afs_status_t configStatus;
126 char *pszCellName = 0;
128 g_LogFile.Write("Is the AFS Client installed on this machine: ");
129 if (!cfg_ClientQueryStatus(GetHostnameA(), &isInstalled, &g_CfgData.nClientVersion, &configStatus, &pszCellName, &nStatus)) {
130 ImmediateErrorDialog(nStatus, IDS_ERROR_AFS_CLIENT_CHECK);
134 g_LogFile.WriteBoolResult((BOOL)isInstalled);
136 bConfigured = (BOOL)(configStatus == 0);
138 lstrncpy(g_CfgData.szClientCellName, A2S(pszCellName), MAX_CELL_NAME_LEN);
140 g_LogFile.WriteError("The client configuration information on this host is not valid", configStatus);
143 g_LogFile.Write("ERROR: AFS Client is not installed. The AFS Server requires the AFS Client.\r\n");
144 ImmediateErrorDialog(0, IDS_ERROR_AFS_CLIENT_NOT_INSTALLED);
145 nStatus = -1; // Just need something nonzero
153 * NOTE: This function has an important side effect. If this machine
154 * is not the first in a new cell, then this function will get the
155 * cell name from the config info. The cell name may be needed in
156 * config calls that come later, and so this function must be called
159 static int IsConfigInfoValid(BOOL& bValid, afs_status_t& nStatus)
164 afs_status_t configStatus;
165 char *pszCellName = 0;
167 NextStep(IDS_CHECK_CONFIG_INFO);
171 g_LogFile.Write("Is there valid configuration information on this machine: ");
172 int nResult = cfg_HostQueryStatus(GetHostnameA(), &configStatus, &pszCellName, &nStatus);
176 g_LogFile.WriteBoolResult((configStatus == 0));
178 if (configStatus == 0)
179 lstrncpy(g_CfgData.szCellName, A2S(pszCellName), MAX_CELL_NAME_LEN);
181 g_LogFile.WriteError("The configuration information on this host is not valid", configStatus);
183 bValid = (BOOL)(configStatus == 0);
188 static int StartBosServer(afs_status_t& nStatus)
193 g_LogFile.Write("Checking if bos server is running.\r\n");
194 int nResult = cfg_BosServerQueryStatus(g_hServer, &isStarted, &isBosProc, &nStatus);
199 g_LogFile.Write("Starting the bos server in %s mode.\r\n", g_CfgData.bValidServerInfo ? "auth" : "no auth");
200 nResult = cfg_BosServerStart(g_hServer, !g_CfgData.bValidServerInfo, BOSSERVER_START_TIMEOUT, &nStatus);
206 static BOOL AreWeLastDBServer(BOOL& bLast, afs_status_t& nStatus)
208 ASSERT(g_CfgData.szHostname[0]);
210 char *pszCellname = 0;
211 char *pszCellServDB = 0;
215 g_LogFile.Write("Checking if this machine is the last DB server in the cell.\r\n");
217 g_LogFile.Write("Getting CellServDB from host %s.\r\n", GetHostnameA());
218 int nResult = cfg_CellServDbEnumerate(GetHostnameA(), &pszCellname, &pszCellServDB, &nStatus);
222 if (!pszCellServDB) {
223 g_LogFile.Write("There are no DB servers in CellServDB!!!!!");
224 ASSERT(FALSE); // This should not be possible
228 char *psz = pszCellServDB;
230 for (int i = 0; *psz; psz += strlen(psz) + 1)
234 ASSERT(lstrcmp(g_CfgData.szHostname, A2S(pszCellServDB)) == 0);
235 g_LogFile.Write("This machine IS the last DB server in the cell.\r\n");
238 g_LogFile.Write("This machine is NOT the last DB server in the cell.\r\n");
243 static afs_status_t IsFSConfigured(BOOL& bConfigured)
245 g_LogFile.Write("Is this machine a file server: ");
250 afs_status_t nStatus;
252 int nResult = cfg_FileServerQueryStatus(g_hServer, &isStarted, &nStatus);
256 bConfigured = isStarted;
258 g_LogFile.WriteBoolResult(bConfigured);
263 static afs_status_t IsDBConfigured(BOOL& bConfigured)
265 g_LogFile.Write("Is this machine a db (or bak) server: ");
269 short isStarted, isBakStarted;
270 afs_status_t nStatus;
272 int nResult = cfg_DbServersQueryStatus(g_hServer, &isStarted, &isBakStarted, 0, &nStatus);
276 bConfigured = isStarted;
277 bBakConfigured = isBakStarted;
279 g_LogFile.Write(bConfigured ? "Yes DB" : "No DB");
280 g_LogFile.Write(", %s.\r\n", bBakConfigured ? "Yes Bak" : "No Bak");
285 static afs_status_t IsBakConfigured(BOOL& bConfigured)
287 bConfigured = bBakConfigured;
292 static afs_status_t DoesAPartitionExist(BOOL& bExists)
294 g_LogFile.Write("Does a partition exist on this machine: ");
298 afs_status_t nStatus;
300 int nResult = ReadPartitionTable(&nStatus);
304 int nNumPartitions = 0;
306 cfg_partitionEntry_t *pTable = GetPartitionTable(nNumPartitions);
308 bExists = nNumPartitions > 0;
310 g_CfgData.chDeviceName = pTable->deviceName[0];
311 lstrcpy(g_CfgData.szPartitionName, ((TCHAR *)A2S(pTable->partitionName)) + lstrlen(TEXT("/vicep")));
314 g_LogFile.WriteBoolResult(bExists);
319 afs_status_t DoRootVolumesExist(BOOL& bExists)
323 afs_status_t nStatus;
325 g_LogFile.Write("Do the root volumes exist: ");
327 // Does root.afs exist? If it does not, the call will fail with the VL_NOENT
328 // status. Any other error causes this function to fail.
329 int nResult = vos_VLDBGet(g_hCell, 0, 0, "root.afs", &vldbRootAfsEntry, &nStatus);
331 g_CfgData.bRootAfsExists = TRUE;
332 g_CfgData.nRootAfsID = vldbRootAfsEntry.volumeId[0];
333 } else if (nStatus != VL_NOENT)
336 // Does root.cell exist?
337 nResult = vos_VLDBGet(g_hCell, 0, 0, "root.cell", &vldbRootCellEntry, &nStatus);
339 g_CfgData.bRootCellExists = TRUE;
340 g_CfgData.nRootCellID = vldbRootCellEntry.volumeId[0];
341 } else if (nStatus != VL_NOENT)
344 bExists = g_CfgData.bRootAfsExists && g_CfgData.bRootCellExists;
346 g_LogFile.WriteBoolResult(bExists);
351 static BOOL IsVolumeReplicated(vos_vldbEntry_t& vldbEntry)
353 if (vldbEntry.numServers <= 1)
356 for (int i = 0; i < vldbEntry.numServers; i++) {
357 if ((vldbEntry.volumeSites[i].serverFlags & VOS_VLDB_READ_ONLY) ||
358 (vldbEntry.volumeSites[i].serverFlags & VOS_VLDB_NEW_REPSITE))
365 afs_status_t AreRootVolumesReplicated(BOOL& bReplicated)
367 g_LogFile.Write("Are the root volumes replicated: ");
369 // Is root.afs replicated?
370 g_CfgData.bRootAfsReplicated = IsVolumeReplicated(vldbRootAfsEntry);
372 // Is root.cell replicated?
373 g_CfgData.bRootCellReplicated = IsVolumeReplicated(vldbRootCellEntry);
375 bReplicated = g_CfgData.bRootAfsReplicated && g_CfgData.bRootCellReplicated;
377 g_LogFile.WriteBoolResult(bReplicated);
382 static afs_status_t IsSCSConfigured(BOOL& bConfigured)
384 g_LogFile.Write("Is this machine a System Control Server: ");
388 short isUpserver, isSC, isBin;
389 afs_status_t nStatus;
391 int nResult = cfg_UpdateServerQueryStatus(g_hServer, &isUpserver, &isSC, &isBin, &nStatus);
395 bConfigured = isUpserver && isSC;
397 g_LogFile.WriteBoolResult(bConfigured);
402 static afs_status_t IsSCCConfigured(BOOL& bConfigured)
404 g_LogFile.Write("Is this machine a System Control Client: ");
408 short isUpclient, isSCC, isBin;
409 afs_status_t nStatus;
411 int nResult = cfg_UpdateClientQueryStatus(g_hServer, &isUpclient, &isSCC, &isBin, &nStatus);
415 bConfigured = isUpclient && isSCC;
417 g_LogFile.WriteBoolResult(bConfigured);
422 static void ShowMsg(UINT uiMsgID)
424 TCHAR szMsg[cchRESOURCE];
426 GetString(szMsg, uiMsgID);
428 pProg->SetOperation(szMsg);
431 static void NextStep(UINT uiMsgID)
440 pProg->SetProgress(nCurStep++);
445 static BOOL CheckConfigState(afs_status_t (*ConfigCheckFunc)(BOOL&), CONFIG_STATE& state, afs_status_t& nStatus, UINT uiMsgID)
454 nStatus = ConfigCheckFunc(bState);
456 g_LogFile.WriteError("Config check failed", nStatus);
460 state = bState ? CS_ALREADY_CONFIGURED : CS_NULL;
465 static DWORD CALLBACK GetCurrentConfigState(LPPROGRESSDISPLAY ppd, LPARAM lp)
467 afs_status_t nStatus = 0;
471 g_LogFile.Write("Checking this machine's current configuration...\r\n");
473 if (!IsClientConfigured(g_CfgData.bValidClientInfo, nStatus))
476 if (!IsConfigInfoValid(g_CfgData.bValidServerInfo, nStatus))
479 // If the server and client have good config info, and the client is in a
480 // different cell than the server, then the config routines will want to
481 // reconfigure the client. To do so they need information that we already
482 // know and don't have to ask the user for. Prefill this information here.
483 if (g_CfgData.bValidClientInfo && g_CfgData.bValidServerInfo &&
484 (lstrcmp(g_CfgData.szCellName, g_CfgData.szClientCellName) != 0))
486 lstrcpy(g_CfgData.szCellServDbHostname, g_CfgData.szHostname);
489 if (!GetLibHandles(&nStatus))
492 if (!CheckConfigState(DoesAPartitionExist, g_CfgData.configPartition, nStatus, IDS_CHECK_PARTITION))
495 if (g_CfgData.bValidServerInfo) {
496 // Must check if bos server is running, and start it if it isn't. We can't determine
497 // if the services are running except by asking the bosserver.
498 if (!StartBosServer(nStatus))
501 if (!CheckConfigState(IsFSConfigured, g_CfgData.configFS, nStatus, IDS_CHECK_FS_CONFIG))
504 if (!CheckConfigState(IsDBConfigured, g_CfgData.configDB, nStatus, IDS_CHECK_DB_CONFIG))
507 if (g_CfgData.configDB == CS_ALREADY_CONFIGURED) {
508 if (!AreWeLastDBServer(g_CfgData.bLastDBServer, nStatus))
512 if (!CheckConfigState(IsBakConfigured, g_CfgData.configBak, nStatus, IDS_CHECK_BAK_CONFIG))
515 if (!CheckConfigState(DoRootVolumesExist, g_CfgData.configRootVolumes, nStatus, IDS_CHECK_ROOT_AFS))
518 g_CfgData.bRootVolumesExistanceKnown = TRUE;
520 if (!CheckConfigState(AreRootVolumesReplicated, g_CfgData.configRep, nStatus, IDS_CHECK_REP))
523 g_CfgData.bRootVolumesReplicationKnown = TRUE;
525 if (!CheckConfigState(IsSCSConfigured, g_CfgData.configSCS, nStatus, IDS_CHECK_SCS))
528 if (!CheckConfigState(IsSCCConfigured, g_CfgData.configSCC, nStatus, IDS_CHECK_SCC))
533 pProg->SetProgress(MAX_STEPS);