static void TestAgentPromises() { Promise pp = { 0 }; pp.conlist = NULL; pp.audit = NULL; printf("%d. Testing promise attribute completeness (with no desired intention)\n", ++NR); GetFilesAttributes(&pp); GetReportsAttributes(&pp); GetExecAttributes(&pp); GetProcessAttributes(&pp); GetStorageAttributes(&pp); GetClassContextAttributes(&pp); GetTopicsAttributes(&pp); GetOccurrenceAttributes(&pp); GetMethodAttributes(&pp); GetInterfacesAttributes(&pp); GetInsertionAttributes(&pp); GetDeletionAttributes(&pp); GetColumnAttributes(&pp); GetReplaceAttributes(&pp); printf(" -> All non-listed items are accounted for\n"); }
void VerifyReportPromise(struct Promise *pp) { struct Attributes a = {{0}}; struct CfLock thislock; struct Rlist *rp; char unique_name[CF_EXPANDSIZE]; a = GetReportsAttributes(pp); if (strcmp(pp->classes,"any") == 0) { CfOut(cf_verbose,""," --> Reports promises may not be in class \"any\""); return; } snprintf(unique_name,CF_EXPANDSIZE-1,"%s_%d",pp->promiser,pp->lineno); thislock = AcquireLock(unique_name,VUQNAME,CFSTARTTIME,a,pp,false); if (thislock.lock == NULL) { return; } PromiseBanner(pp); cfPS(cf_verbose,CF_CHG,"",pp,a,"Report: %s", pp->promiser); if (a.report.to_file) { CfFOut(a.report.to_file,cf_error,"","%s",pp->promiser); } else { CfOut(cf_reporting,"","R: %s",pp->promiser); } if (a.report.haveprintfile) { PrintFile(a,pp); } if (a.report.showstate) { for (rp = a.report.showstate; rp != NULL; rp=rp->next) { ShowState(rp->item,a,pp); } } if (a.report.havelastseen) { FriendStatus(a,pp); } YieldCurrentLock(thislock); }
void VerifyReportPromise(Promise *pp) { Attributes a = { {0} }; CfLock thislock; Rlist *rp; char unique_name[CF_EXPANDSIZE]; a = GetReportsAttributes(pp); snprintf(unique_name, CF_EXPANDSIZE - 1, "%s_%zu", pp->promiser, pp->offset.line); thislock = AcquireLock(unique_name, VUQNAME, CFSTARTTIME, a, pp, false); if (thislock.lock == NULL) { return; } PromiseBanner(pp); cfPS(cf_verbose, CF_CHG, "", pp, a, "Report: %s", pp->promiser); if (a.report.to_file) { CfFOut(a.report.to_file, cf_error, "", "%s", pp->promiser); } else { CfOut(cf_reporting, "", "R: %s", pp->promiser); } if (a.report.haveprintfile) { PrintFile(a, pp); } if (a.report.showstate) { for (rp = a.report.showstate; rp != NULL; rp = rp->next) { ShowState(rp->item); } } if (a.report.havelastseen) { /* Do nothing. Deprecated. */ } YieldCurrentLock(thislock); }
PromiseResult VerifyReportPromise(EvalContext *ctx, const Promise *pp) { CfLock thislock; char unique_name[CF_EXPANDSIZE]; Attributes a = GetReportsAttributes(ctx, pp); // We let AcquireLock worry about making a unique name snprintf(unique_name, CF_EXPANDSIZE - 1, "%s", pp->promiser); thislock = AcquireLock(ctx, unique_name, VUQNAME, CFSTARTTIME, a.transaction, pp, false); // Handle return values before locks, as we always do this if (a.report.result) { // User-unwritable value last-result contains the useresult if (strlen(a.report.result) > 0) { snprintf(unique_name, CF_BUFSIZE, "last-result[%s]", a.report.result); } else { snprintf(unique_name, CF_BUFSIZE, "last-result"); } VarRef *ref = VarRefParseFromBundle(unique_name, PromiseGetBundle(pp)); EvalContextVariablePut(ctx, ref, pp->promiser, CF_DATA_TYPE_STRING, "source=bundle"); VarRefDestroy(ref); if (thislock.lock) { YieldCurrentLock(thislock); } return PROMISE_RESULT_NOOP; } if (thislock.lock == NULL) { return PROMISE_RESULT_SKIPPED; } PromiseBanner(ctx, pp); if (a.transaction.action == cfa_warn) { cfPS(ctx, LOG_LEVEL_WARNING, PROMISE_RESULT_WARN, pp, a, "Need to repair reports promise: %s", pp->promiser); YieldCurrentLock(thislock); return PROMISE_RESULT_WARN; } if (a.report.to_file) { ReportToFile(a.report.to_file, pp->promiser); } else { ReportToLog(pp->promiser); } PromiseResult result = PROMISE_RESULT_NOOP; if (a.report.haveprintfile) { if (!PrintFile(a.report.filename, a.report.numlines)) { result = PromiseResultUpdate(result, PROMISE_RESULT_FAIL); } } YieldCurrentLock(thislock); ClassAuditLog(ctx, pp, a, result); return result; }
void VerifyReportPromise(Promise *pp) { Attributes a = { {0} }; CfLock thislock; Rlist *rp; char unique_name[CF_EXPANDSIZE]; a = GetReportsAttributes(pp); snprintf(unique_name, CF_EXPANDSIZE - 1, "%s_%zu", pp->promiser, pp->offset.line); thislock = AcquireLock(unique_name, VUQNAME, CFSTARTTIME, a, pp, false); // Handle return values before locks, as we always do this if (a.report.result) { // User-unwritable value last-result contains the useresult if (strlen(a.report.result) > 0) { snprintf(unique_name, CF_BUFSIZE, "last-result[%s]", a.report.result); } else { snprintf(unique_name, CF_BUFSIZE, "last-result"); } NewScalar(pp->bundle, unique_name, pp->promiser, cf_str); return; } // Now do regular human reports if (thislock.lock == NULL) { return; } PromiseBanner(pp); cfPS(cf_verbose, CF_CHG, "", pp, a, "Report: %s", pp->promiser); if (a.report.to_file) { CfFOut(a.report.to_file, cf_error, "", "%s", pp->promiser); } else { CfOut(cf_reporting, "", "R: %s", pp->promiser); } if (a.report.haveprintfile) { PrintFile(a, pp); } if (a.report.showstate) { for (rp = a.report.showstate; rp != NULL; rp = rp->next) { ShowState(rp->item); } } if (a.report.havelastseen) { /* Do nothing. Deprecated. */ } YieldCurrentLock(thislock); }
void VerifyReportPromise(EvalContext *ctx, Promise *pp) { Attributes a = { {0} }; CfLock thislock; char unique_name[CF_EXPANDSIZE]; a = GetReportsAttributes(ctx, pp); snprintf(unique_name, CF_EXPANDSIZE - 1, "%s_%zu", pp->promiser, pp->offset.line); thislock = AcquireLock(ctx, unique_name, VUQNAME, CFSTARTTIME, a.transaction, pp, false); // Handle return values before locks, as we always do this if (a.report.result) { // User-unwritable value last-result contains the useresult if (strlen(a.report.result) > 0) { snprintf(unique_name, CF_BUFSIZE, "last-result[%s]", a.report.result); } else { snprintf(unique_name, CF_BUFSIZE, "last-result"); } VarRef *ref = VarRefParseFromBundle(unique_name, PromiseGetBundle(pp)); EvalContextVariablePut(ctx, ref, (Rval) { pp->promiser, RVAL_TYPE_SCALAR }, DATA_TYPE_STRING); VarRefDestroy(ref); return; } // Now do regular human reports if (thislock.lock == NULL) { return; } PromiseBanner(pp); if (a.transaction.action == cfa_warn) { cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_WARN, pp, a, "Need to repair reports promise: %s", pp->promiser); YieldCurrentLock(thislock); return; } cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_CHANGE, pp, a, "Report: %s", pp->promiser); if (a.report.to_file) { ReportToFile(a.report.to_file, pp->promiser); } else { Log(LOG_LEVEL_NOTICE, "R: %s", pp->promiser); } if (a.report.haveprintfile) { PrintFile(ctx, a, pp); } if (a.report.showstate) { /* Do nothing. Deprecated. */ } if (a.report.havelastseen) { /* Do nothing. Deprecated. */ } YieldCurrentLock(thislock); }
void VerifyReportPromise(Promise *pp) { Attributes a = { {0} }; CfLock thislock; char unique_name[CF_EXPANDSIZE]; a = GetReportsAttributes(pp); snprintf(unique_name, CF_EXPANDSIZE - 1, "%s_%zu", pp->promiser, pp->offset.line); thislock = AcquireLock(unique_name, VUQNAME, CFSTARTTIME, a, pp, false); // Handle return values before locks, as we always do this if (a.report.result) { // User-unwritable value last-result contains the useresult if (strlen(a.report.result) > 0) { snprintf(unique_name, CF_BUFSIZE, "last-result[%s]", a.report.result); } else { snprintf(unique_name, CF_BUFSIZE, "last-result"); } NewScalar(pp->bundle, unique_name, pp->promiser, DATA_TYPE_STRING); return; } // Now do regular human reports if (thislock.lock == NULL) { return; } PromiseBanner(pp); cfPS(OUTPUT_LEVEL_VERBOSE, CF_CHG, "", pp, a, "Report: %s", pp->promiser); if (a.report.to_file) { CfFOut(a.report.to_file, OUTPUT_LEVEL_ERROR, "", "%s", pp->promiser); } else { CfOut(OUTPUT_LEVEL_REPORTING, "", "R: %s", pp->promiser); } if (a.report.haveprintfile) { PrintFile(a, pp); } if (a.report.showstate) { /* Do nothing. Deprecated. */ } if (a.report.havelastseen) { /* Do nothing. Deprecated. */ } YieldCurrentLock(thislock); }