static void CollectCallIfDue(EvalContext *ctx) { /* Check whether we have established peering with a hub */ if (CollectCallHasPending()) { extern int COLLECT_WINDOW; int waiting_queue = 0; int new_client = CollectCallGetPending(&waiting_queue); assert(new_client >= 0); if (waiting_queue > COLLECT_WINDOW) { Log(LOG_LEVEL_INFO, "Abandoning collect call attempt with queue longer than collect_window [%d > %d]", waiting_queue, COLLECT_WINDOW); cf_closesocket(new_client); CollectCallMarkProcessed(); } else { ConnectionInfo *info = ConnectionInfoNew(); assert(info); ConnectionInfoSetSocket(info, new_client); info->is_call_collect = true; /* Mark processed when done. */ ServerEntryPoint(ctx, PolicyServerGetIP(), info); } } }
/** * @brief Sets both internal C variables as well as policy sys variables. * * Called at bootstrap and after reading policy_server.dat. * Changes sys.policy_hub and sys.policy_hub_port. * NULL is an acceptable value for new_policy_server. Could happen when an * already bootstrapped server re-parses its policies, and the * policy_server.dat file has been removed. Then this function will be called * with NULL as new_policy_server, and cf-serverd will keep running even * without a policy server set. * * @param ctx EvalContext is used to set related variables * @param new_policy_server can be 'host:port', same as policy_server.dat */ void EvalContextSetPolicyServer(EvalContext *ctx, const char *new_policy_server) { // Remove variables if undefined policy server: if ( NULL_OR_EMPTY(new_policy_server) ) { EvalContextVariableRemoveSpecial( ctx, SPECIAL_SCOPE_SYS, "policy_hub" ); EvalContextVariableRemoveSpecial( ctx, SPECIAL_SCOPE_SYS, "policy_hub_port" ); return; } PolicyServerSet(new_policy_server); const char *ip = PolicyServerGetIP(); // Set the sys.policy_hub variable: if ( ip != NULL ) { EvalContextVariablePutSpecial( ctx, SPECIAL_SCOPE_SYS, "policy_hub", ip, CF_DATA_TYPE_STRING, "source=bootstrap" ); } else { EvalContextVariableRemoveSpecial( ctx, SPECIAL_SCOPE_SYS, "policy_hub" ); } // Set the sys.policy_hub_port variable: if (PolicyServerGetPort() != NULL) { EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS, "policy_hub_port", PolicyServerGetPort(), CF_DATA_TYPE_STRING, "source=bootstrap" ); } else // Default value (CFENGINE_PORT_STR = "5308") is set { EvalContextVariablePutSpecial( ctx, SPECIAL_SCOPE_SYS, "policy_hub_port", CFENGINE_PORT_STR, CF_DATA_TYPE_STRING, "source=bootstrap" ); } }