bool ResourceManifest::loadInclude(IPropertyTree &include, const char *dir) { const char *filename = include.queryProp("@filename"); StringBuffer includePath; makeAbsolutePath(filename, dir, includePath); VStringBuffer xpath("Include[@originalFilename='%s']", includePath.str()); if (manifest->hasProp(xpath.str())) return false; include.setProp("@originalFilename", includePath.str()); StringBuffer includeDir; splitDirTail(includePath, includeDir); Owned<IPropertyTree> manifestInclude = createPTreeFromXMLFile(includePath.str()); Owned<IPropertyTreeIterator> it = manifestInclude->getElements("*"); ForEach(*it) { IPropertyTree &item = it->query(); if (streq(item.queryName(), "Resource")) updateResourcePaths(item, includeDir.str()); else if (streq(item.queryName(), "Include")) { if (!loadInclude(item, includeDir.str())) continue; } manifest->addPropTree(item.queryName(), LINK(&item)); } return true; }
ILoggingManager* init(const char* inputFileName) { if(!inputFileName || !*inputFileName) { printf("Input file not defined.\n"); return NULL; } printf("Input file: %s\n", inputFileName); loggingInput.setown(createPTreeFromXMLFile(inputFileName, ipt_caseInsensitive)); if (!loggingInput) { printf("can't read input file.\n"); return NULL; } loggingConfig = loggingInput->queryPropTree("config/LoggingManager"); testData = loggingInput->queryPropTree("test"); if (!loggingConfig || !testData) { printf("can't read input file.\n"); return NULL; } loggingManager.setown(loadLogggingManager()); if (!loggingManager) { printf("No logging manager\n"); return NULL; } loggingManager->init(loggingConfig, "test_service"); return loggingManager; }
ResourceManifest(const char *filename) : manifest(createPTreeFromXMLFile(filename)) { makeAbsolutePath(filename, absFilename); splitDirTail(absFilename, dir); expand(); }
void CEspConfig::initPtree(const char *location, bool isDali) { IPropertyTree* cfg = createPTreeFromXMLFile(location, ipt_caseInsensitive); if (cfg) { cfg->addProp("@config", location); m_envpt.setown(cfg); } }
void CEclAgentExecutionServer::start(StringBuffer & codeDir) { if (started) { WARNLOG("START called when already started\n"); assert(false); } codeDirectory = codeDir; StringBuffer propertyFile = codeDirectory; addPathSepChar(propertyFile); propertyFile.append("agentexec.xml"); Owned<IPropertyTree> properties; try { DBGLOG("AgentExec: Loading properties file '%s'\n", propertyFile.str()); properties.setown(createPTreeFromXMLFile(propertyFile.str())); } catch (IException *e) { EXCLOG(e, "Error processing properties file\n"); throwUnexpected(); } { //Build logfile from component properties settings Owned<IComponentLogFileCreator> lf = createComponentLogFileCreator(properties, "eclagent"); lf->setCreateAliasFile(false); lf->setMsgFields(MSGFIELD_timeDate | MSGFIELD_msgID | MSGFIELD_process | MSGFIELD_thread | MSGFIELD_code); lf->beginLogging(); PROGLOG("Logging to %s",lf->queryLogFileSpec()); } //get name of workunit job queue StringBuffer sb; properties->getProp("@name", sb.clear()); agentName.set(sb); if (!agentName.length()) { ERRLOG("'name' not specified in properties file\n"); throwUnexpected(); } //get dali server(s) properties->getProp("@daliServers", daliServers); if (!daliServers.length()) { ERRLOG("'daliServers' not specified in properties file\n"); throwUnexpected(); } started = true; Thread::start(); Thread::join(); }
void CEclAgentExecutionServer::start() { if (started) { WARNLOG("START called when already started\n"); assert(false); } Owned<IPropertyTree> properties; try { DBGLOG("AgentExec: Loading properties file 'agentexec.xml'"); properties.setown(createPTreeFromXMLFile("agentexec.xml")); } catch (IException *e) { EXCLOG(e, "Error processing properties file\n"); throwUnexpected(); } { //Build logfile from component properties settings Owned<IComponentLogFileCreator> lf = createComponentLogFileCreator(properties, "eclagent"); lf->setCreateAliasFile(false); lf->beginLogging(); PROGLOG("Logging to %s",lf->queryLogFileSpec()); } //get name of workunit job queue StringBuffer sb; properties->getProp("@name", sb.clear()); agentName.set(sb); if (!agentName.length()) { ERRLOG("'name' not specified in properties file\n"); throwUnexpected(); } setStatisticsComponentName(SCThthor, agentName, true); //get dali server(s) properties->getProp("@daliServers", daliServers); if (!daliServers.length()) { ERRLOG("'daliServers' not specified in properties file\n"); throwUnexpected(); } started = true; Thread::start(); Thread::join(); }
int main(int argc, char* argv[]) { if(argc != 2) { printf("usage: addScopes daliconf.xml\n"); printf("\n\tCreates all user-specific LDAP private file scopes 'hpccinternal::<user>'\n\tand grants users access to their scope. The configuration file\n\tdaliconf.xml is the dali configuration file, typically\n\tfound in /var/lib/HPCCSystems/mydali\n\n"); return -1; } InitModuleObjects(); try { Owned<IPropertyTree> cfg = createPTreeFromXMLFile(argv[1]); Owned<IPropertyTree> seccfg = cfg->getPropTree(".//ldapSecurity"); if(seccfg == NULL) { printf("ldapSecurity not found\n"); return -1; } #ifdef _NO_LDAP printf("System was built with _NO_LDAP\n"); return -1; #else Owned<ISecManager> secmgr = newLdapSecManager("addScopes", *LINK(seccfg)); if(secmgr == NULL) { printf("Security manager can't be created\n"); return -1; } bool ok = secmgr->createUserScopes(); printf(ok ? "User scopes added\n" : "Some scopes not added\n"); #endif } catch(IException* e) { StringBuffer errmsg; e->errorMessage(errmsg); printf("%s\n", errmsg.str()); } catch(...) { printf("Unknown exception\n"); } releaseAtoms(); return 0; }
void ResourceManager::addManifest(const char *filename) { if (finalized) throwError1(HQLERR_ResourceAddAfterFinalManifest, "MANIFEST"); Owned<IPropertyTree> manifestSrc = createPTreeFromXMLFile(filename); StringBuffer dir; splitDirTail(filename, dir); ensureManifestInfo(); Owned<IAttributeIterator> aiter = manifestSrc->getAttributes(); ForEach (*aiter) manifest->setProp(aiter->queryName(), aiter->queryValue()); Owned<IPropertyTreeIterator> iter = manifestSrc->getElements("*"); ForEach(*iter) { IPropertyTree &item = iter->query(); if (streq(item.queryName(), "Resource") && item.hasProp("@filename")) { if (!item.hasProp("@type")) item.setProp("@type", "UNKNOWN"); const char *filename = item.queryProp("@filename"); int id; if (getDuplicateResourceId(item.queryProp("@type"), filename, id)) { item.setPropInt("@id", id); manifest->addPropTree("Resource", LINK(&item)); } else { StringBuffer fullpath; if (!isAbsolutePath(filename)) fullpath.append(dir); fullpath.append(filename); MemoryBuffer content; loadResource(fullpath.str(), content); addCompress(item.queryProp("@type"), content.length(), content.toByteArray(), &item); } } else manifest->addPropTree(item.queryName(), LINK(&item)); } }
void CEnvGen::addUpdateTaskFromFile(const char * inFile) { Owned<IPropertyTree> inPTree; if ((String(inFile).toLowerCase())->endsWith(".json")) { StringBuffer sbFile; sbFile.loadFile(inFile); inPTree.setown(createPTreeFromJSONString(sbFile.str())); } else { inPTree.setown(createPTreeFromXMLFile(inFile)); } // add Config attributies to params IPropertyTree *pCfg = m_params->queryPropTree("Config"); assert(pCfg); Owned<IAttributeIterator> attrIter = inPTree->getAttributes(); ForEach(*attrIter) { const char* propName = attrIter->queryName(); if (!(*propName)) continue; pCfg->setProp(propName, attrIter->queryValue()); } // add Tasks to params Owned<IPropertyTreeIterator> taskIter = inPTree->getElements("Task"); ForEach(*taskIter) { IPropertyTree* task = &taskIter->query(); StringBuffer sb; toXML(task, sb); pCfg->addPropTree("Task", createPTreeFromXMLString(sb.str())); } }
void CConfigHelper::appendBuildSetFromPlugins() { const char *pMask = "*"; StringBuffer strPath(this->m_strConfigXMLDir); strPath.append(STANDARD_CONFIG_CONFIGXML_DIR).append(STANDARD_CONFIG_PLUGIN_DIR_NAME); if (this->m_cbDeployment.get() != NULL) { this->m_cbDeployment->printStatus(STATUS_NORMAL, NULL, NULL, NULL, "Appending plugins to buildset %s", this->m_strBuildSetFilePath.str()); } Owned<IFile> pluginRootDir = createIFile(strPath.str()); if (checkFileExists(strPath.str()) == false) { if (m_cbDeployment.get() != NULL) { m_cbDeployment->printStatus(STATUS_WARN, NULL, NULL, NULL, "Could not find plugin directory at %s", strPath.str()); } return; } Owned<IDirectoryIterator> pluginFiles = pluginRootDir->directoryFiles(pMask, false, true); ForEach(*pluginFiles) { if (pluginFiles->query().isDirectory() == foundYes) { StringBuffer strPluginBuildSetPath; strPluginBuildSetPath.append(pluginFiles->query().queryFilename()).append("/").append(STANDARD_CONFIG_BUILDSETFILE); if (checkFileExists(strPluginBuildSetPath.str()) == true) { StringBuffer strXPath; strXPath.appendf("./%s/%s/%s", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET); Owned<IPropertyTree> pPluginBuildSet = createPTreeFromXMLFile(strPluginBuildSetPath.str()); if (m_cbDeployment.get() != NULL) { m_cbDeployment->printStatus(STATUS_NORMAL, NULL, NULL, NULL, "Loading plugin BuildSet from %s", strPluginBuildSetPath.str()); } Owned<IPropertyTreeIterator> pBuildSetIterator = pPluginBuildSet->getElements(strXPath); ForEach(*pBuildSetIterator) { int nIdx = 1; try { m_pDefBldSet->addPropTree(strXPath.str(), LINK(&(pBuildSetIterator->query()))); nIdx++; } catch (IPTreeException *e) { if (m_cbDeployment.get() != NULL) { m_cbDeployment->printStatus(STATUS_ERROR, NULL, NULL, NULL, "Error adding buildset with xpath %s[%d] from location %s", strXPath.str(), nIdx, strPluginBuildSetPath.str()); } delete e; } } } else { if (m_cbDeployment != NULL)
int init_main(int argc, char* argv[]) { InitModuleObjects(); Owned<IProperties> inputs = createProperties(true); bool interactive = false; for (int i = 1; i < argc; i++) { if (stricmp(argv[i], "-?")==0 || stricmp(argv[i], "-h")==0 || stricmp(argv[i], "-help")==0 || stricmp(argv[i], "/?")==0 || stricmp(argv[i], "/h")==0) usage(); else if(stricmp(argv[i], "interactive") == 0) interactive = true; else if (strchr(argv[i],'=')) { inputs->loadProp(argv[i]); } else { fprintf(stderr, "Unknown option: %s", argv[i]); return 0; } } int result = -1; #ifdef _WIN32 if (!interactive) ::SetErrorMode(SEM_NOGPFAULTERRORBOX|SEM_FAILCRITICALERRORS); #endif SET_ESP_SIGNAL_HANDLER(SIGPIPE, brokenpipe_handler); bool SEHMappingEnabled = false; CEspAbortHandler abortHandler; Owned<IFile> sentinelFile = createSentinelTarget(); removeSentinelFile(sentinelFile); Owned<CEspConfig> config; Owned<CEspServer> server; try { const char* cfgfile = NULL; const char* procname = NULL; if(inputs.get()) { if(inputs->hasProp("config")) cfgfile = inputs->queryProp("config"); if(inputs->hasProp("process")) procname = inputs->queryProp("process"); } if(!cfgfile || !*cfgfile) cfgfile = "esp.xml"; Owned<IPropertyTree> envpt= createPTreeFromXMLFile(cfgfile, ipt_caseInsensitive); Owned<IPropertyTree> procpt = NULL; if (envpt) { envpt->addProp("@config", cfgfile); StringBuffer xpath; if (procname==NULL || strcmp(procname, ".")==0) xpath.appendf("Software/EspProcess[1]"); else xpath.appendf("Software/EspProcess[@name=\"%s\"]", procname); DBGLOG("Using ESP configuration section [%s]", xpath.str()); procpt.set(envpt->queryPropTree(xpath.str())); if (!procpt) throw MakeStringException(-1, "Config section [%s] not found", xpath.str()); } else throw MakeStringException(-1, "Failed to load config file %s", cfgfile); StringBuffer logdir; if(procpt->hasProp("@name")) { StringBuffer espNameStr; procpt->getProp("@name", espNameStr); if (!getConfigurationDirectory(envpt->queryPropTree("Software/Directories"), "log", "esp", espNameStr.str(), logdir)) { logdir.clear(); } } const char* build_ver = BUILD_TAG; setBuildVersion(build_ver); const char* build_level = BUILD_LEVEL; setBuildLevel(build_level); if(logdir.length() == 0) { if(procpt->hasProp("@logDir")) procpt->getProp("@logDir", logdir); } if(logdir.length() == 0) logdir.append("."); if(stricmp(logdir.str(), ".") != 0) { recursiveCreateDirectory(logdir.str()); } if(logdir.charAt(logdir.length() - 1) != PATHSEPCHAR) logdir.append(PATHSEPCHAR); openEspLogFile(logdir.str(), procpt.get()); StringBuffer componentfilesDir; if(procpt->hasProp("@componentfilesDir")) procpt->getProp("@componentfilesDir", componentfilesDir); if(componentfilesDir.length() > 0 && strcmp(componentfilesDir.str(), ".") != 0) { DBGLOG("componentfiles are under %s", componentfilesDir.str()); setCFD(componentfilesDir.str()); } StringBuffer sehsetting; procpt->getProp("@enableSEHMapping", sehsetting); if(!interactive && sehsetting.length() > 0 && (stricmp(sehsetting.str(), "true") == 0 || stricmp(sehsetting.str(), "1") == 0)) SEHMappingEnabled = true; if(SEHMappingEnabled) EnableSEHtoExceptionMapping(); CEspConfig* cfg = new CEspConfig(inputs.getLink(), envpt.getLink(), procpt.getLink(), false); if(cfg && cfg->isValid()) { config.setown(cfg); abortHandler.setConfig(cfg); } } catch(IException* e) { StringBuffer description; ERRLOG("ESP Unhandled IException (%d -- %s)", e->errorCode(), e->errorMessage(description).str()); e->Release(); return -1; } catch (...) { ERRLOG("ESP Unhandled General Exception."); return -1; } if (config && config->isValid()) { PROGLOG("Configuring Esp Platform..."); try { CEspServer *srv = new CEspServer(config); if(SEHMappingEnabled) srv->setSavedSEHHandler(SEHMappingEnabled); server.setown(srv); abortHandler.setServer(srv); setEspContainer(server.get()); config->loadAll(); config->bindServer(*server.get(), *server.get()); } catch(IException* e) { StringBuffer description; ERRLOG("ESP Unhandled IException (%d -- %s)", e->errorCode(), e->errorMessage(description).str()); e->Release(); return -1; } catch (...) { ERRLOG("ESP Unhandled General Exception."); return -1; } writeSentinelFile(sentinelFile); result = work_main(*config, *server.get()); } else { ERRLOG("!!! Unable to load ESP configuration."); } return result; }
void CEclAgentExecutionServer::start(StringBuffer & codeDir) { if (started) { WARNLOG("START called when already started\n"); assert(false); } codeDirectory = codeDir; StringBuffer propertyFile = codeDirectory; addPathSepChar(propertyFile); propertyFile.append("agentexec.xml"); Owned<IPropertyTree> properties; try { DBGLOG("AgentExec: Loading properties file '%s'\n", propertyFile.str()); properties.setown(createPTreeFromXMLFile(propertyFile.str())); } catch (IException *e) { EXCLOG(e, "Error processing properties file\n"); throwUnexpected(); } // get the logfile specification properties->getProp("@logDir", logDir.clear()); if (!logDir.length()) { WARNLOG("logDir not specified in properties file - assuming code dir\n"); logDir.append(codeDir); //default to code dir addPathSepChar(logDir); logDir.append("logs"); //default folder name } recursiveCreateDirectory(logDir.str()); addPathSepChar(logDir); rebuildLogfileName(); //get name of workunit job queue StringBuffer sb; properties->getProp("@name", sb.clear()); agentName.set(sb); if (!agentName.length()) { ERRLOG("'name' not specified in properties file\n"); throwUnexpected(); } //get dali server(s) properties->getProp("@daliServers", daliServers); if (!daliServers.length()) { ERRLOG("'daliServers' not specified in properties file\n"); throwUnexpected(); } started = true; Thread::start(); Thread::join(); }
int main(int argc, char* argv[]) { InitModuleObjects(); EnableSEHtoExceptionMapping(); if (argc<2) { usage(argv[0]); return -1; } bool forceGroupUpdate = false; StringBuffer filename; StringBuffer inst; StringBuffer dcat; StringBuffer dcomp; StringBuffer dinst; StringBuffer dip; for (int i=1;i<argc;i++) { if (argv[i][0]=='-') { if ((stricmp(argv[i],"-i")==0)&&(i+1<argc)) { inst.append(argv[++i]); } else if (0==stricmp(argv[i],"-f")) { forceGroupUpdate = true; } else if ((stricmp(argv[i],"-d")==0)&&(i+3<argc)) { dcat.append(argv[++i]); dcomp.append(argv[++i]); dinst.append(argv[++i]); } else if ((stricmp(argv[i],"-ip")==0)&&(i+1<argc)) { dip.append(argv[++i]); } else { usage(argv[0]); return -1; } } else { if (filename.length()) { usage(argv[0]); return -1; } filename.append(argv[i]); } } Owned<IPropertyTree> env; try { env.setown(createPTreeFromXMLFile(argv[1])); if (!env.get()) { fprintf(stderr,"Could not load Environment from %s\n",argv[1]); return 1; } const char *s = env->queryName(); if (!s||(strcmp(s,"Environment")!=0)) { fprintf(stderr,"File %s is invalid\n",argv[1]); return 1; } } catch (IException *e) { StringBuffer err; e->errorMessage(err); fprintf(stderr,"Could not load Environment from %s, %s\n",argv[1],err.str()); return 1; } int ret = 0; try { if (dcat.length()) { IPropertyTree* dirs = env->queryPropTree("Software/Directories"); StringBuffer dirout; if (getConfigurationDirectory(dirs,dcat.str(),dcomp.str(),dinst.str(),dirout)&&dirout.length()) { if (dip.length()) { SocketEndpoint ep(dip.str()); RemoteFilename rfn; rfn.setPath(ep,dirout.str()); rfn.getRemotePath(dirout.clear()); } printf("%s",dirout.str()); } else { ret = 1; } } else { if (!updateDaliEnv(env, forceGroupUpdate, inst.str())) ret = 1; } } catch (IException *e) { pexception("updtdalienv",e); e->Release(); ret = 1; } releaseAtoms(); return ret; }
int main(int argc, char** argv) { InitModuleObjects(); const char* out_envname = NULL; const char* in_ipfilename; StringBuffer ipAddrs; int roxieNodes=0, thorNodes=0, slavesPerNode=1; MapStringTo<StringBuffer> dirMap; int i = 1; bool writeToFiles = false; int port = 80; while(i<argc) { if(stricmp(argv[i], "-help") == 0 || stricmp(argv[i], "-?") == 0) { usage(); releaseAtoms(); return 0; } else if (stricmp(argv[i], "-env") == 0) { i++; out_envname = argv[i++]; } else if (stricmp(argv[i], "-roxienodes") == 0) { i++; roxieNodes = atoi(argv[i++]); } else if (stricmp(argv[i], "-thornodes") == 0) { i++; thorNodes = atoi(argv[i++]); } else if (stricmp(argv[i], "-slavespernode") == 0) { i++; slavesPerNode = atoi(argv[i++]); } else if (stricmp(argv[i], "-ip") == 0) { i++; ipAddrs.append(argv[i++]); } else if(stricmp(argv[i], "-ipfile") == 0) { i++; in_ipfilename = argv[i++]; ipAddrs.loadFile(in_ipfilename); } else if(stricmp(argv[i], "-o") == 0) { i++; StringArray sbarr; DelimToStringArray(argv[i++], sbarr, "="); if (sbarr.length() != 2) continue; if (strstr(sbarr.item(1), "[NAME]") && (strstr(sbarr.item(1), "[INST]") || strstr(sbarr.item(1), "[COMPONENT]"))) dirMap.setValue(sbarr.item(0), sbarr.item(1)); else { fprintf(stderr, "Error: Directory Override must contain [NAME] and either [INST] or [COMPONENT]\n"); releaseAtoms(); return 1; } } else { fprintf(stderr, "Error: unknown command line parameter: %s\n", argv[i]); usage(); releaseAtoms(); return 1; } } if (!out_envname) { fprintf(stderr, "Error: Output environment xml file is required. Please specify.\n"); usage(); releaseAtoms(); return 1; } if (ipAddrs.length() == 0) { fprintf(stderr, "Error: Ip addresses are required. Please specify.\n"); usage(); releaseAtoms(); return 1; } try { validateIPS(ipAddrs.str()); StringBuffer optionsXml, envXml; const char* pServiceName = "WsDeploy_wsdeploy_esp"; Owned<IPropertyTree> pCfg = createPTreeFromXMLFile(ENVGEN_PATH_TO_ESP_CONFIG); optionsXml.appendf("<XmlArgs roxieNodes=\"%d\" thorNodes=\"%d\" slavesPerNode=\"%d\" ipList=\"%s\"/>", roxieNodes, thorNodes, slavesPerNode, ipAddrs.str()); buildEnvFromWizard(optionsXml, pServiceName, pCfg, envXml, &dirMap); if(envXml.length()) { StringBuffer env; StringBuffer thisip; queryHostIP().getIpText(thisip); env.appendf("<"XML_HEADER">\n<!-- Generated with envgen on ip %s -->\n", thisip.str()); env.append(envXml); Owned<IEnvironmentFactory> factory = getEnvironmentFactory(); Owned<IConstEnvironment> constEnv = factory->loadLocalEnvironment(env); validateEnv(constEnv); Owned<IFile> pFile; pFile.setown(createIFile(out_envname)); Owned<IFileIO> pFileIO; pFileIO.setown(pFile->open(IFOcreaterw)); pFileIO->write(0, env.length(), env.str()); } } catch(IException *excpt) { StringBuffer errMsg; fprintf(stderr, "Exception: %d:\n%s\n", excpt->errorCode(), excpt->errorMessage(errMsg).str()); releaseAtoms(); excpt->Release(); return 1; } catch(...) { fprintf(stderr, "Unknown exception\n"); releaseAtoms(); return 1; } releaseAtoms(); return 0; }
void ResourceManager::addManifestFile(const char *filename) { Owned<IPropertyTree> manifestSrc = createPTreeFromXMLFile(filename); StringBuffer dir; splitDirTail(filename, dir); ensureManifestInfo(); Owned<IAttributeIterator> aiter = manifestSrc->getAttributes(); ForEach (*aiter) manifest->setProp(aiter->queryName(), aiter->queryValue()); Owned<IPropertyTreeIterator> iter = manifestSrc->getElements("*"); ForEach(*iter) { IPropertyTree &item = iter->query(); if (streq(item.queryName(), "Include") && item.hasProp("@filename")) addManifestInclude(item, dir.str()); else if (streq(item.queryName(), "Resource") && item.hasProp("@filename")) { StringBuffer filepath; StringBuffer respath; makeAbsolutePath(item.queryProp("@filename"), dir.str(), filepath); makePathUniversal(filepath.str(), respath); item.setProp("@originalFilename", filepath.str()); item.setProp("@resourcePath", respath.str()); if (containsFileWildcard(filepath)) { StringBuffer wildpath; const char *tail = splitDirTail(filepath, wildpath); expandManifestDirectory(manifestSrc, item, dir, wildpath, tail, item.getPropBool("@recursive")); manifestSrc->removeTree(&item); } } else manifest->addPropTree(item.queryName(), LINK(&item)); } Owned<IPropertyTreeIterator> resources = manifestSrc->getElements("Resource[@filename]"); ForEach(*resources) { IPropertyTree &item = resources->query(); if (!item.hasProp("@type")) item.setProp("@type", "UNKNOWN"); int id; if (getDuplicateResourceId(item.queryProp("@type"), item.queryProp("@resourcePath"), NULL, id)) { item.setPropInt("@id", id); manifest->addPropTree("Resource", LINK(&item)); } else { MemoryBuffer content; loadResource(item.queryProp("@originalFilename"), content); addCompress(item.queryProp("@type"), content.length(), content.toByteArray(), &item); } } }
//----------------------------------------------------------------------- // SetEnvironment //----------------------------------------------------------------------- void CWizardInputs::setEnvironment() { StringBuffer xpath; if(m_pXml->hasProp("@ipList")) formIPList(m_pXml->queryProp("@ipList"), m_ipaddress); if(m_pXml->hasProp("@supportNodes")) { m_supportNodes = atoi(m_pXml->queryProp("@supportNodes")); if (m_supportNodes) { if (m_ipaddress.length() > 0 && m_ipaddress.length() > m_supportNodes) { for(unsigned i = 0; i < m_supportNodes; i++) m_ipaddressSupport.append(m_ipaddress.item(i)); m_ipaddress.removen(0, m_supportNodes); } else m_supportNodes = 0; } } if(m_pXml->hasProp("@roxieNodes")) m_roxieNodes = atoi(m_pXml->queryProp("@roxieNodes")); if(m_pXml->hasProp("@thorNodes")) m_thorNodes = atoi(m_pXml->queryProp("@thorNodes")); if(m_pXml->hasProp("@dbuser")) m_dbuser = m_pXml->queryProp("@dbuser"); if(m_pXml->hasProp("@dbpassword")) m_dbpassword = m_pXml->queryProp("@dbpassword"); m_thorSlavesPerNode = 1; if(m_pXml->hasProp("@slavesPerNode")) m_thorSlavesPerNode = atoi( m_pXml->queryProp("@slavesPerNode")); if (m_thorSlavesPerNode < 1) m_thorSlavesPerNode = 1; m_roxieOnDemand = m_pXml->getPropBool("@roxieOnDemand", true); xpath.clear().appendf("Software/EspProcess/EspService[@name='%s']/LocalConfFile", m_service.str()); const char* pConfFile = m_cfg->queryProp(xpath.str()); xpath.clear().appendf("Software/EspProcess/EspService[@name='%s']/LocalEnvConfFile", m_service.str()); const char* pEnvConfFile = m_cfg->queryProp(xpath.str()); if (pConfFile && *pConfFile && pEnvConfFile && *pEnvConfFile) { Owned<IProperties> pParams = createProperties(pConfFile); Owned<IProperties> pEnvParams = createProperties(pEnvConfFile); StringBuffer sb, fileName; fileName.append((pEnvParams->queryProp("path")!= NULL ? (sb.clear().append(pEnvParams->queryProp("path")).append("/componentfiles/configxml/")) : STANDARD_CONFIGXMLDIR)); fileName.append((pParams->queryProp("buildset") != NULL ? (sb.clear().append(pParams->queryProp("buildset"))) : STANDARD_CONFIG_BUILDSETFILE)); if(fileName.length() && checkFileExists(fileName.str())) m_buildSetTree.setown(createPTreeFromXMLFile(fileName.str())); else throw MakeStringException( -1 , "The buildSetFile %s does not exists", fileName.str()); fileName.clear().append((pEnvParams->queryProp("configs") != NULL ? (sb.clear().append(pEnvParams->queryProp("configs")).append("/")): STANDARD_CONFIG_DIR)); fileName.append((pParams->queryProp("wizardalgorithm") != NULL ? (sb.clear().append(pParams->queryProp("wizardalgorithm"))) : STANDARD_CONFIG_ALGORITHMFILE)); if(fileName.length() && checkFileExists(fileName.str())) m_algProp.setown(createProperties(fileName.str())); else throw MakeStringException( -1 , "The algorithm file %s does not exists", fileName.str()); } setWizardRules(); setTopologyParam(); }
int main(int argc, char* argv[]) { InitModuleObjects(); InstanceType itype = IT_UNKNOWN; int times = 1; int threads = 1; StringBuffer in_fname; StringBuffer out_fname; StringBuffer host; int port = 80; int localport = 80; bool use_ssl = false; bool add_soap_headers = false; StringBuffer scfname; StringBuffer url; const char* soapaction = NULL; int delay = 0; int recvDelay = 0, sendDelay = 0, blockDelay = 0; int i = 1; while(i<argc) { if (stricmp(argv[i], "-s")==0) { itype = HTTPSERVER; i++; } else if (stricmp(argv[i], "-c")==0) { itype = HTTPCLIENT; i++; } else if (stricmp(argv[i], "-x")==0) { itype = HTTPPROXY; i++; } else if (stricmp(argv[i],"-r")==0) { i++; times = atoi(argv[i++]); } else if (stricmp(argv[i],"-t")==0) { i++; threads = atoi(argv[i++]); } else if (stricmp(argv[i], "-h")==0) { i++; host.clear().append(argv[i++]); } else if (stricmp(argv[i], "-p")==0) { i++; port = atoi(argv[i++]); } else if (stricmp(argv[i], "-i") == 0) { i++; in_fname.clear().append(argv[i++]); } else if (stricmp(argv[i], "-o") == 0) { i++; out_fname.clear().append(argv[i++]); } else if (stricmp(argv[i], "-ssl") == 0) { use_ssl = true; i++; } else if (stricmp(argv[i], "-sc") == 0) { i++; scfname.clear().append(argv[i++]); } else if (stricmp(argv[i], "-lp") == 0) { i++; localport = atoi(argv[i++]); } else if (stricmp(argv[i], "-delay") == 0) { i++; delay = atoi(argv[i++]); } else if (stricmp(argv[i], "-dr") == 0) { i++; recvDelay = atoi(argv[i++]); } else if (stricmp(argv[i], "-ds") == 0) { i++; sendDelay = atoi(argv[i++]); } else if (stricmp(argv[i], "-dc") == 0) { i++; blockDelay = atoi(argv[i++]); } else if(stricmp(argv[i], "-url") == 0) { i++; url.append(argv[i++]); } else if (stricmp(argv[i], "-soap")==0) { add_soap_headers = true; i++; } else if (stricmp(argv[i], "-action")==0) { i++; soapaction = argv[i++]; } else if (stricmp(argv[i], "-d")==0) { i++; httptest_tracelevel = atoi(argv[i++]);; } else { printf("Error: command format error\n"); usage(); } } try { Owned<IPropertyTree> sslconfig; if(scfname.length() > 0) sslconfig.setown(createPTreeFromXMLFile(scfname.str(), ipt_caseInsensitive)); FILE* ofile = NULL; if(out_fname.length() != 0) { ofile = fopen(out_fname.str(), "a+"); if(ofile == NULL) { printf("can't open file %s\n", out_fname.str()); exit(-1); } } else { ofile = stdout; } if(itype == HTTPSERVER) { HttpServer server(port, in_fname.str(), ofile, use_ssl, sslconfig.get()); server.setDelays(recvDelay, sendDelay, blockDelay); server.start(); } else if(itype == HTTPPROXY) { HttpProxy proxy(localport, host.str(), port, ofile, use_ssl, sslconfig.get()); proxy.start(); } else { if(add_soap_headers && url.length() == 0) { printf("Error: when you use -soap option, you must provide the full url\ntype in \"%s -h\" for usage", argv[0]); return 0; } if(host.length() == 0 && url.length() == 0) { printf("Error: destination host or url required\n"); usage(); } if(add_soap_headers) { HttpClient client(threads, times, ofile); if(delay > 0) client.setDelay(delay); client.sendSoapRequest(url.str(), soapaction, in_fname.str()); } else if(url.length() == 0) { HttpClient client(threads, times, host.str(), port, ofile, use_ssl, sslconfig.get()); if(delay > 0) client.setDelay(delay); client.sendRequest(in_fname.str()); } else { HttpClient client(threads, times, ofile); if(delay > 0) client.setDelay(delay); client.getUrl(url.str()); } } fclose(ofile); } catch(IException *excpt) { StringBuffer errMsg; DBGLOG("Error - %d:%s", excpt->errorCode(), excpt->errorMessage(errMsg).str()); return -1; } catch(...) { DBGLOG("Unknown exception"); return -1; } releaseAtoms(); return 0; }
//--------------------------------------------------------------------------- // determineInstallFiles //--------------------------------------------------------------------------- int CConfigGenEngine::determineInstallFiles(IPropertyTree& processNode, CInstallFiles& installFiles) const { try { m_pCallback->printStatus(STATUS_NORMAL, NULL, NULL, NULL, "Determining files to install for %s", processNode.queryProp("@name")); StringBuffer compListPath(CONFIGGEN_COMP_LIST); if (m_inDir.length()) compListPath.clear().append(m_inDir).append(PATHSEPCHAR).append(CONFIGGEN_COMP_LIST); Owned<IPropertyTree> deployNode = createPTreeFromXMLFile(compListPath.str(), ipt_caseInsensitive); StringBuffer srcFilePath; srcFilePath.ensureCapacity(_MAX_PATH); const bool bFindStartable = &m_process == &processNode && m_startable == unknown; const bool bFindStoppable = &m_process == &processNode && m_stoppable == unknown; StringBuffer xpath; xpath.appendf("Component[@name=\"%s\"]",processNode.queryProp("@buildSet")); IPropertyTree* pComponent = deployNode->queryPropTree(xpath.str()); if (!pComponent) { m_pCallback->printStatus(STATUS_NORMAL, NULL, NULL, NULL, "Cannot find files to install for %s", processNode.queryProp("@buildSet")); return 0; } Owned<IPropertyTreeIterator> iter = pComponent->getElements("File"); ForEach(*iter) { IPropertyTree* pFile = &iter->query(); const char* name = pFile->queryProp("@name"); if (!stricmp(name, "deploy_map.xml")) continue; if (bFindStartable && !strnicmp(name, "startup", sizeof("startup")-1)) m_startable = yes; if (bFindStoppable && !strnicmp(name, "stop", sizeof("stop")-1)) m_stoppable = yes; const char* method = pFile->queryProp("@method"); if (method && !stricmp(method, "schema")) continue; //if we are not deploying build files and method is copy then ignore this file if (!(m_deployFlags & DEFLAGS_BUILDFILES) && (!method || !stricmp(method, "copy"))) continue; const char* srcPath = pFile->queryProp("@srcPath"); const char* destPath= pFile->queryProp("@destPath"); const char* destName= pFile->queryProp("@destName"); bool bCacheable = pFile->getPropBool("@cache", false); // Get source filespec if (srcPath && !strcmp(srcPath, "@temp")) { char tempfile[_MAX_PATH]; getTempPath(tempfile, sizeof(tempfile), m_name); srcFilePath.clear().append(tempfile).append(name); } else { srcFilePath.clear().append(m_inDir); //adjust source paths if (srcPath && 0!=strcmp(srcPath, ".")) { if (!strncmp(srcPath, "..", 2) && (*(srcPath+2)=='/' || *(srcPath+2)=='\\')) { StringBuffer reldir(srcPath); reldir.replace('/', '\\'); while (!strncmp(reldir.str(), "..\\", 3)) { srcFilePath.setLength( srcFilePath.length() - 1 ); //remove last char PATHSEPCHAR const char* tail = pathTail(srcFilePath.str()); srcFilePath.setLength( tail - srcFilePath.str() ); reldir.remove(0, 3); } srcFilePath.append(reldir).append(PATHSEPCHAR); } else srcFilePath.append(srcPath).append(PATHSEPCHAR); } srcFilePath.append(name); } std::string sDestName; if (method && (!stricmp(method, "esp_service_module") || !stricmp(method, "esp_plugin"))) { //if this is xsl transformation and we are not generating config files then ignore // if (!(m_deployFlags & DEFLAGS_CONFIGFILES) && !stricmp(method, "esp_service_module")) continue; //if this file is an esp service module, encode name of service in the dest file name //so the esp deployment can figure out which service this file belongs to // const char* serviceName = processNode.queryProp("@name"); //if destination name is specified then use it otherwise use <service-name>[index of module].xml sDestName = serviceName; if (destName) { sDestName += '_'; sDestName += destName; } else { int espServiceModules = m_envDepEngine.incrementEspModuleCount(); if (espServiceModules > 1) { char achNum[16]; itoa(espServiceModules, achNum, 10); sDestName += achNum; } sDestName += ".xml"; } //encode name of service herein - this is needed by and removed by CEspDeploymentEngine::processServiceModules() sDestName += '+'; sDestName += processNode.queryProp("@name");//encode the name of service } else if (method && (!stricmp(method, "xsl") || !stricmp(method, "xslt")) && !(m_deployFlags & DEFLAGS_CONFIGFILES)) continue;//ignore xsl transformations if we are not generating config files else { if (!method || !*method) method = "copy"; // Get destination filespec if (destName && *destName) { //we now support attribute names within the destination file names like delimted by @ and + (optional) //for e.g. segment_@attrib1+_file_@attrib2 would produce segment_attribval1_file_attrib2value //+ not necessary if the attribute name ends with the word, for e.g. file_@attrib1 //for instnace, suite_@eclServer+.bat would expand to suite_myeclserver.bat //if this process has an @eclServer with value "myeclserver" // if (strchr(destName, '@') || strchr(destName, '+')) { char* pszParts = strdup(destName); char *saveptr; const char* pszPart = strtok_r(pszParts, "+", &saveptr); while (pszPart) { const char* p = pszPart; if (*p) { if (strchr(p, '@'))//xpath for an attribute? { // find name of attribute and replace it with its value const char* value = m_process.queryProp( p ); if (value) sDestName.append(value); } else sDestName.append(p); //no attribute so copy verbatim } pszPart = strtok_r(NULL, "+", &saveptr); } free(pszParts); } else sDestName = destName; if (sDestName.empty()) throw MakeStringException(-1, "The destination file name '%s' for source file '%s' " "translates to an empty string!", destName, name); } } StringBuffer destFilePath; destFilePath.ensureCapacity(_MAX_PATH); bool bTempFile = (destPath && !stricmp(destPath, "@temp")) || !strnicmp(name, "@temp", 5); //@name starts with @temp or @tmp if (bTempFile) { if (sDestName.empty())//dest name not specified { if (!strcmp(method, "copy")) sDestName = name; else { StringBuffer dir; const char* pszFileName = splitDirTail(name, dir); const char* pExt = findFileExtension(pszFileName); if (pExt) sDestName.append(pszFileName, pExt-pszFileName); else sDestName.append(pszFileName); char index[16]; itoa(m_envDepEngine.incrementTempFileCount(), index, 10); sDestName.append(index); if (pExt) sDestName.append(pExt); } } destFilePath.append("@temp" PATHSEPSTR); } else { if (destPath && *destPath) { destFilePath.append(destPath); if (destPath[strlen(destPath)-1] != PATHSEPCHAR) destFilePath.append(PATHSEPCHAR); } if (sDestName.empty()) sDestName = name; } if (!bTempFile) destFilePath.append(processNode.queryProp("@name")).append(PATHSEPCHAR); destFilePath.append(sDestName.c_str()); //For oss, plugins to be handled globally, per Richard. //esp plugins also end with plugins.xml but they should be handled above. String destFilePathStr(destFilePath); String* tmpstr = destFilePathStr.toLowerCase(); if (tmpstr->indexOf("plugins.xml") > 0) { delete tmpstr; createFakePlugins(destFilePath); continue; } delete tmpstr; //find all occurrences of this destination file in the map and resove any conflicts //like size mismatch etc. bool bAddToFileMap = installFiles.resolveConflicts(processNode, method, srcFilePath.str(), destFilePath.str(), m_name, m_curInstance, NULL); //resolve conflicts if method is not schema or exec if (0 != stricmp(method, "schema") && 0 != stricmp(method, "exec") && 0 != strnicmp(method, "del", 3)) { } else if (!strnicmp(method, "del", 3))//treat files to be deleted as temp files - to be deleted AFTER we are done! { bTempFile = true; bAddToFileMap = false; m_envDepEngine.addTempFile(destFilePath.str()); } if (bAddToFileMap) { if (bTempFile) m_envDepEngine.addTempFile(destFilePath.str()); //enable caching for files to be copied unless expressly asked not to do so // if (!bCacheable && !strcmp(method, "copy")) bCacheable = pFile->getPropBool("@cache", true); installFiles.addInstallFile(method, srcFilePath.str(), destFilePath.str(), bCacheable, NULL); } } } catch (IException* e) { StringBuffer msg; e->errorMessage(msg); e->Release(); throw MakeStringException(0, "Error creating file list for process %s: %s", m_name.get(), msg.str()); } catch (...) { throw MakeErrnoException("Error creating file list for process %s", m_name.get()); } m_pCallback->printStatus(STATUS_NORMAL, NULL, NULL, NULL, NULL); return installFiles.getInstallFileList().size(); }
int main(int argc, const char *argv[]) { InitModuleObjects(); EnableSEHtoExceptionMapping(); NoQuickEditSection xxx; Owned<IFile> file = createIFile("dfuserver.xml"); if (file->exists()) globals.setown(createPTreeFromXMLFile("dfuserver.xml", ipt_caseInsensitive)); else globals.setown(readOldIni()); for (unsigned i=1;i<(unsigned)argc;i++) { const char *arg = argv[i]; StringBuffer prop("@"); StringBuffer val; while (*arg && *arg != '=') prop.append(*arg++); if (*arg) { arg++; while (isspace(*arg)) arg++; val.append(arg); prop.clip(); val.clip(); if (prop.length()>1) globals->setProp(prop.str(), val.str()); } } StringBuffer daliServer; StringBuffer queue; if (!globals->getProp("@DALISERVERS", daliServer)||!globals->getProp("@QUEUE", queue)) { usage(); globals.clear(); releaseAtoms(); return 1; } Owned<IFile> sentinelFile; bool stop = globals->getPropInt("@STOP",0)!=0; if (!stop) { sentinelFile.setown(createSentinelTarget()); removeSentinelFile(sentinelFile); StringBuffer logname; StringBuffer logdir; if (!getConfigurationDirectory(globals->queryPropTree("Directories"),"log","dfuserver",globals->queryProp("@name"),logdir)) globals->getProp("@LOG_DIR", logdir); if (logdir.length() && recursiveCreateDirectory(logdir.str())) logname.append(logdir); else appendCurrentDirectory(logname, true); if (logname.length() && logname.charAt(logname.length()-1) != PATHSEPCHAR) logname.append(PATHSEPCHAR); logname.append("dfuserver"); StringBuffer aliasLogName(logname); aliasLogName.append(".log"); fileMsgHandler = getRollingFileLogMsgHandler(logname.str(), ".log", MSGFIELD_STANDARD, false, true, NULL, aliasLogName.str()); queryLogMsgManager()->addMonitorOwn(fileMsgHandler, getCategoryLogMsgFilter(MSGAUD_all, MSGCLS_all, 1000)); } StringBuffer ftslogdir; if (getConfigurationDirectory(globals->queryPropTree("Directories"),"log","ftslave",globals->queryProp("@name"),ftslogdir)) // NB instance deliberately dfuserver's setFtSlaveLogDir(ftslogdir.str()); setRemoteSpawnSSH( globals->queryProp("SSH/@SSHidentityfile"), globals->queryProp("SSH/@SSHusername"), globals->queryProp("SSH/@SSHpassword"), globals->getPropInt("SSH/@SSHtimeout",0), globals->getPropInt("SSH/@SSHretries",3), "run_"); bool enableSNMP = globals->getPropInt("@enableSNMP")!=0; CSDSServerStatus *serverstatus=NULL; Owned<IReplicateServer> replserver; try { Owned<IGroup> serverGroup = createIGroup(daliServer.str(),DALI_SERVER_PORT); initClientProcess(serverGroup, DCR_DfuServer, 0, NULL, NULL, stop?(1000*30):MP_WAIT_FOREVER); setPasswordsFromSDS(); if(!stop) { if (globals->getPropBool("@enableSysLog",true)) UseSysLogForOperatorMessages(); serverstatus = new CSDSServerStatus("DFUserver"); setDaliServixSocketCaching(true); // speeds up lixux operations startLogMsgParentReceiver(); // for auditing connectLogMsgManagerToDali(); engine.setown(createDFUengine()); addAbortHandler(exitDFUserver); } const char *q = queue.str(); loop { StringBuffer subq; const char *comma = strchr(q,','); if (comma) subq.append(comma-q,q); else subq.append(q); if (stop) { stopDFUserver(subq.str()); } else { StringBuffer mask; mask.appendf("Queue[@name=\"%s\"][1]",subq.str()); IPropertyTree *t=serverstatus->queryProperties()->queryPropTree(mask.str()); if (t) t->setPropInt("@num",t->getPropInt("@num",0)+1); else { t = createPTree(); t->setProp("@name",subq.str()); t->setPropInt("@num",1); serverstatus->queryProperties()->addPropTree("Queue",t); } serverstatus->commitProperties(); engine->setDefaultTransferBufferSize((size32_t)globals->getPropInt("@transferBufferSize")); engine->startListener(subq.str(),serverstatus); } if (!comma) break; q = comma+1; if (!*q) break; } q = globals->queryProp("@MONITORQUEUE"); if (q&&*q) { if (stop) { stopDFUserver(q); } else { IPropertyTree *t=serverstatus->queryProperties()->addPropTree("MonitorQueue",createPTree()); t->setProp("@name",q); engine->startMonitor(q,serverstatus,globals->getPropInt("@MONITORINTERVAL",60)*1000); } } q = globals->queryProp("@REPLICATEQUEUE"); if (q&&*q) { if (stop) { // TBD? } else { replserver.setown(createReplicateServer(q)); replserver->runServer(); } } if (!stop) { serverstatus->commitProperties(); writeSentinelFile(sentinelFile); engine->joinListeners(); if (replserver.get()) replserver->stopServer(); LOG(MCprogress, unknownJob, "Exiting"); } } catch(IException *e){ EXCLOG(e, "DFU Server Exception: "); e->Release(); } catch (const char *s) { WARNLOG("DFU: %s",s); } delete serverstatus; if (stop) Sleep(2000); // give time to stop engine.clear(); globals.clear(); closeEnvironment(); closedownClientProcess(); UseSysLogForOperatorMessages(false); setDaliServixSocketCaching(false); releaseAtoms(); return 0; }
CConfigHelper* CConfigHelper::getInstance(const IPropertyTree *cfg, const char* esp_name, IDeploymentCallback *pCallBack) { CriticalBlock block(m_critSect); static CConfigHelper *p_sConfigHelper = NULL; StringBuffer xpath1, xpath2; if (p_sConfigHelper != NULL) { return p_sConfigHelper; } p_sConfigHelper = new CConfigHelper(pCallBack); if (cfg != NULL && esp_name != NULL) { xpath1.clear().appendf("%s/%s/%s[%s='%s']/%s",XML_TAG_SOFTWARE, XML_TAG_ESPPROCESS, XML_TAG_ESPSERVICE, XML_ATTR_NAME, esp_name, XML_TAG_LOCALCONFFILE); p_sConfigHelper->m_strConfFile = cfg->queryProp(xpath1.str()); xpath2.clear().appendf("%s/%s/%s[%s='%s']/%s",XML_TAG_SOFTWARE, XML_TAG_ESPPROCESS, XML_TAG_ESPSERVICE, XML_ATTR_NAME, esp_name, XML_TAG_LOCALENVCONFFILE); p_sConfigHelper->m_strEnvConfFile = cfg->queryProp(xpath2.str()); if (p_sConfigHelper->m_strConfFile.length() > 0 && p_sConfigHelper->m_strEnvConfFile.length() > 0 && checkFileExists(p_sConfigHelper->m_strConfFile.str()) && checkFileExists(p_sConfigHelper->m_strEnvConfFile.str())) { Owned<IProperties> pParams = createProperties(p_sConfigHelper->m_strConfFile.str()); Owned<IProperties> pEnvParams = createProperties(p_sConfigHelper->m_strEnvConfFile.str()); p_sConfigHelper->m_strConfigXMLDir = pEnvParams->queryProp(TAG_PATH); if (p_sConfigHelper->m_strConfigXMLDir.length() == 0) { p_sConfigHelper->m_strConfigXMLDir = INSTALL_DIR; } p_sConfigHelper->m_strBuildSetFileName = pParams->queryProp(TAG_BUILDSET); p_sConfigHelper->m_strBuildSetFilePath.append(p_sConfigHelper->m_strConfigXMLDir).append(STANDARD_CONFIG_CONFIGXML_DIR).append( p_sConfigHelper->m_strBuildSetFileName.length() > 0 ? p_sConfigHelper->m_strBuildSetFileName : STANDARD_CONFIG_BUILDSETFILE); try { p_sConfigHelper->m_pDefBldSet.set(createPTreeFromXMLFile(p_sConfigHelper->m_strBuildSetFilePath.str())); } catch (IException *e) { if (p_sConfigHelper->m_pDefBldSet.get() != NULL) { p_sConfigHelper->m_pDefBldSet.clear(); } StringBuffer msg; e->errorMessage(msg); delete e; if (p_sConfigHelper->m_cbDeployment.get() != NULL) { p_sConfigHelper->m_cbDeployment->printStatus(STATUS_ERROR, NULL, NULL, NULL, "Failed create PTree from buildset.xml file %s with error %s", p_sConfigHelper->m_strBuildSetFilePath.str(), msg.str()); return p_sConfigHelper; } else { throw MakeStringException(-1, "Failed create PTree from buildset.xml file %s with error %s", p_sConfigHelper->m_strBuildSetFilePath.str(), msg.str()); } } try { p_sConfigHelper->appendBuildSetFromPlugins(); } catch (IException *e) { if (p_sConfigHelper->m_cbDeployment.get() != NULL) { StringBuffer msg; e->errorMessage(msg); p_sConfigHelper->m_cbDeployment->printStatus(STATUS_ERROR, NULL, NULL, NULL, "Failed to add plugin buildset.xml file %s with error %s", p_sConfigHelper->m_strBuildSetFilePath.str(), msg.str()); } // TODO: log message to configmgr log but continue execution delete e; } return p_sConfigHelper; } else { delete p_sConfigHelper; p_sConfigHelper = NULL; throw MakeStringException(-1, "Config file does not define values for %s and %s", xpath1.str(), xpath2.str()); } } return p_sConfigHelper; }
int main(int argc, char* argv[]) { if(argc < 2) { usage(); return -1; } InitModuleObjects(); const char *action = NULL, *configfile = NULL, *username = NULL, *passwd = NULL, *resource = NULL, *resourcetype = NULL, *newpasswd = NULL, *firstname = NULL, *lastname=NULL; bool stress = false; int numthrds = 0; int numrounds = 0; int numfiles = 0; int i = 1; while(i<argc) { if (stricmp(argv[i], "-ac")==0 || stricmp(argv[i], "-au") == 0 || stricmp(argv[i], "-ar") == 0|| stricmp(argv[i], "-cp") == 0) { action = argv[i++]; } else if (stricmp(argv[i], "-c")==0) { i++; configfile = argv[i++]; } else if (stricmp(argv[i],"-u")==0) { i++; username = argv[i++]; } else if (stricmp(argv[i], "-p")==0) { i++; passwd = argv[i++]; } else if (stricmp(argv[i], "-r")==0) { i++; resource = argv[i++]; } else if (stricmp(argv[i], "-t") == 0) { i++; resourcetype = argv[i++]; } else if (stricmp(argv[i], "-np") == 0) { i++; newpasswd = argv[i++]; } else if (stricmp(argv[i], "-fn") == 0) { i++; firstname = argv[i++]; } else if (stricmp(argv[i], "-ln") == 0) { i++; lastname = argv[i++]; } else if (stricmp(argv[i], "-stress") == 0) { stress = true; i++; numthrds = atoi(argv[i++]); numrounds = atoi(argv[i++]); } else if (stricmp(argv[i], "-open") == 0) { i++; numfiles = atoi(argv[i++]); } else { printf("Error: command format error\n"); usage(); return -1; } } if(configfile == NULL || *configfile == '\0') { printf("You have to specify the config file"); return -1; } try { Owned<IPropertyTree> cfg = createPTreeFromXMLFile(configfile); Owned<IPropertyTree> seccfg = cfg->getPropTree(".//ldapSecurity"); if(seccfg == NULL) { printf("ldapSecurity not found\n"); return -1; } #ifdef _NO_LDAP printf("System was built with _NO_LDAP\n"); return -1; #else Owned<ISecManager> secmgr = newLdapSecManager("test", *LINK(seccfg)); if(secmgr == NULL) { printf("security manager can't be created\n"); return -1; } if(action == NULL || stricmp(action, "-ac") == 0) { if(username == NULL || *username == '\0') { printf("missing username\n"); return -1; } if(resource == NULL || *resource == '\0') { printf("missing resource\n"); return -1; } SecResourceType rtype = RT_DEFAULT; if((resourcetype != NULL) && (stricmp(resourcetype, "filescope") == 0)) rtype = RT_FILE_SCOPE; else if((resourcetype != NULL) && (stricmp(resourcetype, "workunit") == 0)) rtype = RT_WORKUNIT_SCOPE; StringBuffer passbuf; if(passwd == NULL || *passwd == '\0') { getpassword("Enter password: "******"%s's permission = %d \n", resource, access); } else { CPermissionCheckThread** thrds = new CPermissionCheckThread*[numthrds]; for(int i = 0; i < numthrds; i++) thrds[i] = new CPermissionCheckThread(secmgr, username, passwd, resource, rtype, numrounds); for(int j = 0; j < numthrds; j++) thrds[j]->start(); for(int k = 0; k < numthrds; k++) thrds[k]->join(); } } else if(stricmp(action, "-au") == 0) { if(username == NULL || *username == '\0') { printf("missing username\n"); return -1; } Owned<ISecUser> usr = secmgr->createUser(username); if(firstname != NULL) usr->setFirstName(firstname); if(lastname != NULL) usr->setLastName(lastname); usr->credentials().setPassword(passwd); bool ok = usr?secmgr->addUser(*usr):false; if(ok) printf("user %s added\n", username); else printf("user %s not added\n", username); } else if(stricmp(action, "-ar") == 0) { if(resource == NULL || *resource == '\0') { printf("missing resource\n"); return -1; } SecResourceType rtype = RT_DEFAULT; if((resourcetype != NULL) && (stricmp(resourcetype, "filescope") == 0)) rtype = RT_FILE_SCOPE; else if((resourcetype != NULL) && (stricmp(resourcetype, "workunit") == 0)) rtype = RT_WORKUNIT_SCOPE; Owned<ISecUser> usr; if(username != NULL && *username != '\0') usr.setown(secmgr->createUser(username)); bool ok = secmgr->addResourceEx(rtype, *usr, resource, PT_ADMINISTRATORS_ONLY, NULL); if(!ok) printf("resource not added\n"); else printf("resource %s added\n", resource); } else if(stricmp(action, "-cp") == 0) { if(username == NULL || *username == '\0') { printf("missing username\n"); return -1; } StringBuffer passbuf, newpassbuf; if(passwd == NULL || *passwd == '\0') { getpassword("Enter password: "******"\nEnter new password: "******"user password changed\n"); else printf("user password not changed\n"); } #endif } catch(IException* e) { StringBuffer errmsg; e->errorMessage(errmsg); printf("%s\n", errmsg.str()); } catch(...) { printf("Unknown exception\n"); } releaseAtoms(); return 0; }