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 _________________________________________________________________
19 #include <afsconfig.h>
20 #include <afs/param.h>
29 #include "get_cur_config.h"
30 #include "partition_utils.h"
32 #include <afs\dirpath.h>
33 #include <afs\afs_clientAdmin.h>
35 #include <afs\lanahelper.h>
39 * DEFINITIONS _________________________________________________________________
45 * PROTOTYPES _________________________________________________________________
48 static void SetConfigDefaults();
49 static void RunCfgTool();
50 static void RunWizard();
51 static void CloseLibHandles(BOOL bExiting = FALSE);
53 void RegisterWizardHelp();
54 void RegisterConfigToolHelp();
56 // These are the prototypes for the dialog procs of each wizard page.
57 BOOL CALLBACK IntroPageDlgProc(HWND hRHS, UINT msg, WPARAM wp, LPARAM lp);
58 BOOL CALLBACK InfoPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
59 BOOL CALLBACK InfoPage2DlgProc(HWND hRHS, UINT msg, WPARAM wp, LPARAM lp);
60 BOOL CALLBACK FileServerPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
61 BOOL CALLBACK DBServerPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
62 BOOL CALLBACK BackupPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
63 BOOL CALLBACK PartitionPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
64 BOOL CALLBACK RootAfsPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
65 BOOL CALLBACK ReplicationPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
66 BOOL CALLBACK SysControlPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
67 BOOL CALLBACK ConfigServerPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp);
70 static WIZARD_STATE g_aStates[] = {
71 { sidSTEP_ONE, IDD_INTRO_PAGE, (DLGPROC)IntroPageDlgProc, 0 },
72 { sidSTEP_TWO, IDD_INFO_PAGE, (DLGPROC)InfoPageDlgProc, 0 },
73 { sidSTEP_THREE, IDD_INFO_PAGE2_FIRST_SERVER, (DLGPROC)InfoPage2DlgProc, 0 },
74 { sidSTEP_FOUR, IDD_INFO_PAGE2_NOT_FIRST_SERVER,(DLGPROC)InfoPage2DlgProc, 0 },
75 { sidSTEP_FIVE, IDD_FILE_SERVER_PAGE, (DLGPROC)FileServerPageDlgProc, 0 },
76 { sidSTEP_SIX, IDD_DB_SERVER_PAGE, (DLGPROC)DBServerPageDlgProc, 0 },
77 { sidSTEP_SEVEN, IDD_BACKUP_SERVER_PAGE, (DLGPROC)BackupPageDlgProc, 0 },
78 { sidSTEP_EIGHT, IDD_PARTITION_PAGE, (DLGPROC)PartitionPageDlgProc, 0 },
79 { sidSTEP_NINE, IDD_ROOT_VOLUMES_PAGE, (DLGPROC)RootAfsPageDlgProc, 0 },
80 { sidSTEP_TEN, IDD_REPLICATION_PAGE, (DLGPROC)ReplicationPageDlgProc, 0 },
81 { sidSTEP_ELEVEN, IDD_SYS_CONTROL_PAGE, (DLGPROC)SysControlPageDlgProc, 0 },
82 { sidSTEP_TWELVE, IDD_CONFIG_SERVER_PAGE, (DLGPROC)ConfigServerPageDlgProc, 0 }
85 size_t g_nNumStates = sizeof(g_aStates) / sizeof(g_aStates[0]);
88 // Res ID's of text descriptions of each state
89 UINT g_StateDesc[] = {
107 * EXPORTED VARIABLES _________________________________________________________________
110 LPWIZARD g_pWiz = NULL;
111 LPPROPSHEET g_pSheet = NULL;
120 static void *hClientCell = 0;
127 * EXPORTED FUNCTIONS _________________________________________________________________
130 extern "C" int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pszCmdLineA, int nCmdShow)
132 afs_status_t nStatus;
134 TaLocale_LoadCorrespondingModule (hInst);
136 // Tell the applib our application's name
137 TCHAR szAppName[cchRESOURCE];
138 AfsAppLib_SetAppName(GetResString(GetAppTitleID(), szAppName));
140 // Open the admin libraries
141 int nResult = afsclient_Init(&nStatus);
143 ShowError(0, nStatus, IDS_CANT_INIT_ADMIN_LIBS);
148 char szLogPath[MAX_PATH];
149 sprintf(szLogPath, "%s\\%s", AFSDIR_SERVER_LOGS_DIRPATH, LOG_FILE_NAME);
150 if (!g_LogFile.Open(szLogPath))
151 ShowError(0, 0, IDS_CANT_OPEN_LOG_FILE);
153 // Register the help file with the applib's help system
154 AfsAppLib_RegisterHelpFile(TEXT("TaAfsCfg.hlp"));
156 /* Start up sockets */
158 WSAStartup(0x0101, &WSAjunk);
160 memset(&g_CfgData, 0, sizeof(CFG_DATA));
162 // Get this machine's local name
163 char szLocalName[sizeof(g_CfgData.szLocalName) / sizeof(TCHAR)];
164 if (gethostname(szLocalName, sizeof(szLocalName)) != 0) {
165 ShowError(GetFocus(), WSAGetLastError(), IDS_ERROR_LOCAL_HOST_NAME);
168 CopyAnsiToString(g_CfgData.szLocalName, szLocalName);
170 // Turn the local name into a host name
171 struct hostent *pHostEnt = gethostbyname(szLocalName);
173 ShowError(GetFocus(), WSAGetLastError(), IDS_ERROR_HOST_NAME);
176 CopyAnsiToString(g_CfgData.szHostname, pHostEnt->h_name, sizeof(g_CfgData.szHostname));
178 RegisterFastListClass();
180 // Get current config status
181 BOOL bCanceled = FALSE;
182 DWORD dwStatus = GetCurrentConfig(NULL, bCanceled);
183 if (dwStatus || bCanceled) {
185 ShowError(GetFocus(), dwStatus, IDS_CONFIG_CHECK_FAILED);
189 // Run the appropriate interface
190 if ((strstr(_strlwr(pszCmdLineA), "wizard") != 0))
195 FreePartitionTable();
197 // Disconnect from the config and admin libraries
198 CloseLibHandles(TRUE);
204 * This is a dialog proc that is shared by all of the wizard pages. It
205 * handles things that are common to all of them. Each page also has its
208 BOOL CALLBACK WizStep_Common_DlgProc(HWND hRHS, UINT msg, WPARAM wp, LPARAM lp)
210 // Get the dialog's resource ID
211 int nIDD = GetWindowLong(hRHS, GWL_ID);
213 if (AfsAppLib_HandleHelp(nIDD, hRHS, msg, wp, lp))
217 case WM_INITDIALOG: MakeBold(hRHS, IDC_TITLE);
222 switch (LOWORD(wp)) {
233 BOOL QueryCancelWiz()
235 int nChoice = Message(MB_YESNO, IDS_WIZARD_APP_TITLE, IDS_CANCEL_DESC);
236 if (nChoice == IDYES) {
237 g_LogFile.Write("User has chosen to cancel the program.\r\n");
248 * Accessor functions for the g_CfgData variable. There are versions
249 * for both TCHARs and char *'s.
251 TCHAR GetDeviceName() { return g_CfgData.chDeviceName; }
252 LPTSTR GetPartitionName() { return g_CfgData.szPartitionName; }
253 LPTSTR GetHostName() { return g_CfgData.szHostname; }
254 LPTSTR GetSysControlMachine() { return g_CfgData.szSysControlMachine; }
255 LPTSTR GetCellName() { return g_CfgData.szCellName; }
256 LPTSTR GetServerPW() { return g_CfgData.szServerPW; }
257 LPTSTR GetAdminName() { return g_CfgData.szAdminName; }
258 LPTSTR GetAdminPW() { return g_CfgData.szAdminPW; }
259 LPTSTR GetAdminUID() { return g_CfgData.szAdminUID; }
260 LPTSTR GetLocalName() { return g_CfgData.szLocalName; }
261 LPTSTR GetHostname() { return g_CfgData.szHostname; }
262 LPTSTR GetCellServDbHostname() { return g_CfgData.szCellServDbHostname; }
263 LPTSTR GetClientCellName() { return g_CfgData.szClientCellName; }
264 LPTSTR GetSalvageLogFileName() { return g_CfgData.szSalvageLogFileName; }
266 LPTSTR GetClientNetbiosName()
268 static TCHAR szValue[MAX_MACHINE_NAME_LEN + 1] = "";
270 if ( szValue[0] == 0 )
271 CopyAnsiToString(GetClientNetbiosNameA(), szValue);
276 char GetDeviceNameA()
278 static char szValueA[2];
280 TCHAR devName[2] = TEXT("X");
281 devName[0] = g_CfgData.chDeviceName;
283 CopyStringToAnsi(szValueA, devName);
288 char *GetPartitionNameA()
290 static char szValueA[MAX_PARTITION_NAME_LEN + 1];
292 CopyStringToAnsi(szValueA, g_CfgData.szPartitionName);
297 char *GetSysControlMachineA()
299 static char szValueA[MAX_MACHINE_NAME_LEN + 1];
301 CopyStringToAnsi(szValueA, g_CfgData.szSysControlMachine);
308 static char szValueA[MAX_CELL_NAME_LEN + 1];
310 CopyStringToAnsi(szValueA, g_CfgData.szCellName);
317 static char szValueA[MAX_SERVER_PW_LEN + 1];
319 CopyStringToAnsi(szValueA, g_CfgData.szServerPW);
324 char *GetAdminNameA()
326 static char szValueA[MAX_ADMIN_NAME_LEN + 1];
328 CopyStringToAnsi(szValueA, g_CfgData.szAdminName);
335 static char szValueA[MAX_ADMIN_PW_LEN + 1];
337 CopyStringToAnsi(szValueA, g_CfgData.szAdminPW);
344 static char szValueA[MAX_UID_LEN + 1];
346 CopyStringToAnsi(szValueA, g_CfgData.szAdminUID);
351 char *GetLocalNameA()
353 static char szValueA[MAX_MACHINE_NAME_LEN + 1];
355 CopyStringToAnsi(szValueA, g_CfgData.szLocalName);
362 static char szValueA[MAX_MACHINE_NAME_LEN + 1];
364 CopyStringToAnsi(szValueA, g_CfgData.szHostname);
369 char *GetCellServDbHostnameA()
371 static char szValueA[MAX_MACHINE_NAME_LEN + 1];
373 CopyStringToAnsi(szValueA, g_CfgData.szCellServDbHostname);
378 char *GetClientCellNameA()
380 static char szValueA[MAX_CELL_NAME_LEN + 1];
382 CopyStringToAnsi(szValueA, g_CfgData.szClientCellName);
387 char *GetClientNetbiosNameA()
389 static char szValueA[MAX_MACHINE_NAME_LEN + 1]="";
391 if ( szValueA[0] == 0 )
392 lana_GetNetbiosName(szValueA, LANA_NETBIOS_NAME_FULL);
397 char *GetSalvageLogFileNameA()
399 static char szValueA[_MAX_PATH];
401 CopyStringToAnsi(szValueA, g_CfgData.szSalvageLogFileName);
407 BOOL GetLibHandles(afs_status_t *pStatus)
409 ASSERT(g_CfgData.szHostname[0]);
413 // ************************* NOTE ********************************
414 // * You MUST have already determined whether or not the host
415 // * and client config info is valid before calling this function.
416 // ***************************************************************
418 // This function can be called at any time to get handles to the cell and
419 // the config library. It will try to get the most powerful handle to the
420 // cell that it can, and then use that to open the config library. If the
421 // libraries are already open, it will close them first. Two handles to
422 // the config library will be opened, one to the server to be configured,
423 // and one to the client machine we are configuring from.
425 // There are two types of cell handles, NULL and Standard. A null handle
426 // can make calls to any server except DB servers. We need this primarily
427 // to talk to the bos server to determine the machine's current configuration,
428 // and to configure the client information if it is not already. A standard
429 // handle can talk to any server. Standard handles can be either authenticated
430 // or unauthenticated.
432 // Close all current handles
435 g_LogFile.Write("Getting handles to the cell and the config library.\r\n");
438 // Start by getting a null cell handle and using it to open the client
439 // connection to the config library.
440 g_LogFile.Write("Opening a NULL cell handle to use with the client config library handle.\r\n");
441 nResult = afsclient_NullCellOpen(&hClientCell, pStatus);
443 g_LogFile.Write("Failed to open a NULL cell handle: %lx.\r\n", (unsigned long)*pStatus);
447 // Get the client handle. We never need a better handle than this
448 // for the client, and so this handle will never be upgraded.
449 g_LogFile.Write("Getting config handle for the client.\r\n");
450 if (!cfg_HostOpen(hClientCell, GetHostnameA(), &g_hClient, pStatus)) {
451 g_LogFile.Write("Failed to get config handle: %lx.\r\n", (unsigned long)*pStatus);
456 // Now we need to get the most powerful cell handle that we can and use it
457 // to open the config library for the server.
459 // If the client info is valid and we know what cell the server should be in,
460 // and the client has that cell in its CellServDB, then we can get a Standard cell
461 // handle. However there is an exception: if this is the first server in the
462 // cell then there may not yet be an authentication server to talk to. In that
463 // case we use a null cell handle.
464 if (g_CfgData.bValidClientInfo && // Client config is valid
465 g_CfgData.szCellName[0] && // We have a cell name
466 (!g_CfgData.bFirstServer || g_CfgData.bAuthServerRunning)) // Auth server is running
468 g_LogFile.Write("Opening a non-NULL cell handle to use with the server config library handle.\r\n");
470 // Do we have the user info necessary to authenticate?
471 BOOL bHaveUserInfo = g_CfgData.szAdminName[0] && g_CfgData.szAdminPW[0];
473 // Open a standard cell handle. szAdminName and szAdminPW will either be NULL, or
474 // if they have been entered by the user, will be the admin name and password strings.
475 if ((!g_CfgData.bFirstServer || g_CfgData.bAdminPrincipalCreated) && bHaveUserInfo) {
476 g_LogFile.Write("Getting tokens in cell %s for user '%s'.\r\n", GetCellNameA(), GetAdminNameA());
477 nResult = afsclient_TokenGetNew(GetCellNameA(), GetAdminNameA(), GetAdminPWA(), &g_hToken, pStatus);
479 g_LogFile.Write("Getting unauthenticated tokens for cell '%s'.\r\n", GetCellNameA());
480 nResult = afsclient_TokenGetNew(GetCellNameA(), "", "", &g_hToken, pStatus);
484 g_LogFile.Write("Failed to get tokens for the specified cell: %lx.\r\n", (unsigned long)*pStatus);
488 // If the admin name and password are NULL, then this will be an unauthenticated
489 // connection to the cell.
490 g_LogFile.Write("Getting cell handle for cell %s.\r\n", GetCellNameA());
491 nResult = afsclient_CellOpen(GetCellNameA(), g_hToken, &g_hCell, pStatus);
493 g_LogFile.Write("Failed to open the cell: %lx.\r\n", (unsigned long)*pStatus);
497 g_LogFile.Write("Opening a NULL cell handle to use with the server config library handle.\r\n");
498 nResult = afsclient_NullCellOpen(&g_hCell, pStatus);
500 g_LogFile.Write("Failed to open a NULL cell handle: %lx.\r\n", (unsigned long)*pStatus);
505 // Get the server handle
506 g_LogFile.Write("Getting config library handle for the server.\r\n");
507 if (!cfg_HostOpen(g_hCell, GetHostnameA(), &g_hServer, pStatus)) {
508 g_LogFile.Write("Failed to get config library handle for the server: %lx.\r\n", (unsigned long)*pStatus);
515 BOOL GetHandles(HWND hParentDlg)
517 afs_status_t nStatus;
519 if (!GetLibHandles(&nStatus)) {
520 ShowError(hParentDlg, nStatus, IDS_GET_TOKENS_ERROR);
521 g_CfgData.szAdminPW[0] = 0;
530 * Static FUNCTIONS _________________________________________________________________
533 static void CloseLibHandles(BOOL bExiting)
535 afs_status_t nStatus;
537 // We will close them in the reverse order of their creation.
539 cfg_HostClose(g_hServer, &nStatus);
544 afsclient_CellClose(g_hCell, &nStatus);
549 afsclient_TokenClose(g_hToken, &nStatus);
553 // Only close the client cfg and cell handles if we are exiting.
556 cfg_HostClose(g_hClient, &nStatus);
561 afsclient_CellClose(hClientCell, &nStatus);
567 static void SetConfigDefaults()
569 if (g_CfgData.bWizard) {
570 if (g_CfgData.configFS == CS_NULL)
571 g_CfgData.configFS = CS_CONFIGURE;
573 if (g_CfgData.configDB == CS_NULL)
574 g_CfgData.configDB = CS_CONFIGURE;
576 if (g_CfgData.configBak == CS_NULL)
577 g_CfgData.configBak = CS_CONFIGURE;
579 if (g_CfgData.configPartition == CS_NULL)
580 g_CfgData.configPartition = CS_CONFIGURE;
582 if (g_CfgData.configRootVolumes == CS_NULL)
583 g_CfgData.configRootVolumes = CS_CONFIGURE;
585 if (g_CfgData.configRep == CS_NULL)
586 g_CfgData.configRep = CS_CONFIGURE;
588 if (g_CfgData.configSCS == CS_NULL)
589 g_CfgData.configSCS = CS_DONT_CONFIGURE;
591 if (g_CfgData.configSCC == CS_NULL)
592 g_CfgData.configSCC = CS_DONT_CONFIGURE;
595 lstrcpy(g_CfgData.szAdminName, TEXT("admin"));
596 lstrcpy(g_CfgData.szAdminUID, TEXT("0"));
598 g_CfgData.bUseNextUid = TRUE;
602 // Prototypes for each property page's dialog proc
603 BOOL CALLBACK PartitionsPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
604 BOOL CALLBACK ServicesPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
606 static void RunCfgTool()
608 // If the client info is invalid, then the config tool cannot run. Inform the user and
609 // ask if they want to run the wizard instead.
610 if (!g_CfgData.bValidClientInfo) {
611 int nChoice = MsgBox(0, IDS_NEED_CLIENT_INFO, GetAppTitleID(), MB_YESNO | MB_ICONSTOP);
612 if (nChoice == IDYES)
617 // If the server info is invalid, then the config tool cannot run. The Wizard must be run
618 // to initially configure the server. Inform the user and ask if they want to run the wizard instead.
619 if (!g_CfgData.bValidServerInfo) {
620 int nChoice = MsgBox(0, IDS_NEED_SERVER_INFO, GetAppTitleID(), MB_OKCANCEL | MB_ICONEXCLAMATION);
626 g_CfgData.bWizard = FALSE;
630 RegisterConfigToolHelp();
632 // Create the prop sheet
633 g_pSheet = PropSheet_Create(IDS_CFG_TOOL_APP_TITLE, TRUE);
636 PropSheet_AddTab(g_pSheet, IDS_PARTITIONS_PAGE_TITLE, IDD_PARTITIONS_PAGE, (DLGPROC)PartitionsPageDlgProc, 0, TRUE, TRUE);
637 PropSheet_AddTab(g_pSheet, IDS_SERVICES_PAGE_TITLE, IDD_SERVICES_PAGE, (DLGPROC)ServicesPageDlgProc, 0, TRUE);
639 // Let the user see it
640 PropSheet_ShowModal(g_pSheet);
643 static void RunWizard()
645 g_CfgData.bWizard = TRUE;
649 RegisterWizardHelp();
652 g_pWiz->SetDialogTemplate(IDD_WIZARD, IDC_WIZARD_LEFTPANE, IDC_WIZARD_RIGHTPANE, IDBACK, IDNEXT);
653 g_pWiz->SetGraphic(IDB_GRAPHIC_16, IDB_GRAPHIC_256);
654 g_pWiz->SetStates(g_aStates, g_nNumStates);
655 g_pWiz->SetGraphicCallback(PaintPageGraphic);
657 g_pWiz->SetState(sidSTEP_ONE);