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 _________________________________________________________________
16 #include <afs/param.h>
24 #include "get_cur_config.h"
25 #include "partition_utils.h"
27 #include <afs\dirpath.h>
28 #include <afs\afs_clientAdmin.h>
33 * DEFINITIONS _________________________________________________________________
39 * PROTOTYPES _________________________________________________________________
42 static void SetConfigDefaults();
43 static void RunCfgTool();
44 static void RunWizard();
45 static void CloseLibHandles(BOOL bExiting = FALSE);
47 void RegisterWizardHelp();
48 void RegisterConfigToolHelp();
50 // These are the prototypes for the dialog procs of each wizard page.
51 BOOL CALLBACK IntroPageDlgProc(HWND hRHS, UINT msg, WPARAM wp, LPARAM lp);
52 BOOL CALLBACK InfoPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
53 BOOL CALLBACK InfoPage2DlgProc(HWND hRHS, UINT msg, WPARAM wp, LPARAM lp);
54 BOOL CALLBACK FileServerPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
55 BOOL CALLBACK DBServerPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
56 BOOL CALLBACK BackupPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
57 BOOL CALLBACK PartitionPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
58 BOOL CALLBACK RootAfsPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
59 BOOL CALLBACK ReplicationPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
60 BOOL CALLBACK SysControlPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
61 BOOL CALLBACK ConfigServerPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
64 static WIZARD_STATE g_aStates[] = {
65 { sidSTEP_ONE, IDD_INTRO_PAGE, (DLGPROC)IntroPageDlgProc, 0 },
66 { sidSTEP_TWO, IDD_INFO_PAGE, (DLGPROC)InfoPageDlgProc, 0 },
67 { sidSTEP_THREE, IDD_INFO_PAGE2_FIRST_SERVER, (DLGPROC)InfoPage2DlgProc, 0 },
68 { sidSTEP_FOUR, IDD_INFO_PAGE2_NOT_FIRST_SERVER,(DLGPROC)InfoPage2DlgProc, 0 },
69 { sidSTEP_FIVE, IDD_FILE_SERVER_PAGE, (DLGPROC)FileServerPageDlgProc, 0 },
70 { sidSTEP_SIX, IDD_DB_SERVER_PAGE, (DLGPROC)DBServerPageDlgProc, 0 },
71 { sidSTEP_SEVEN, IDD_BACKUP_SERVER_PAGE, (DLGPROC)BackupPageDlgProc, 0 },
72 { sidSTEP_EIGHT, IDD_PARTITION_PAGE, (DLGPROC)PartitionPageDlgProc, 0 },
73 { sidSTEP_NINE, IDD_ROOT_VOLUMES_PAGE, (DLGPROC)RootAfsPageDlgProc, 0 },
74 { sidSTEP_TEN, IDD_REPLICATION_PAGE, (DLGPROC)ReplicationPageDlgProc, 0 },
75 { sidSTEP_ELEVEN, IDD_SYS_CONTROL_PAGE, (DLGPROC)SysControlPageDlgProc, 0 },
76 { sidSTEP_TWELVE, IDD_CONFIG_SERVER_PAGE, (DLGPROC)ConfigServerPageDlgProc, 0 }
79 size_t g_nNumStates = sizeof(g_aStates) / sizeof(g_aStates[0]);
82 // Res ID's of text descriptions of each state
83 UINT g_StateDesc[] = {
101 * EXPORTED VARIABLES _________________________________________________________________
104 LPWIZARD g_pWiz = NULL;
105 LPPROPSHEET g_pSheet = NULL;
114 static void *hClientCell = 0;
121 * EXPORTED FUNCTIONS _________________________________________________________________
124 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pszCmdLineA, int nCmdShow)
126 afs_status_t nStatus;
128 TaLocale_LoadCorrespondingModule (hInst);
130 // Tell the applib our application's name
131 TCHAR szAppName[cchRESOURCE];
132 AfsAppLib_SetAppName(GetResString(GetAppTitleID(), szAppName));
134 // Open the admin libraries
135 int nResult = afsclient_Init(&nStatus);
137 ShowError(0, nStatus, IDS_CANT_INIT_ADMIN_LIBS);
142 char szLogPath[MAX_PATH];
143 sprintf(szLogPath, "%s\\%s", AFSDIR_SERVER_LOGS_DIRPATH, LOG_FILE_NAME);
144 if (!g_LogFile.Open(szLogPath))
145 ShowError(0, 0, IDS_CANT_OPEN_LOG_FILE);
147 // Register the help file with the applib's help system
148 AfsAppLib_RegisterHelpFile(TEXT("TaAfsCfg.hlp"));
150 /* Start up sockets */
152 WSAStartup(0x0101, &WSAjunk);
154 memset(&g_CfgData, 0, sizeof(CFG_DATA));
156 // Get this machine's local name
157 char szLocalName[sizeof(g_CfgData.szLocalName) / sizeof(TCHAR)];
158 if (gethostname(szLocalName, sizeof(szLocalName)) != 0) {
159 ShowError(GetFocus(), WSAGetLastError(), IDS_ERROR_LOCAL_HOST_NAME);
162 CopyAnsiToString(g_CfgData.szLocalName, szLocalName);
164 // Turn the local name into a host name
165 struct hostent *pHostEnt = gethostbyname(szLocalName);
167 ShowError(GetFocus(), WSAGetLastError(), IDS_ERROR_HOST_NAME);
170 CopyAnsiToString(g_CfgData.szHostname, pHostEnt->h_name, sizeof(g_CfgData.szHostname));
172 RegisterFastListClass();
174 // Get current config status
175 BOOL bCanceled = FALSE;
176 DWORD dwStatus = GetCurrentConfig(NULL, bCanceled);
177 if (dwStatus || bCanceled) {
179 ShowError(GetFocus(), dwStatus, IDS_CONFIG_CHECK_FAILED);
183 // Run the appropriate interface
184 if ((strstr(_strlwr(pszCmdLineA), "wizard") != 0))
189 FreePartitionTable();
191 // Disconnect from the config and admin libraries
192 CloseLibHandles(TRUE);
198 * This is a dialog proc that is shared by all of the wizard pages. It
199 * handles things that are common to all of them. Each page also has its
202 BOOL CALLBACK WizStep_Common_DlgProc(HWND hRHS, UINT msg, WPARAM wp, LPARAM lp)
204 // Get the dialog's resource ID
205 int nIDD = GetWindowLong(hRHS, GWL_ID);
207 if (AfsAppLib_HandleHelp(nIDD, hRHS, msg, wp, lp))
211 case WM_INITDIALOG: MakeBold(hRHS, IDC_TITLE);
216 switch (LOWORD(wp)) {
227 BOOL QueryCancelWiz()
229 int nChoice = Message(MB_YESNO, IDS_WIZARD_APP_TITLE, IDS_CANCEL_DESC);
230 if (nChoice == IDYES) {
231 g_LogFile.Write("User has chosen to cancel the program.\r\n");
242 * Accessor functions for the g_CfgData variable. There are versions
243 * for both TCHARs and char *'s.
245 TCHAR GetDeviceName() { return g_CfgData.chDeviceName; }
246 LPTSTR GetPartitionName() { return g_CfgData.szPartitionName; }
247 LPTSTR GetHostName() { return g_CfgData.szHostname; }
248 LPTSTR GetSysControlMachine() { return g_CfgData.szSysControlMachine; }
249 LPTSTR GetCellName() { return g_CfgData.szCellName; }
250 LPTSTR GetServerPW() { return g_CfgData.szServerPW; }
251 LPTSTR GetAdminName() { return g_CfgData.szAdminName; }
252 LPTSTR GetAdminPW() { return g_CfgData.szAdminPW; }
253 LPTSTR GetAdminUID() { return g_CfgData.szAdminUID; }
254 LPTSTR GetLocalName() { return g_CfgData.szLocalName; }
255 LPTSTR GetHostname() { return g_CfgData.szHostname; }
256 LPTSTR GetCellServDbHostname() { return g_CfgData.szCellServDbHostname; }
257 LPTSTR GetClientCellName() { return g_CfgData.szClientCellName; }
258 LPTSTR GetSalvageLogFileName() { return g_CfgData.szSalvageLogFileName; }
260 LPTSTR GetClientNetbiosName()
262 static TCHAR szValue[MAX_MACHINE_NAME_LEN + 1];
264 lstrcpy(szValue, g_CfgData.szLocalName);
266 szValue[11] = TEXT('\0');
268 for (LPTSTR pch = szValue; *pch != TEXT('\0'); pch++) {
269 if (*pch == TEXT('.')) {
274 lstrcat(szValue, TEXT("-AFS"));
279 char GetDeviceNameA()
281 static char szValueA[2];
283 TCHAR devName[2] = TEXT("X");
284 devName[0] = g_CfgData.chDeviceName;
286 CopyStringToAnsi(szValueA, devName);
291 char *GetPartitionNameA()
293 static char szValueA[MAX_PARTITION_NAME_LEN + 1];
295 CopyStringToAnsi(szValueA, g_CfgData.szPartitionName);
300 char *GetSysControlMachineA()
302 static char szValueA[MAX_MACHINE_NAME_LEN + 1];
304 CopyStringToAnsi(szValueA, g_CfgData.szSysControlMachine);
311 static char szValueA[MAX_CELL_NAME_LEN + 1];
313 CopyStringToAnsi(szValueA, g_CfgData.szCellName);
320 static char szValueA[MAX_SERVER_PW_LEN + 1];
322 CopyStringToAnsi(szValueA, g_CfgData.szServerPW);
327 char *GetAdminNameA()
329 static char szValueA[MAX_ADMIN_NAME_LEN + 1];
331 CopyStringToAnsi(szValueA, g_CfgData.szAdminName);
338 static char szValueA[MAX_ADMIN_PW_LEN + 1];
340 CopyStringToAnsi(szValueA, g_CfgData.szAdminPW);
347 static char szValueA[MAX_UID_LEN + 1];
349 CopyStringToAnsi(szValueA, g_CfgData.szAdminUID);
354 char *GetLocalNameA()
356 static char szValueA[MAX_MACHINE_NAME_LEN + 1];
358 CopyStringToAnsi(szValueA, g_CfgData.szLocalName);
365 static char szValueA[MAX_MACHINE_NAME_LEN + 1];
367 CopyStringToAnsi(szValueA, g_CfgData.szHostname);
372 char *GetCellServDbHostnameA()
374 static char szValueA[MAX_MACHINE_NAME_LEN + 1];
376 CopyStringToAnsi(szValueA, g_CfgData.szCellServDbHostname);
381 char *GetClientCellNameA()
383 static char szValueA[MAX_CELL_NAME_LEN + 1];
385 CopyStringToAnsi(szValueA, g_CfgData.szClientCellName);
390 char *GetClientNetbiosNameA()
392 static char szValueA[MAX_MACHINE_NAME_LEN + 1];
395 CopyStringToAnsi(szValueA, g_CfgData.szLocalName);
399 if ((dotp = strchr(szValueA, '.')) != NULL) {
402 strcat(szValueA, "-AFS");
407 char *GetSalvageLogFileNameA()
409 static char szValueA[_MAX_PATH];
411 CopyStringToAnsi(szValueA, g_CfgData.szSalvageLogFileName);
417 BOOL GetLibHandles(afs_status_t *pStatus)
419 ASSERT(g_CfgData.szHostname[0]);
423 // ************************* NOTE ********************************
424 // * You MUST have already determined whether or not the host
425 // * and client config info is valid before calling this function.
426 // ***************************************************************
428 // This function can be called at any time to get handles to the cell and
429 // the config library. It will try to get the most powerful handle to the
430 // cell that it can, and then use that to open the config library. If the
431 // libraries are already open, it will close them first. Two handles to
432 // the config library will be opened, one to the server to be configured,
433 // and one to the client machine we are configuring from.
435 // There are two types of cell handles, NULL and Standard. A null handle
436 // can make calls to any server except DB servers. We need this primarily
437 // to talk to the bos server to determine the machine's current configuration,
438 // and to configure the client information if it is not already. A standard
439 // handle can talk to any server. Standard handles can be either authenticated
440 // or unauthenticated.
442 // Close all current handles
445 g_LogFile.Write("Getting handles to the cell and the config library.\r\n");
448 // Start by getting a null cell handle and using it to open the client
449 // connection to the config library.
450 g_LogFile.Write("Opening a NULL cell handle to use with the client config library handle.\r\n");
451 nResult = afsclient_NullCellOpen(&hClientCell, pStatus);
453 g_LogFile.Write("Failed to open a NULL cell handle: %lx.\r\n", (unsigned long)*pStatus);
457 // Get the client handle. We never need a better handle than this
458 // for the client, and so this handle will never be upgraded.
459 g_LogFile.Write("Getting config handle for the client.\r\n");
460 if (!cfg_HostOpen(hClientCell, GetHostnameA(), &g_hClient, pStatus)) {
461 g_LogFile.Write("Failed to get config handle: %lx.\r\n", (unsigned long)*pStatus);
466 // Now we need to get the most powerful cell handle that we can and use it
467 // to open the config library for the server.
469 // If the client info is valid and we know what cell the server should be in,
470 // and the client has that cell in its CellServDB, then we can get a Standard cell
471 // handle. However there is an exception: if this is the first server in the
472 // cell then there may not yet be an authentication server to talk to. In that
473 // case we use a null cell handle.
474 if (g_CfgData.bValidClientInfo && // Client config is valid
475 g_CfgData.szCellName[0] && // We have a cell name
476 (!g_CfgData.bFirstServer || g_CfgData.bAuthServerRunning)) // Auth server is running
478 g_LogFile.Write("Opening a non-NULL cell handle to use with the server config library handle.\r\n");
480 // Do we have the user info necessary to authenticate?
481 BOOL bHaveUserInfo = g_CfgData.szAdminName[0] && g_CfgData.szAdminPW[0];
483 // Open a standard cell handle. szAdminName and szAdminPW will either be NULL, or
484 // if they have been entered by the user, will be the admin name and password strings.
485 if ((!g_CfgData.bFirstServer || g_CfgData.bAdminPrincipalCreated) && bHaveUserInfo) {
486 g_LogFile.Write("Getting tokens in cell %s for user '%s'.\r\n", GetCellNameA(), GetAdminNameA());
487 nResult = afsclient_TokenGetNew(GetCellNameA(), GetAdminNameA(), GetAdminPWA(), &g_hToken, pStatus);
489 g_LogFile.Write("Getting unauthenticated tokens for cell '%s'.\r\n", GetCellNameA());
490 nResult = afsclient_TokenGetNew(GetCellNameA(), "", "", &g_hToken, pStatus);
494 g_LogFile.Write("Failed to get tokens for the specified cell: %lx.\r\n", (unsigned long)*pStatus);
498 // If the admin name and password are NULL, then this will be an unauthenticated
499 // connection to the cell.
500 g_LogFile.Write("Getting cell handle for cell %s.\r\n", GetCellNameA());
501 nResult = afsclient_CellOpen(GetCellNameA(), g_hToken, &g_hCell, pStatus);
503 g_LogFile.Write("Failed to open the cell: %lx.\r\n", (unsigned long)*pStatus);
507 g_LogFile.Write("Opening a NULL cell handle to use with the server config library handle.\r\n");
508 nResult = afsclient_NullCellOpen(&g_hCell, pStatus);
510 g_LogFile.Write("Failed to open a NULL cell handle: %lx.\r\n", (unsigned long)*pStatus);
515 // Get the server handle
516 g_LogFile.Write("Getting config library handle for the server.\r\n");
517 if (!cfg_HostOpen(g_hCell, GetHostnameA(), &g_hServer, pStatus)) {
518 g_LogFile.Write("Failed to get config library handle for the server: %lx.\r\n", (unsigned long)*pStatus);
525 BOOL GetHandles(HWND hParentDlg)
527 afs_status_t nStatus;
529 if (!GetLibHandles(&nStatus)) {
530 ShowError(hParentDlg, nStatus, IDS_GET_TOKENS_ERROR);
531 g_CfgData.szAdminPW[0] = 0;
540 * Static FUNCTIONS _________________________________________________________________
543 static void CloseLibHandles(BOOL bExiting)
545 afs_status_t nStatus;
547 // We will close them in the reverse order of their creation.
550 cfg_HostClose(g_hServer, &nStatus);
555 afsclient_CellClose(g_hCell, &nStatus);
560 afsclient_TokenClose(g_hToken, &nStatus);
564 // Only close the client cfg and cell handles if we are exiting.
567 cfg_HostClose(g_hClient, &nStatus);
572 afsclient_CellClose(hClientCell, &nStatus);
578 static void SetConfigDefaults()
580 if (g_CfgData.bWizard) {
581 if (g_CfgData.configFS == CS_NULL)
582 g_CfgData.configFS = CS_CONFIGURE;
584 if (g_CfgData.configDB == CS_NULL)
585 g_CfgData.configDB = CS_CONFIGURE;
587 if (g_CfgData.configBak == CS_NULL)
588 g_CfgData.configBak = CS_CONFIGURE;
590 if (g_CfgData.configPartition == CS_NULL)
591 g_CfgData.configPartition = CS_CONFIGURE;
593 if (g_CfgData.configRootVolumes == CS_NULL)
594 g_CfgData.configRootVolumes = CS_CONFIGURE;
596 if (g_CfgData.configRep == CS_NULL)
597 g_CfgData.configRep = CS_CONFIGURE;
599 if (g_CfgData.configSCS == CS_NULL)
600 g_CfgData.configSCS = CS_DONT_CONFIGURE;
602 if (g_CfgData.configSCC == CS_NULL)
603 g_CfgData.configSCC = CS_DONT_CONFIGURE;
606 lstrcpy(g_CfgData.szAdminName, TEXT("admin"));
607 lstrcpy(g_CfgData.szAdminUID, TEXT("0"));
609 g_CfgData.bUseNextUid = TRUE;
613 // Prototypes for each property page's dialog proc
614 BOOL CALLBACK PartitionsPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
615 BOOL CALLBACK ServicesPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
617 static void RunCfgTool()
619 // If the client info is invalid, then the config tool cannot run. Inform the user and
620 // ask if they want to run the wizard instead.
621 if (!g_CfgData.bValidClientInfo) {
622 int nChoice = MsgBox(0, IDS_NEED_CLIENT_INFO, GetAppTitleID(), MB_YESNO | MB_ICONSTOP);
623 if (nChoice == IDYES)
628 // If the server info is invalid, then the config tool cannot run. The Wizard must be run
629 // to initially configure the server. Inform the user and ask if they want to run the wizard instead.
630 if (!g_CfgData.bValidServerInfo) {
631 int nChoice = MsgBox(0, IDS_NEED_SERVER_INFO, GetAppTitleID(), MB_OKCANCEL | MB_ICONEXCLAMATION);
637 g_CfgData.bWizard = FALSE;
641 RegisterConfigToolHelp();
643 // Create the prop sheet
644 g_pSheet = PropSheet_Create(IDS_CFG_TOOL_APP_TITLE, TRUE);
647 PropSheet_AddTab(g_pSheet, IDS_PARTITIONS_PAGE_TITLE, IDD_PARTITIONS_PAGE, (DLGPROC)PartitionsPageDlgProc, 0, TRUE, TRUE);
648 PropSheet_AddTab(g_pSheet, IDS_SERVICES_PAGE_TITLE, IDD_SERVICES_PAGE, (DLGPROC)ServicesPageDlgProc, 0, TRUE);
650 // Let the user see it
651 PropSheet_ShowModal(g_pSheet);
654 static void RunWizard()
656 g_CfgData.bWizard = TRUE;
660 RegisterWizardHelp();
663 g_pWiz->SetDialogTemplate(IDD_WIZARD, IDC_WIZARD_LEFTPANE, IDC_WIZARD_RIGHTPANE, IDBACK, IDNEXT);
664 g_pWiz->SetGraphic(IDB_GRAPHIC_16, IDB_GRAPHIC_256);
665 g_pWiz->SetStates(g_aStates, g_nNumStates);
666 g_pWiz->SetGraphicCallback(PaintPageGraphic);
668 g_pWiz->SetState(sidSTEP_ONE);