Ejemplo n.º 1
0
void PrintVersionBanner(const char *component)
{
const char *text[] =
   {
   "",
   component,
   "",
   NameVersion(),
#ifdef HAVE_NOVA
   Nova_NameVersion(),
#endif
#ifdef HAVE_CONSTELLATION
   Constellation_NameVersion(),
#endif
   NULL
   };

printf("\n");
AgentBanner(text);
printf("\n");
printf("Copyright (C) CFEngine AS 2008-%d\n", BUILD_YEAR);
printf("See Licensing at http://cfengine.com/3rdpartylicenses\n");
}
Ejemplo n.º 2
0
ENTERPRISE_VOID_FUNC_1ARG_DEFINE_STUB(void, GenericAgentWriteVersion, Writer *, w)
{
    WriterWriteF(w, "%s\n", NameVersion());
}
Ejemplo n.º 3
0
void GenericAgentDiscoverContext(EvalContext *ctx, GenericAgentConfig *config)
{
    strcpy(VPREFIX, "");

    Log(LOG_LEVEL_VERBOSE, " %s", NameVersion());
    Banner("Initialization preamble");

    GenericAgentSetDefaultDigest(&CF_DEFAULT_DIGEST, &CF_DEFAULT_DIGEST_LEN);
    GenericAgentInitialize(ctx, config);

    time_t t = SetReferenceTime();
    UpdateTimeClasses(ctx, t);
    SanitizeEnvironment();

    THIS_AGENT_TYPE = config->agent_type;
    LoggingSetAgentType(CF_AGENTTYPES[config->agent_type]);
    EvalContextClassPutHard(ctx, CF_AGENTTYPES[config->agent_type],
                            "cfe_internal,source=agent");

    DetectEnvironment(ctx);

    EvalContextHeapPersistentLoadAll(ctx);
    LoadSystemConstants(ctx);

    const char *bootstrap_arg =
        config->agent_specific.agent.bootstrap_policy_server;

    /* Are we bootstrapping the agent? */
    if (config->agent_type == AGENT_TYPE_AGENT && bootstrap_arg != NULL)
    {
        EvalContextClassPutHard(ctx, "bootstrap_mode", "source=environment");

        if (!RemoveAllExistingPolicyInInputs(GetInputDir()))
        {
            Log(LOG_LEVEL_ERR,
                "Error removing existing input files prior to bootstrap");
            exit(EXIT_FAILURE);
        }

        if (!WriteBuiltinFailsafePolicy(GetInputDir()))
        {
            Log(LOG_LEVEL_ERR,
                "Error writing builtin failsafe to inputs prior to bootstrap");
            exit(EXIT_FAILURE);
        }

        char canonified_ipaddr[strlen(bootstrap_arg) + 1];
        StringCanonify(canonified_ipaddr, bootstrap_arg);

        bool am_policy_server =
            EvalContextClassGet(ctx, NULL, canonified_ipaddr) != NULL;

        if (am_policy_server)
        {
            Log(LOG_LEVEL_INFO, "Assuming role as policy server,"
                " with policy distribution point at: %s", GetMasterDir());
            MarkAsPolicyServer(ctx);

            if (!MasterfileExists(GetMasterDir()))
            {
                Log(LOG_LEVEL_ERR, "In order to bootstrap as a policy server,"
                    " the file '%s/promises.cf' must exist.", GetMasterDir());
                exit(EXIT_FAILURE);
            }

            CheckAndSetHAState(GetWorkDir(), ctx);
        }
        else
        {
            Log(LOG_LEVEL_INFO, "Assuming role as regular client,"
                " bootstrapping to policy server: %s", bootstrap_arg);

            if (config->agent_specific.agent.bootstrap_trust_server)
            {
                EvalContextClassPutHard(ctx, "trust_server", "source=agent");
                Log(LOG_LEVEL_NOTICE,
                    "Bootstrap mode: implicitly trusting server, "
                    "use --trust-server=no if server trust is already established");
            }
        }

        WriteAmPolicyHubFile(am_policy_server);

        WritePolicyServerFile(GetWorkDir(), bootstrap_arg);
        SetPolicyServer(ctx, bootstrap_arg);

        /* FIXME: Why it is called here? Can't we move both invocations to before if? */
        UpdateLastPolicyUpdateTime(ctx);
    }
    else
    {
        char *existing_policy_server = ReadPolicyServerFile(GetWorkDir());
        if (existing_policy_server)
        {
            Log(LOG_LEVEL_VERBOSE, "This agent is bootstrapped to: %s",
                existing_policy_server);
            SetPolicyServer(ctx, existing_policy_server);
            free(existing_policy_server);
            UpdateLastPolicyUpdateTime(ctx);
        }
        else
        {
            Log(LOG_LEVEL_VERBOSE, "This agent is not bootstrapped -"
                " can't find policy_server.dat in: %s", GetWorkDir());
            return;
        }

        if (GetAmPolicyHub())
        {
            MarkAsPolicyServer(ctx);

            /* Should this go in MarkAsPolicyServer() ? */
            CheckAndSetHAState(GetWorkDir(), ctx);
        }
    }
}
Ejemplo n.º 4
0
static void TexinfoHeader(FILE *fout)
{
    fprintf(fout,
            "\\input texinfo-altfont\n"
            "\\input texinfo-logo\n"
            "\\input texinfo\n"
            "@selectaltfont{cmbright}\n"
            "@setlogo{CFEngineFrontPage}\n"
            "@c *********************************************************************\n"
            "@c\n"
            "@c  This is an AUTO_GENERATED TEXINFO file. Do not submit patches against it.\n"
            "@c  Refer to the the component .texinfo files instead when patching docs.\n"
            "@c\n"
            "@c ***********************************************************************\n"
            "@c %%** start of header\n"
            "@setfilename cf3-Reference.info\n"
            "@settitle CFEngine reference manual\n"
            "@setchapternewpage odd\n"
            "@c %%** end of header\n"
            "@titlepage\n"
            "@title CFEngine Reference Manual\n" "@subtitle Auto generated, self-healing knowledge\n" "@subtitle %s\n"
#ifdef HAVE_NOVA
            "@subtitle %s\n"
#endif
            "@author cfengine.com\n"
            "@c @smallbook\n"
            "@fonttextsize 10\n"
            "@page\n"
            "@vskip 0pt plus 1filll\n"
            "@cartouche\n"
            "Under no circumstances shall CFEngine AS be liable for errors or omissions\n"
            "in this document. All efforts have been made to ensure the correctness of\n"
            "the information contained herein.\n"
            "@end cartouche\n"
            "Copyright @copyright{} 2008,2010 to the year of issue CFEngine AS\n"
            "@end titlepage\n"
            "@c *************************** File begins here ************************\n"
            "@ifinfo\n"
            "@dircategory CFEngine Training\n"
            "@direntry\n"
            "* cfengine Reference:\n"
            "                        CFEngine is a language based framework\n"
            "                        designed for configuring and maintaining\n"
            "                        Unix-like operating systems attached\n"
            "                        to a TCP/IP network.\n"
            "@end direntry\n"
            "@end ifinfo\n"
            "@ifnottex\n"
            "@node Top\n"
            "@top CFEngine-AutoReference\n"
            "@end ifnottex\n"
            "@menu\n"
            "* Getting started::\n"
            "* A simple crash course::\n"
            "* How to run CFEngine 3 examples::\n"
            "* A complete configuration::\n"
            "* Control Promises::\n"
            "* Bundles for common::\n"
            "* Bundles for agent::\n"
            "* Bundles for server::\n"
            "* Bundles for knowledge::\n"
            "* Bundles for monitor::\n"
            "* Special functions::\n"
            "* Special Variables::\n"
            "* Logs and records::\n"
            "@end menu\n"
            "@ifhtml\n"
            "@html\n"
            "<a href=\"#Contents\"><h1>COMPLETE TABLE OF CONTENTS</h1></a>\n"
            "<h2>Summary of contents</h2>\n"
            "@end html\n" "@end ifhtml\n" "@iftex\n" "@contents\n" "@end iftex\n", NameVersion()
#ifdef HAVE_NOVA
            , Nova_NameVersion()
#endif
        );
}
Ejemplo n.º 5
0
void GenericAgentDiscoverContext(EvalContext *ctx, GenericAgentConfig *config)
{
    strcpy(VPREFIX, "");

    Log(LOG_LEVEL_VERBOSE, " %s", NameVersion());
    Banner("Initialization preamble");

    GenericAgentSetDefaultDigest(&CF_DEFAULT_DIGEST, &CF_DEFAULT_DIGEST_LEN);
    GenericAgentInitialize(ctx, config);

    time_t t = SetReferenceTime();
    UpdateTimeClasses(ctx, t);
    SanitizeEnvironment();

    THIS_AGENT_TYPE = config->agent_type;
    LoggingSetAgentType(CF_AGENTTYPES[config->agent_type],
                        config->agent_type == AGENT_TYPE_AGENT);
    EvalContextClassPutHard(ctx, CF_AGENTTYPES[config->agent_type], "cfe_internal,source=agent");

    DetectEnvironment(ctx);

    EvalContextHeapPersistentLoadAll(ctx);
    LoadSystemConstants(ctx);

    if (config->agent_type == AGENT_TYPE_AGENT && config->agent_specific.agent.bootstrap_policy_server)
    {
        if (!RemoveAllExistingPolicyInInputs(GetInputDir()))
        {
            Log(LOG_LEVEL_ERR, "Error removing existing input files prior to bootstrap");
            exit(EXIT_FAILURE);
        }

        if (!WriteBuiltinFailsafePolicy(GetInputDir()))
        {
            Log(LOG_LEVEL_ERR, "Error writing builtin failsafe to inputs prior to bootstrap");
            exit(EXIT_FAILURE);
        }

        bool am_policy_server = false;
        {
            const char *canonified_bootstrap_policy_server = CanonifyName(config->agent_specific.agent.bootstrap_policy_server);
            am_policy_server = NULL != EvalContextClassGet(ctx, NULL, canonified_bootstrap_policy_server);
            {
                char policy_server_ipv4_class[CF_BUFSIZE];
                snprintf(policy_server_ipv4_class, CF_MAXVARSIZE, "ipv4_%s", canonified_bootstrap_policy_server);
                am_policy_server |= NULL != EvalContextClassGet(ctx, NULL, policy_server_ipv4_class);
            }

            if (am_policy_server)
            {
                Log(LOG_LEVEL_INFO, "Assuming role as policy server, with policy distribution point at %s", GetMasterDir());
                MarkAsPolicyServer(ctx);

                if (!MasterfileExists(GetMasterDir()))
                {
                    Log(LOG_LEVEL_ERR, "In order to bootstrap as a policy server, the file '%s/promises.cf' must exist.", GetMasterDir());
                    exit(EXIT_FAILURE);
                }
            }
            else
            {
                Log(LOG_LEVEL_INFO, "Not assuming role as policy server");
            }

            WriteAmPolicyHubFile(CFWORKDIR, am_policy_server);
        }

        WritePolicyServerFile(GetWorkDir(), config->agent_specific.agent.bootstrap_policy_server);
        SetPolicyServer(ctx, config->agent_specific.agent.bootstrap_policy_server);

        if (am_policy_server) //It makes sense to check HA status only on policy hub.
        {
            CheckAndSetHAState(GetWorkDir(), ctx);
        }

        /* FIXME: Why it is called here? Can't we move both invocations to before if? */
        UpdateLastPolicyUpdateTime(ctx);
        Log(LOG_LEVEL_INFO, "Bootstrapping to '%s'", POLICY_SERVER);
    }
    else
    {
        char *existing_policy_server = ReadPolicyServerFile(GetWorkDir());
        if (existing_policy_server)
        {
            Log(LOG_LEVEL_VERBOSE, "This agent is bootstrapped to '%s'", existing_policy_server);
            SetPolicyServer(ctx, existing_policy_server);
            free(existing_policy_server);
            UpdateLastPolicyUpdateTime(ctx);
        }
        else
        {
            Log(LOG_LEVEL_VERBOSE, "This agent is not bootstrapped - can't find policy_server.dat in %s", GetWorkDir());
            return;
        }

        if (GetAmPolicyHub(GetWorkDir()))
        {
            MarkAsPolicyServer(ctx);

            /* Should this go in MarkAsPolicyServer() ? */
            CheckAndSetHAState(GetWorkDir(), ctx);
        }
    }
}