static VersionCmpResult RunCmpCommand(const char *command, const char *v1, const char *v2, Attributes a, Promise *pp) { char expanded_command[CF_EXPANDSIZE]; SetNewScope("cf_pack_context"); NewScalar("cf_pack_context", "v1", v1, cf_str); NewScalar("cf_pack_context", "v2", v2, cf_str); ExpandScalar(command, expanded_command); DeleteScope("cf_pack_context"); FILE *pfp = a.packages.package_commands_useshell ? cf_popen_sh(expanded_command, "w") : cf_popen(expanded_command, "w"); if (pfp == NULL) { cfPS(cf_error, CF_FAIL, "cf_popen", pp, a, "Can not start package version comparison command: %s", expanded_command); return VERCMP_ERROR; } CfOut(cf_verbose, "", "Executing %s", expanded_command); int retcode = cf_pclose(pfp); if (retcode == -1) { cfPS(cf_error, CF_FAIL, "cf_pclose", pp, a, "Error during package version comparison command execution: %s", expanded_command); return VERCMP_ERROR; } return retcode == 0; }
void TestVariableScan() { int i; char *list_text1 = "$(administrator),a,b,c,d,e,f"; char *list_text2 = "1,2,3,4,@(one)"; Rlist *varlist1, *varlist2, *listoflists = NULL, *scalars = NULL; static char *varstrings[] = { "alpha $(one) beta $(two) gamma", "alpha $(five) beta $(none) gamma $(array[$(four)])", "alpha $(none) beta $(two) gamma", "alpha $(four) beta $(two) gamma $(array[$(diagnostic.three)])", NULL }; printf("%d. Test variable scanning\n", ++NR); SetNewScope("diagnostic"); varlist1 = SplitStringAsRList(list_text1, ','); varlist2 = SplitStringAsRList(list_text2, ','); NewList("diagnostic", "one", varlist1, cf_slist); NewScalar("diagnostic", "two", "secondary skills", cf_str); NewScalar("diagnostic", "administrator", "root", cf_str); NewList("diagnostic", "three", varlist2, cf_slist); NewList("diagnostic", "four", varlist2, cf_slist); NewList("diagnostic", "five", varlist2, cf_slist); for (i = 0; varstrings[i] != NULL; i++) { if (VERBOSE || DEBUG) { printf("-----------------------------------------------------------\n"); printf("Scanning: [%s]\n", varstrings[i]); MapIteratorsFromRval("diagnostic", &scalars, &listoflists, (Rval) { varstrings[i], CF_SCALAR }, NULL); printf("Cumulative scan produced:\n"); printf(" Scalar variables: "); ShowRlist(stdout, scalars); printf("\n"); printf(" Lists variables: "); ShowRlist(stdout, listoflists); printf("\n"); } } }
void HashControls() { struct Body *bdp; char buf[CF_BUFSIZE]; /* Only control bodies need to be hashed like variables */ for (bdp = BODIES; bdp != NULL; bdp = bdp->next) /* get schedule */ { if (strcmp(bdp->name,"control") == 0) { snprintf(buf,CF_BUFSIZE,"%s_%s",bdp->name,bdp->type); Debug("Initiate control variable convergence...%s\n",buf); DeleteScope(buf); SetNewScope(buf); CheckControlPromises(buf,bdp->type,bdp->conlist); } } }
static void KeepPromiseBundles() { Bundle *bp; SubType *sp; Promise *pp; char *scope; /* Dial up the generic promise expansion with a callback */ for (bp = BUNDLES; bp != NULL; bp = bp->next) /* get schedule */ { scope = bp->name; SetNewScope(bp->name); if ((strcmp(bp->type, CF_AGENTTYPES[cf_server]) == 0) || (strcmp(bp->type, CF_AGENTTYPES[cf_common]) == 0)) { DeletePrivateClassContext(); // Each time we change bundle BannerBundle(bp, NULL); scope = bp->name; for (sp = bp->subtypes; sp != NULL; sp = sp->next) /* get schedule */ { if (strcmp(sp->name, "access") != 0 && strcmp(sp->name, "roles") != 0) { continue; } BannerSubType(scope, sp->name, 0); SetScope(scope); AugmentScope(scope, NULL, NULL); for (pp = sp->promiselist; pp != NULL; pp = pp->next) { ExpandPromise(cf_server, scope, pp, KeepServerPromise); } } } } }
void HashVariables(char *name) { struct Bundle *bp; struct SubType *sp; CfOut(cf_verbose,"","Initiate variable convergence...\n"); for (bp = BUNDLES; bp != NULL; bp = bp->next) /* get schedule */ { if (name && strcmp(name,bp->name) != 0) { continue; } SetNewScope(bp->name); THIS_BUNDLE = bp->name; for (sp = bp->subtypes; sp != NULL; sp = sp->next) /* get schedule */ { if (strcmp(sp->name,"vars") == 0) { CheckVariablePromises(bp->name,sp->promiselist); } // We must also set global classes here? if (strcmp(bp->type,"common") == 0 && strcmp(sp->name,"classes") == 0) { CheckCommonClassPromises(sp->promiselist); } if (THIS_AGENT_TYPE == cf_common) { CheckBundleParameters(bp->name,bp->args); } } } }
void GenericInitialize(int argc,char **argv,char *agents) { enum cfagenttype ag = Agent2Type(agents); char vbuff[CF_BUFSIZE]; int ok = false; #ifdef HAVE_NOVA CF_DEFAULT_DIGEST = cf_sha256; CF_DEFAULT_DIGEST_LEN = CF_SHA256_LEN; #else CF_DEFAULT_DIGEST = cf_md5; CF_DEFAULT_DIGEST_LEN = CF_MD5_LEN; #endif InitializeGA(argc,argv); SetReferenceTime(true); SetStartTime(false); SetSignals(); SanitizeEnvironment(); strcpy(THIS_AGENT,CF_AGENTTYPES[ag]); NewClass(THIS_AGENT); THIS_AGENT_TYPE = ag; // need scope sys to set vars in expiry function SetNewScope("sys"); if (EnterpriseExpiry()) { CfOut(cf_error,"","Cfengine - autonomous configuration engine. This enterprise license is invalid.\n"); exit(1); } if (AM_NOVA) { CfOut(cf_verbose,""," -> This is CFE Nova\n"); } if (AM_CONSTELLATION) { CfOut(cf_verbose,""," -> This is CFE Constellation\n"); } NewScope("const"); NewScope("match"); NewScope("mon"); GetNameInfo3(); CfGetInterfaceInfo(ag); if (ag != cf_know) { Get3Environment(); BuiltinClasses(); OSClasses(); } LoadPersistentContext(); LoadSystemConstants(); snprintf(vbuff,CF_BUFSIZE,"control_%s",THIS_AGENT); SetNewScope(vbuff); NewScope("this"); NewScope("match"); if (BOOTSTRAP) { CheckAutoBootstrap(); } else { if (strlen(POLICY_SERVER) > 0) { CfOut(cf_verbose,""," -> Found a policy server (hub) on %s",POLICY_SERVER); } else { CfOut(cf_verbose,""," -> No policy server (hub) watch yet registered"); } } SetPolicyServer(POLICY_SERVER); if (ag != cf_keygen) { if (!MissingInputFile()) { bool check_promises = false; if (SHOWREPORTS) { check_promises = true; CfOut(cf_verbose, "", " -> Reports mode is enabled, force-validating policy"); } if (IsFileOutsideDefaultRepository(VINPUTFILE)) { check_promises = true; CfOut(cf_verbose, "", " -> Input file is outside default repository, validating it"); } if (NewPromiseProposals()) { check_promises = true; CfOut(cf_verbose, "", " -> Input file is changed since last validation, validating it"); } if (check_promises) { ok = CheckPromises(ag); if (BOOTSTRAP && !ok) { CfOut(cf_verbose, "", " -> Policy is not valid, but proceeding with bootstrap"); ok = true; } } else { CfOut(cf_verbose, "", " -> Policy is already validated"); ok = true; } } if (ok) { ReadPromises(ag,agents); } else { CfOut(cf_error,"","cf-agent was not able to get confirmation of promises from cf-promises, so going to failsafe\n"); snprintf(VINPUTFILE,CF_BUFSIZE-1,"failsafe.cf"); ReadPromises(ag,agents); } if (SHOWREPORTS) { CompilationReport(VINPUTFILE); } CheckLicenses(); } XML = 0; }