void KeepPromises(Policy *policy, ExecConfig *config) { bool schedule_is_specified = false; Seq *constraints = ControlBodyConstraints(policy, AGENT_TYPE_EXECUTOR); if (constraints) { for (size_t i = 0; i < SeqLength(constraints); i++) { Constraint *cp = SeqAt(constraints, i); if (IsExcluded(cp->classes, NULL)) { continue; } Rval retval; if (GetVariable("control_executor", cp->lval, &retval) == DATA_TYPE_NONE) { CfOut(OUTPUT_LEVEL_ERROR, "", "Unknown lval %s in exec control body", cp->lval); continue; } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_mailfrom].lval) == 0) { free(config->mail_from_address); config->mail_from_address = SafeStringDuplicate(retval.item); CfDebug("mailfrom = %s\n", config->mail_from_address); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_mailto].lval) == 0) { free(config->mail_to_address); config->mail_to_address = SafeStringDuplicate(retval.item); CfDebug("mailto = %s\n", config->mail_to_address); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_smtpserver].lval) == 0) { free(config->mail_server); config->mail_server = SafeStringDuplicate(retval.item); CfDebug("smtpserver = %s\n", config->mail_server); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_execcommand].lval) == 0) { free(config->exec_command); config->exec_command = SafeStringDuplicate(retval.item); CfDebug("exec_command = %s\n", config->exec_command); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_agent_expireafter].lval) == 0) { config->agent_expireafter = IntFromString(retval.item); CfDebug("agent_expireafter = %d\n", config->agent_expireafter); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_executorfacility].lval) == 0) { SetFacility(retval.item); continue; } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_mailmaxlines].lval) == 0) { config->mail_max_lines = IntFromString(retval.item); CfDebug("maxlines = %d\n", config->mail_max_lines); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_splaytime].lval) == 0) { int time = IntFromString(RvalScalarValue(retval)); SPLAYTIME = (int) (time * SECONDS_PER_MINUTE * GetSplay()); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_schedule].lval) == 0) { CfDebug("Loading user-defined schedule...\n"); DeleteItemList(SCHEDULE); SCHEDULE = NULL; schedule_is_specified = true; for (const Rlist *rp = retval.item; rp; rp = rp->next) { if (!IsItemIn(SCHEDULE, rp->item)) { AppendItem(&SCHEDULE, rp->item, NULL); } } } } } if (!schedule_is_specified) { LoadDefaultSchedule(); } }
void KeepPromises(Policy *policy, ExecConfig *config) { for (Constraint *cp = ControlBodyConstraints(policy, cf_executor); cp != NULL; cp = cp->next) { if (IsExcluded(cp->classes, NULL)) { continue; } Rval retval; if (GetVariable("control_executor", cp->lval, &retval) == cf_notype) { CfOut(cf_error, "", "Unknown lval %s in exec control body", cp->lval); continue; } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_mailfrom].lval) == 0) { free(config->mail_from_address); config->mail_from_address = SafeStringDuplicate(retval.item); CfDebug("mailfrom = %s\n", config->mail_from_address); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_mailto].lval) == 0) { free(config->mail_to_address); config->mail_to_address = SafeStringDuplicate(retval.item); CfDebug("mailto = %s\n", config->mail_to_address); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_smtpserver].lval) == 0) { free(config->mail_server); config->mail_server = SafeStringDuplicate(retval.item); CfDebug("smtpserver = %s\n", config->mail_server); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_execcommand].lval) == 0) { free(config->exec_command); config->exec_command = SafeStringDuplicate(retval.item); CfDebug("exec_command = %s\n", config->exec_command); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_agent_expireafter].lval) == 0) { config->agent_expireafter = Str2Int(retval.item); CfDebug("agent_expireafter = %d\n", config->agent_expireafter); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_executorfacility].lval) == 0) { SetFacility(retval.item); continue; } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_mailmaxlines].lval) == 0) { config->mail_max_lines = Str2Int(retval.item); CfDebug("maxlines = %d\n", config->mail_max_lines); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_splaytime].lval) == 0) { int time = Str2Int(ScalarRvalValue(retval)); SPLAYTIME = (int) (time * SECONDS_PER_MINUTE * GetSplay()); } if (strcmp(cp->lval, CFEX_CONTROLBODY[cfex_schedule].lval) == 0) { Rlist *rp; CfDebug("schedule ...\n"); DeleteItemList(SCHEDULE); SCHEDULE = NULL; for (rp = (Rlist *) retval.item; rp != NULL; rp = rp->next) { if (!IsItemIn(SCHEDULE, rp->item)) { AppendItem(&SCHEDULE, rp->item, NULL); } } } } }
void ExecConfigUpdate(const EvalContext *ctx, const Policy *policy, ExecConfig *exec_config) { ExecConfigResetDefault(exec_config); Seq *constraints = ControlBodyConstraints(policy, AGENT_TYPE_EXECUTOR); if (constraints) { for (size_t i = 0; i < SeqLength(constraints); i++) { Constraint *cp = SeqAt(constraints, i); if (!IsDefinedClass(ctx, cp->classes, NULL)) { continue; } VarRef *ref = VarRefParseFromScope(cp->lval, "control_executor"); Rval retval; if (!EvalContextVariableGet(ctx, ref, &retval, NULL)) { // TODO: should've been checked before this point. change to programming error Log(LOG_LEVEL_ERR, "Unknown lval '%s' in exec control body", cp->lval); VarRefDestroy(ref); continue; } VarRefDestroy(ref); if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_MAILFROM].lval) == 0) { free(exec_config->mail_from_address); exec_config->mail_from_address = xstrdup(retval.item); Log(LOG_LEVEL_DEBUG, "mailfrom '%s'", exec_config->mail_from_address); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_MAILTO].lval) == 0) { free(exec_config->mail_to_address); exec_config->mail_to_address = xstrdup(retval.item); Log(LOG_LEVEL_DEBUG, "mailto '%s'", exec_config->mail_to_address); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_MAILSUBJECT].lval) == 0) { free(exec_config->mail_subject); exec_config->mail_subject = xstrdup(retval.item); Log(LOG_LEVEL_DEBUG, "mailsubject '%s'", exec_config->mail_subject); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_SMTPSERVER].lval) == 0) { free(exec_config->mail_server); exec_config->mail_server = xstrdup(retval.item); Log(LOG_LEVEL_DEBUG, "smtpserver '%s'", exec_config->mail_server); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_EXECCOMMAND].lval) == 0) { free(exec_config->exec_command); exec_config->exec_command = xstrdup(retval.item); Log(LOG_LEVEL_DEBUG, "exec_command '%s'", exec_config->exec_command); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_AGENT_EXPIREAFTER].lval) == 0) { exec_config->agent_expireafter = IntFromString(retval.item); Log(LOG_LEVEL_DEBUG, "agent_expireafter %d", exec_config->agent_expireafter); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_EXECUTORFACILITY].lval) == 0) { exec_config->log_facility = xstrdup(retval.item); Log(LOG_LEVEL_DEBUG, "executorfacility '%s'", exec_config->log_facility); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_MAILMAXLINES].lval) == 0) { exec_config->mail_max_lines = IntFromString(retval.item); Log(LOG_LEVEL_DEBUG, "maxlines %d", exec_config->mail_max_lines); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_SPLAYTIME].lval) == 0) { int time = IntFromString(RvalScalarValue(retval)); exec_config->splay_time = (int) (time * SECONDS_PER_MINUTE * GetSplay()); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_SCHEDULE].lval) == 0) { Log(LOG_LEVEL_DEBUG, "Loading user-defined schedule..."); StringSetClear(exec_config->schedule); for (const Rlist *rp = retval.item; rp; rp = rp->next) { StringSetAdd(exec_config->schedule, xstrdup(RlistScalarValue(rp))); Log(LOG_LEVEL_DEBUG, "Adding '%s'", RlistScalarValue(rp)); } } } } char ipbuf[CF_MAXVARSIZE] = ""; for (Item *iptr = EvalContextGetIpAddresses(ctx); iptr != NULL; iptr = iptr->next) { if ((SafeStringLength(ipbuf) + SafeStringLength(iptr->name)) < sizeof(ipbuf)) { strcat(ipbuf, iptr->name); strcat(ipbuf, " "); } else { break; } } Chop(ipbuf, sizeof(ipbuf)); free(exec_config->ip_addresses); exec_config->ip_addresses = xstrdup(ipbuf); }
void ExecConfigUpdate(const EvalContext *ctx, const Policy *policy, ExecConfig *exec_config) { ExecConfigResetDefault(exec_config); Seq *constraints = ControlBodyConstraints(policy, AGENT_TYPE_EXECUTOR); if (constraints) { for (size_t i = 0; i < SeqLength(constraints); i++) { Constraint *cp = SeqAt(constraints, i); if (!IsDefinedClass(ctx, cp->classes, NULL)) { continue; } Rval retval; if (!EvalContextVariableGet(ctx, (VarRef) { NULL, "control_executor", cp->lval }, &retval, NULL)) { // TODO: should've been checked before this point. change to programming error CfOut(OUTPUT_LEVEL_ERROR, "", "Unknown lval %s in exec control body", cp->lval); continue; } if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_MAILFROM].lval) == 0) { free(exec_config->mail_from_address); exec_config->mail_from_address = xstrdup(retval.item); CfDebug("mailfrom = %s\n", exec_config->mail_from_address); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_MAILTO].lval) == 0) { free(exec_config->mail_to_address); exec_config->mail_to_address = xstrdup(retval.item); CfDebug("mailto = %s\n", exec_config->mail_to_address); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_SMTPSERVER].lval) == 0) { free(exec_config->mail_server); exec_config->mail_server = xstrdup(retval.item); CfDebug("smtpserver = %s\n", exec_config->mail_server); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_EXECCOMMAND].lval) == 0) { free(exec_config->exec_command); exec_config->exec_command = xstrdup(retval.item); CfDebug("exec_command = %s\n", exec_config->exec_command); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_AGENT_EXPIREAFTER].lval) == 0) { exec_config->agent_expireafter = IntFromString(retval.item); CfDebug("agent_expireafter = %d\n", exec_config->agent_expireafter); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_EXECUTORFACILITY].lval) == 0) { exec_config->log_facility = xstrdup(retval.item); CfDebug("executorfacility = %s\n", exec_config->log_facility); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_MAILMAXLINES].lval) == 0) { exec_config->mail_max_lines = IntFromString(retval.item); CfDebug("maxlines = %d\n", exec_config->mail_max_lines); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_SPLAYTIME].lval) == 0) { int time = IntFromString(RvalScalarValue(retval)); exec_config->splay_time = (int) (time * SECONDS_PER_MINUTE * GetSplay()); } else if (strcmp(cp->lval, CFEX_CONTROLBODY[EXEC_CONTROL_SCHEDULE].lval) == 0) { CfDebug("Loading user-defined schedule...\n"); StringSetClear(exec_config->schedule); for (const Rlist *rp = retval.item; rp; rp = rp->next) { StringSetAdd(exec_config->schedule, xstrdup(RlistScalarValue(rp))); CfDebug("Adding %s\n", RlistScalarValue(rp)); } } } } }