static void exec_config_copy_cb(const EvalContext *ctx, const Policy *policy) { ExecConfig *config = ExecConfigNew(true, ctx, policy); ExecConfig *config2 = ExecConfigCopy(config); ExecConfigDestroy(config); CheckFullExecConfig(config2); ExecConfigDestroy(config2); }
int main(int argc, char *argv[]) { GenericAgentConfig *config = CheckOpts(argc, argv); EvalContext *ctx = EvalContextNew(); GenericAgentConfigApply(ctx, config); GenericAgentDiscoverContext(ctx, config); Policy *policy = NULL; if (GenericAgentCheckPolicy(config, false, false)) { policy = LoadPolicy(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"); EvalContextClassPutHard(ctx, "failsafe_fallback", "attribute_name=Errors,source=agent"); GenericAgentConfigSetInputFile(config, GetInputDir(), "failsafe.cf"); policy = LoadPolicy(ctx, config); } ThisAgentInit(); ExecConfig *exec_config = ExecConfigNew(!ONCE, ctx, policy); ExecdConfig *execd_config = ExecdConfigNew(ctx, policy); SetFacility(execd_config->log_facility); #ifdef __MINGW32__ if (WINSERVICE) { NovaWin_StartExecService(); } else #endif /* __MINGW32__ */ { StartServer(ctx, policy, config, &execd_config, &exec_config); } ExecConfigDestroy(exec_config); ExecdConfigDestroy(execd_config); GenericAgentConfigDestroy(config); return 0; }
static void exec_config_empty_cb(const EvalContext *ctx, const Policy *policy) { ExecConfig *config = ExecConfigNew(false, ctx, policy); assert_int_equal(false, config->scheduled_run); /* FIXME: exec-config should provide default exec_command */ assert_string_equal("", config->exec_command); assert_string_equal("", config->mail_server); /* FIXME: exec-config should provide default from address */ assert_string_equal("", config->mail_from_address); assert_string_equal("", config->mail_to_address); /* FIXME: exec-config should provide default subject */ assert_string_equal("", config->mail_subject); assert_int_equal(30, config->mail_max_lines); assert_string_equal("localhost.localdomain", config->fq_name); assert_string_equal("127.0.0.100", config->ip_address); assert_string_equal("127.0.0.100 127.0.0.101", config->ip_addresses); ExecConfigDestroy(config); }
int main(int argc, char *argv[]) { GenericAgentConfig *config = CheckOpts(argc, argv); EvalContext *ctx = EvalContextNew(); GenericAgentConfigApply(ctx, config); GenericAgentDiscoverContext(ctx, config); Policy *policy = SelectAndLoadPolicy(config, ctx, false, false); if (!policy) { Log(LOG_LEVEL_ERR, "Error reading CFEngine policy. Exiting..."); exit(EXIT_FAILURE); } GenericAgentPostLoadInit(ctx); ThisAgentInit(); ExecConfig *exec_config = ExecConfigNew(!ONCE, ctx, policy); ExecdConfig *execd_config = ExecdConfigNew(ctx, policy); SetFacility(execd_config->log_facility); #ifdef __MINGW32__ if (WINSERVICE) { NovaWin_StartExecService(); } else #endif /* __MINGW32__ */ { StartServer(ctx, policy, config, &execd_config, &exec_config); } GenericAgentFinalize(ctx, config); ExecConfigDestroy(exec_config); ExecdConfigDestroy(execd_config); return 0; }
static bool ScheduleRun(EvalContext *ctx, Policy **policy, GenericAgentConfig *config, ExecdConfig **execd_config, ExecConfig **exec_config) { Log(LOG_LEVEL_VERBOSE, "Sleeping for pulse time %d seconds...", CFPULSETIME); sleep(CFPULSETIME); /* 1 Minute resolution is enough */ /* * FIXME: this logic duplicates the one from cf-serverd.c. Unify ASAP. */ if (CheckNewPromises(config) == RELOAD_FULL) { /* Full reload */ Log(LOG_LEVEL_INFO, "Re-reading promise file '%s'", config->input_file); EvalContextClear(ctx); strcpy(VDOMAIN, "undefined.domain"); PolicyDestroy(*policy); *policy = NULL; { char *existing_policy_server = ReadPolicyServerFile(GetWorkDir()); SetPolicyServer(ctx, existing_policy_server); free(existing_policy_server); } UpdateLastPolicyUpdateTime(ctx); DetectEnvironment(ctx); EvalContextClassPutHard(ctx, CF_AGENTTYPES[AGENT_TYPE_EXECUTOR], "cfe_internal,source=agent"); time_t t = SetReferenceTime(); UpdateTimeClasses(ctx, t); GenericAgentConfigSetBundleSequence(config, NULL); *policy = LoadPolicy(ctx, config); ExecConfigDestroy(*exec_config); ExecdConfigDestroy(*execd_config); *exec_config = ExecConfigNew(!ONCE, ctx, *policy); *execd_config = ExecdConfigNew(ctx, *policy); SetFacility((*execd_config)->log_facility); } else { /* Environment reload */ EvalContextClear(ctx); DetectEnvironment(ctx); time_t t = SetReferenceTime(); UpdateTimeClasses(ctx, t); } { StringSetIterator it = StringSetIteratorInit((*execd_config)->schedule); const char *time_context = NULL; while ((time_context = StringSetIteratorNext(&it))) { if (IsDefinedClass(ctx, time_context)) { Log(LOG_LEVEL_VERBOSE, "Waking up the agent at %s ~ %s", ctime(&CFSTARTTIME), time_context); return true; } } } Log(LOG_LEVEL_VERBOSE, "Nothing to do at %s", ctime(&CFSTARTTIME)); return false; }