Example #1
0
void CheckAutoBootstrap()
{
    struct stat sb;
    char name[CF_BUFSIZE];
    int repaired = false, have_policy = false, am_appliance = false;

    CfOut(cf_cmdout, "", "** CFEngine BOOTSTRAP probe initiated");

    PrintVersionBanner("CFEngine");
    printf("\n");

    printf(" -> This host is: %s\n", VSYSNAME.nodename);
    printf(" -> Operating System Type is %s\n", VSYSNAME.sysname);
    printf(" -> Operating System Release is %s\n", VSYSNAME.release);
    printf(" -> Architecture = %s\n", VSYSNAME.machine);
    printf(" -> Internal soft-class is %s\n", CLASSTEXT[VSYSTEMHARDCLASS]);

    if (!BootstrapAllowed())
    {
        FatalError(" !! Not enough privileges to bootstrap CFEngine");
    }

    snprintf(name, CF_BUFSIZE - 1, "%s/inputs/failsafe.cf", CFWORKDIR);
    MapName(name);

    if (cfstat(name, &sb) == -1)
    {
        CreateFailSafe(name);
        repaired = true;
    }

    snprintf(name, CF_BUFSIZE - 1, "%s/inputs/promises.cf", CFWORKDIR);
    MapName(name);

    if (cfstat(name, &sb) == -1)
    {
        CfOut(cf_cmdout, "", " -> No previous policy has been cached on this host");
    }
    else
    {
        CfOut(cf_cmdout, "", " -> An existing policy was cached on this host in %s/inputs", CFWORKDIR);
        have_policy = true;
    }

    if (strlen(POLICY_SERVER) > 0)
    {
        CfOut(cf_cmdout, "", " -> Assuming the policy distribution point at: %s:/var/cfengine/masterfiles\n",
              POLICY_SERVER);
    }
    else
    {
        if (have_policy)
        {
            CfOut(cf_cmdout, "",
                  " -> No policy distribution host was discovered - it might be contained in the existing policy, otherwise this will function autonomously\n");
        }
        else if (repaired)
        {
            CfOut(cf_cmdout, "", " -> No policy distribution host was defined - use --policy-server to set one\n");
        }
    }

    printf(" -> Attempting to initiate promised autonomous services...\n\n");

    am_appliance = IsDefinedClass(CanonifyName(POLICY_SERVER), NULL);
    snprintf(name, CF_MAXVARSIZE, "ipv4_%s", CanonifyName(POLICY_SERVER));
    am_appliance |= IsDefinedClass(name, NULL);

    if (strlen(POLICY_SERVER) == 0)
    {
        am_appliance = false;
    }

    snprintf(name, sizeof(name), "%s/state/am_policy_hub", CFWORKDIR);
    MapName(name);

    if (am_appliance)
    {
        HardClass("am_policy_hub");
        printf
        (" ** This host recognizes itself as a CFEngine Policy Hub, with policy distribution and knowledge base.\n");
        printf
        (" -> The system is now converging. Full initialisation and self-analysis could take up to 30 minutes\n\n");
        creat(name, 0600);
    }
    else
    {
        unlink(name);
    }
}
Example #2
0
void CheckAutoBootstrap(EvalContext *ctx)
{
    struct stat sb;
    char name[CF_BUFSIZE];
    int have_policy = false, am_appliance = false;

    printf("** CFEngine BOOTSTRAP probe initiated\n");

    PrintVersion();
    printf("\n");

    printf(" -> This host is: %s\n", VSYSNAME.nodename);
    printf(" -> Operating System Type is %s\n", VSYSNAME.sysname);
    printf(" -> Operating System Release is %s\n", VSYSNAME.release);
    printf(" -> Architecture = %s\n", VSYSNAME.machine);
    printf(" -> Internal soft-class is %s\n", CLASSTEXT[VSYSTEMHARDCLASS]);

    if (!BootstrapAllowed())
    {
        FatalError(ctx, " !! Not enough privileges to bootstrap CFEngine");
    }

    snprintf(name, CF_BUFSIZE - 1, "%s/inputs/failsafe.cf", CFWORKDIR);
    MapName(name);

    CreateFailSafe(name);

    snprintf(name, CF_BUFSIZE - 1, "%s/inputs/promises.cf", CFWORKDIR);
    MapName(name);

    if (cfstat(name, &sb) == -1)
    {
        printf(" -> No previous policy has been cached on this host\n");
    }
    else
    {
        printf(" -> An existing policy was cached on this host in %s/inputs\n", CFWORKDIR);
        have_policy = true;
    }

    if (strlen(POLICY_SERVER) > 0)
    {
        printf(" -> Assuming the policy distribution point at: %s:%s/masterfiles\n", CFWORKDIR,
              POLICY_SERVER);
    }
    else
    {
        if (have_policy)
        {
            printf(" -> No policy distribution host was discovered - it might be contained in the existing policy, otherwise this will function autonomously\n");
        }
        else
        {
            printf(" -> No policy distribution host was defined - use --policy-server to set one\n");
        }
    }

    printf(" -> Attempting to initiate promised autonomous services...\n\n");

    am_appliance = IsDefinedClass(ctx, CanonifyName(POLICY_SERVER), NULL);
    snprintf(name, CF_MAXVARSIZE, "ipv4_%s", CanonifyName(POLICY_SERVER));
    am_appliance |= IsDefinedClass(ctx, name, NULL);

    if (strlen(POLICY_SERVER) == 0)
    {
        am_appliance = false;
    }

    snprintf(name, sizeof(name), "%s/state/am_policy_hub", CFWORKDIR);
    MapName(name);

    if (am_appliance)
    {
        EvalContextHeapAddHard(ctx, "am_policy_hub");
        printf
            (" ** This host recognizes itself as a CFEngine policy server, with policy distribution from %s/masterfiles.\n", WORKDIR);
        creat(name, 0600);
    }
    else
    {
        unlink(name);
    }

}