//------------------------------------------------------------------ // // Copyright (C) 2010 Intel Corporation // // File: HostBasedSetupSample.cpp // //------------------------------------------------------------------ #include "HostBasedSetupSample.h" #include "HostBasedSetupTypedFlow.h" #include "HostBasedSetupUntypedFlow.h" #include "CommonDefinitions.h" #include "Options.h" #include "PTHICommand.h" #include "CimOpenWsmanClient.h" #include using namespace std; using namespace Intel::Manageability::Exceptions; /* * This is a main entry point */ int main(UINT32 argc, char *argv[]) { PT_STATUS status = PT_STATUS_SUCCESS; HOST_BASED_SETUP_PARAMS params; if (1 == argc) { // Running the sample with no parameters displays the usage DisplayUsage(); return PT_STATUS_SUCCESS; } if (false == Parse(argc, argv, ¶ms)) { DisplayUsage(); return PTSDK_STATUS_INVALID_PARAM; } if (params.Disable && !params.Force) { cout << endl << "Since this operation is irreversible (once client control mode is disabled it " << endl; cout << "cannot be enabled), one must use the " << CMD_FORCE << " option as well to actually disable " << endl; cout << "the client control mode." <Discovery = false; params->Setup = false; params->Disable = false; params->NewAdminPassword = ""; params->AdapterName = ""; params->Force = false; params->Unprovision = false; params->WMI = false; Options options; const Options::FormatNode format[] = {{CMD_DISCOVERY, false}, {CMD_SETUP, false}, {CMD_NEWPASS, true}, {CMD_ADAPTERNAME, true}, {CMD_DISABLE, false}, {CMD_FORCE, false}, {CMD_UNPROVISION, false}, {CMD_WMI, false}}; if (!options.Parse(argc, const_cast(argv), format, sizeof(format)/sizeof(Options::FormatNode))) { cout << endl << "Error: Invalid parameter" << endl; return false; } if(options.OptionExists(CMD_DISCOVERY)) { params->Discovery = true; } if(options.OptionExists(CMD_SETUP)) { if (params->Discovery) { cout << endl << "Error: Cannot specify more than one option" << endl; return false; } params->Setup = true; if (options.OptionExists(CMD_NEWPASS)) { auto res = options.GetOption(CMD_NEWPASS); params->NewAdminPassword = (res != NULL) ? res : ""; if (params->NewAdminPassword != "" && (params->NewAdminPassword.length() < 8 || params->NewAdminPassword.length() > 32)) { cout << endl << "Error: Password must contain between 8 to 32 characters." << endl; return false; } } else { cout << endl << "Error: Must specify " << CMD_NEWPASS << " with the " << CMD_SETUP << " option" << endl; return false; } if (options.OptionExists(CMD_ADAPTERNAME)) { auto res = options.GetOption(CMD_ADAPTERNAME); params->AdapterName = (res != NULL) ? res : ""; } } if(options.OptionExists(CMD_DISABLE)) { if (params->Setup || params->Discovery) { cout << endl << "Error: Cannot specify more than one option" << endl; return false; } params->Disable = true; params->Force = options.OptionExists(CMD_FORCE); } if(options.OptionExists(CMD_UNPROVISION)) { if (params->Disable || params->Setup || params->Discovery) { cout << endl << "Error: Cannot specify more than one option" << endl; return false; } params->Unprovision = true; } if (!params->Discovery && !params->Setup && !params->Disable && !params->Unprovision) { cout << endl << "Error: Must specify a valid option" << endl; return false; } if(options.OptionExists(CMD_WMI)) { params->WMI = true; } return true; } /* * Description: Displays the usage. */ VOID DisplayUsage() { cout << endl << "Usage:" << endl; cout << "HostBasedSetup.exe < -" << CMD_DISCOVERY << " | -" << CMD_SETUP << " -" << CMD_NEWPASS << " -" << CMD_ADAPTERNAME; cout << " | -" << CMD_DISABLE << " -" << CMD_FORCE << " | -"<< CMD_UNPROVISION << " >"; cout << " [-" << CMD_WMI << "]" << endl; cout << endl << "Where options are: " << endl << endl; cout << " " << CMD_DISCOVERY; cout << " - Perform discovery test on the Intel(R) AMT device." << endl; cout << endl; cout << " " << CMD_SETUP; cout << " - Perform setup of an Intel(R) AMT device in client control mode." << endl; cout << endl; cout << " " << CMD_DISABLE; cout << " - Disable the client control mode of an Intel(R) AMT device." << endl; cout << " Since this operation is irreversible (once client control mode " << endl; cout << " is disabled it cannot be enabled), one must use the " << CMD_FORCE << endl; cout << " option as well to actually disable the client control mode." <