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;
231 for (i = 0; *psz; psz += strlen(psz) + 1)
235 ASSERT(lstrcmp(g_CfgData.szHostname, A2S(pszCellServDB)) == 0);
236 g_LogFile.Write("This machine IS the last DB server in the cell.\r\n");
239 g_LogFile.Write("This machine is NOT the last DB server in the cell.\r\n");
244 static afs_status_t IsFSConfigured(BOOL& bConfigured)
246 g_LogFile.Write("Is this machine a file server: ");
251 afs_status_t nStatus;
253 int nResult = cfg_FileServerQueryStatus(g_hServer, &isStarted, &nStatus);
257 bConfigured = isStarted;
259 g_LogFile.WriteBoolResult(bConfigured);
264 static afs_status_t IsDBConfigured(BOOL& bConfigured)
266 g_LogFile.Write("Is this machine a db (or bak) server: ");
270 short isStarted, isBakStarted;
271 afs_status_t nStatus;
273 int nResult = cfg_DbServersQueryStatus(g_hServer, &isStarted, &isBakStarted, 0, &nStatus);
277 bConfigured = isStarted;
278 bBakConfigured = isBakStarted;
280 g_LogFile.Write(bConfigured ? "Yes DB" : "No DB");
281 g_LogFile.Write(", %s.\r\n", bBakConfigured ? "Yes Bak" : "No Bak");
286 static afs_status_t IsBakConfigured(BOOL& bConfigured)
288 bConfigured = bBakConfigured;
293 static afs_status_t DoesAPartitionExist(BOOL& bExists)
295 g_LogFile.Write("Does a partition exist on this machine: ");
299 afs_status_t nStatus;
301 int nResult = ReadPartitionTable(&nStatus);
305 int nNumPartitions = 0;
307 cfg_partitionEntry_t *pTable = GetPartitionTable(nNumPartitions);
309 bExists = nNumPartitions > 0;
311 g_CfgData.chDeviceName = pTable->deviceName[0];
312 lstrcpy(g_CfgData.szPartitionName, ((TCHAR *)A2S(pTable->partitionName)) + lstrlen(TEXT("/vicep")));
315 g_LogFile.WriteBoolResult(bExists);
320 afs_status_t DoRootVolumesExist(BOOL& bExists)
324 afs_status_t nStatus;
326 g_LogFile.Write("Do the root volumes exist: ");
328 // Does root.afs exist? If it does not, the call will fail with the VL_NOENT
329 // status. Any other error causes this function to fail.
330 int nResult = vos_VLDBGet(g_hCell, 0, 0, "root.afs", &vldbRootAfsEntry, &nStatus);
332 g_CfgData.bRootAfsExists = TRUE;
333 g_CfgData.nRootAfsID = vldbRootAfsEntry.volumeId[0];
334 } else if (nStatus != VL_NOENT)
337 // Does root.cell exist?
338 nResult = vos_VLDBGet(g_hCell, 0, 0, "root.cell", &vldbRootCellEntry, &nStatus);
340 g_CfgData.bRootCellExists = TRUE;
341 g_CfgData.nRootCellID = vldbRootCellEntry.volumeId[0];
342 } else if (nStatus != VL_NOENT)
345 bExists = g_CfgData.bRootAfsExists && g_CfgData.bRootCellExists;
347 g_LogFile.WriteBoolResult(bExists);
352 static BOOL IsVolumeReplicated(vos_vldbEntry_t& vldbEntry)
354 if (vldbEntry.numServers <= 1)
357 for (int i = 0; i < vldbEntry.numServers; i++) {
358 if ((vldbEntry.volumeSites[i].serverFlags & VOS_VLDB_READ_ONLY) ||
359 (vldbEntry.volumeSites[i].serverFlags & VOS_VLDB_NEW_REPSITE))
366 afs_status_t AreRootVolumesReplicated(BOOL& bReplicated)
368 g_LogFile.Write("Are the root volumes replicated: ");
370 // Is root.afs replicated?
371 g_CfgData.bRootAfsReplicated = IsVolumeReplicated(vldbRootAfsEntry);
373 // Is root.cell replicated?
374 g_CfgData.bRootCellReplicated = IsVolumeReplicated(vldbRootCellEntry);
376 bReplicated = g_CfgData.bRootAfsReplicated && g_CfgData.bRootCellReplicated;
378 g_LogFile.WriteBoolResult(bReplicated);
383 static afs_status_t IsSCSConfigured(BOOL& bConfigured)
385 g_LogFile.Write("Is this machine a System Control Server: ");
389 short isUpserver, isSC, isBin;
390 afs_status_t nStatus;
392 int nResult = cfg_UpdateServerQueryStatus(g_hServer, &isUpserver, &isSC, &isBin, &nStatus);
396 bConfigured = isUpserver && isSC;
398 g_LogFile.WriteBoolResult(bConfigured);
403 static afs_status_t IsSCCConfigured(BOOL& bConfigured)
405 g_LogFile.Write("Is this machine a System Control Client: ");
409 short isUpclient, isSCC, isBin;
410 afs_status_t nStatus;
412 int nResult = cfg_UpdateClientQueryStatus(g_hServer, &isUpclient, &isSCC, &isBin, &nStatus);
416 bConfigured = isUpclient && isSCC;
418 g_LogFile.WriteBoolResult(bConfigured);
423 static void ShowMsg(UINT uiMsgID)
425 TCHAR szMsg[cchRESOURCE];
427 GetString(szMsg, uiMsgID);
429 pProg->SetOperation(szMsg);
432 static void NextStep(UINT uiMsgID)
434 static int nCurStep = 1;
441 pProg->SetProgress(nCurStep++);
446 static BOOL CheckConfigState(afs_status_t (*ConfigCheckFunc)(BOOL&), CONFIG_STATE& state, afs_status_t& nStatus, UINT uiMsgID)
455 nStatus = ConfigCheckFunc(bState);
457 g_LogFile.WriteError("Config check failed", nStatus);
461 state = bState ? CS_ALREADY_CONFIGURED : CS_NULL;
466 static DWORD CALLBACK GetCurrentConfigState(LPPROGRESSDISPLAY ppd, LPARAM lp)
468 afs_status_t nStatus = 0;
472 g_LogFile.Write("Checking this machine's current configuration...\r\n");
474 if (!IsClientConfigured(g_CfgData.bValidClientInfo, nStatus))
477 if (!IsConfigInfoValid(g_CfgData.bValidServerInfo, nStatus))
480 // If the server and client have good config info, and the client is in a
481 // different cell than the server, then the config routines will want to
482 // reconfigure the client. To do so they need information that we already
483 // know and don't have to ask the user for. Prefill this information here.
484 if (g_CfgData.bValidClientInfo && g_CfgData.bValidServerInfo &&
485 (lstrcmp(g_CfgData.szCellName, g_CfgData.szClientCellName) != 0))
487 lstrcpy(g_CfgData.szCellServDbHostname, g_CfgData.szHostname);
490 if (!GetLibHandles(&nStatus))
493 if (!CheckConfigState(DoesAPartitionExist, g_CfgData.configPartition, nStatus, IDS_CHECK_PARTITION))
496 if (g_CfgData.bValidServerInfo) {
497 // Must check if bos server is running, and start it if it isn't. We can't determine
498 // if the services are running except by asking the bosserver.
499 if (!StartBosServer(nStatus))
502 if (!CheckConfigState(IsFSConfigured, g_CfgData.configFS, nStatus, IDS_CHECK_FS_CONFIG))
505 if (!CheckConfigState(IsDBConfigured, g_CfgData.configDB, nStatus, IDS_CHECK_DB_CONFIG))
508 if (g_CfgData.configDB == CS_ALREADY_CONFIGURED) {
509 if (!AreWeLastDBServer(g_CfgData.bLastDBServer, nStatus))
513 if (!CheckConfigState(IsBakConfigured, g_CfgData.configBak, nStatus, IDS_CHECK_BAK_CONFIG))
516 if (!CheckConfigState(DoRootVolumesExist, g_CfgData.configRootVolumes, nStatus, IDS_CHECK_ROOT_AFS))
519 g_CfgData.bRootVolumesExistanceKnown = TRUE;
521 if (!CheckConfigState(AreRootVolumesReplicated, g_CfgData.configRep, nStatus, IDS_CHECK_REP))
524 g_CfgData.bRootVolumesReplicationKnown = TRUE;
526 if (!CheckConfigState(IsSCSConfigured, g_CfgData.configSCS, nStatus, IDS_CHECK_SCS))
529 if (!CheckConfigState(IsSCCConfigured, g_CfgData.configSCC, nStatus, IDS_CHECK_SCC))
534 pProg->SetProgress(MAX_STEPS);