static void ExecConfigResetDefault(ExecConfig *exec_config) { free(exec_config->log_facility); exec_config->log_facility = xstrdup("LOG_USER"); free(exec_config->exec_command); exec_config->exec_command = xstrdup(""); free(exec_config->mail_server); exec_config->mail_server = xstrdup(""); free(exec_config->mail_from_address); exec_config->mail_from_address = xstrdup(""); free(exec_config->mail_to_address); exec_config->mail_to_address = xstrdup(""); exec_config->mail_max_lines = 30; exec_config->agent_expireafter = 10800; exec_config->splay_time = 0; StringSetClear(exec_config->schedule); StringSetAdd(exec_config->schedule, xstrdup("Min00")); StringSetAdd(exec_config->schedule, xstrdup("Min05")); StringSetAdd(exec_config->schedule, xstrdup("Min10")); StringSetAdd(exec_config->schedule, xstrdup("Min15")); StringSetAdd(exec_config->schedule, xstrdup("Min20")); StringSetAdd(exec_config->schedule, xstrdup("Min25")); StringSetAdd(exec_config->schedule, xstrdup("Min30")); StringSetAdd(exec_config->schedule, xstrdup("Min35")); StringSetAdd(exec_config->schedule, xstrdup("Min40")); StringSetAdd(exec_config->schedule, xstrdup("Min45")); StringSetAdd(exec_config->schedule, xstrdup("Min50")); StringSetAdd(exec_config->schedule, xstrdup("Min55")); }
void EvalContextHeapClear(EvalContext *ctx) { StringSetClear(ctx->heap_soft); StringSetClear(ctx->heap_hard); StringSetClear(ctx->heap_negated); }
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 EvalContextStackFrameClear(EvalContext *ctx) { StackFrame *frame = EvalContextStackFrame(ctx); StringSetClear(frame->contexts); StringSetClear(frame->contexts_negated); }
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)); } } } } }