int main(int argc, char *argv[]) { EvalContext *ctx = EvalContextNew(); GenericAgentConfig *config = CheckOpts(ctx, argc, argv); GenericAgentConfigApply(ctx, config); GenericAgentDiscoverContext(ctx, config); Policy *policy = NULL; if (GenericAgentCheckPolicy(ctx, config, false)) { policy = GenericAgentLoadPolicy(ctx, config); } else if (config->tty_interactive) { exit(EXIT_FAILURE); } else { CfOut(OUTPUT_LEVEL_ERROR, "", "CFEngine was not able to get confirmation of promises from cf-promises, so going to failsafe\n"); EvalContextHeapAddHard(ctx, "failsafe_fallback"); GenericAgentConfigSetInputFile(config, "failsafe.cf"); policy = GenericAgentLoadPolicy(ctx, config); } WarnAboutDeprecatedFeatures(ctx); CheckForPolicyHub(ctx); ThisAgentInit(); ExecConfig *exec_config = ExecConfigNewDefault(!ONCE, VFQNAME, VIPADDRESS); ExecConfigUpdate(ctx, policy, exec_config); SetFacility(exec_config->log_facility); #ifdef __MINGW32__ if (WINSERVICE) { NovaWin_StartExecService(); } else #endif /* __MINGW32__ */ { StartServer(ctx, policy, config, exec_config); } ExecConfigDestroy(exec_config); GenericAgentConfigDestroy(config); return 0; }
int main(int argc, char *argv[]) { EvalContext *ctx = EvalContextNew(); GenericAgentConfig *config = CheckOpts(ctx, argc, argv); GenericAgentConfigApply(ctx, config); GenericAgentDiscoverContext(ctx, config); Policy *policy = NULL; if (GenericAgentCheckPolicy(config, false)) { policy = GenericAgentLoadPolicy(ctx, config); } else if (config->tty_interactive) { exit(EXIT_FAILURE); } else { Log(LOG_LEVEL_ERR, "CFEngine was not able to get confirmation of promises from cf-promises, so going to failsafe"); EvalContextClassPut(ctx, NULL, "failsafe_fallback", false, CONTEXT_SCOPE_NAMESPACE, "goal=update,source=agent"); GenericAgentConfigSetInputFile(config, GetWorkDir(), "failsafe.cf"); policy = GenericAgentLoadPolicy(ctx, config); } ThisAgentInit(); ExecConfig *exec_config = ExecConfigNewDefault(!ONCE, VFQNAME, VIPADDRESS); ExecConfigUpdate(ctx, policy, exec_config); SetFacility(exec_config->log_facility); #ifdef __MINGW32__ if (WINSERVICE) { NovaWin_StartExecService(); } else #endif /* __MINGW32__ */ { StartServer(ctx, policy, config, exec_config); } ExecConfigDestroy(exec_config); GenericAgentConfigDestroy(config); return 0; }
static void test_load(void) { GenericAgentConfig *agent_config = GenericAgentConfigNewDefault(AGENT_TYPE_EXECUTOR); ExecConfig *c = ExecConfigNewDefault(true, "host", "ip"); assert_true(c->scheduled_run); assert_string_equal("host", c->fq_name); assert_string_equal("ip", c->ip_address); TestCheckConfigIsDefault(c); EvalContext *ctx = EvalContextNew(); { VarRef *lval = VarRefParse("g.host"); EvalContextVariablePut(ctx, lval, "snookie", DATA_TYPE_STRING, NULL); VarRefDestroy(lval); } // provide a full body executor control and check that all options are collected { Policy *p = LoadPolicy("body_executor_control_full.cf"); PolicyResolve(ctx, p, agent_config); ExecConfigUpdate(ctx, p, c); assert_true(c->scheduled_run); assert_string_equal("host", c->fq_name); assert_string_equal("ip", c->ip_address); assert_int_equal(120, c->agent_expireafter); assert_string_equal("/bin/echo", c->exec_command); assert_string_equal("LOG_LOCAL6",c->log_facility); assert_string_equal("*****@*****.**",c->mail_from_address); assert_int_equal(50, c->mail_max_lines); assert_string_equal("localhost", c->mail_server); assert_string_equal("*****@*****.**",c->mail_to_address); assert_string_equal("Test [localhost/127.0.0.1]",c->mail_subject); // splay time hard to test (pseudo random) assert_int_equal(2, StringSetSize(c->schedule)); assert_true(StringSetContains(c->schedule, "Min00_05")); assert_true(StringSetContains(c->schedule, "Min05_10")); PolicyDestroy(p); } // provide a small policy and check that missing settings are being reverted to default { { Policy *p = LoadPolicy("body_executor_control_agent_expireafter_only.cf"); PolicyResolve(ctx, p, agent_config); ExecConfigUpdate(ctx, p, c); assert_true(c->scheduled_run); assert_string_equal("host", c->fq_name); assert_string_equal("ip", c->ip_address); assert_int_equal(121, c->agent_expireafter); // rest should be default assert_string_equal("", c->exec_command); assert_string_equal("LOG_USER",c->log_facility); assert_string_equal("",c->mail_from_address); assert_int_equal(30, c->mail_max_lines); assert_string_equal("", c->mail_server); assert_string_equal("",c->mail_to_address); assert_string_equal("",c->mail_subject); assert_int_equal(0, c->splay_time); assert_int_equal(12, StringSetSize(c->schedule)); PolicyDestroy(p); } } EvalContextDestroy(ctx); GenericAgentConfigDestroy(agent_config); }
static void test_new_destroy(void) { ExecConfig *c = ExecConfigNewDefault(true, "host", "ip"); TestCheckConfigIsDefault(c); ExecConfigDestroy(c); }