Exemple #1
0
void TestExpandPromise(const ReportContext *report_context)
{
    Promise pp = { 0 }, *pcopy;

    printf("%d. Testing promise duplication and expansion\n", ++NR);
    pp.promiser = "the originator";
    pp.promisee = (Rval) {
        "the recipient", CF_SCALAR
    };
    pp.classes = "upper classes";
    pp.offset.line = 12;
    pp.audit = NULL;
    pp.conlist = NULL;

    pp.bundletype = "bundle_type";
    pp.bundle = "test_bundle";
    pp.ref = "commentary";
    pp.agentsubtype = NULL;
    pp.done = false;
    pp.next = NULL;
    pp.cache = NULL;
    pp.inode_cache = NULL;
    pp.this_server = NULL;
    pp.donep = &(pp.done);
    pp.conn = NULL;

    ConstraintAppendToPromise(&pp, "lval1", (Rval) {
        xstrdup("rval1"), CF_SCALAR
    }, "lower classes1", false);
    ConstraintAppendToPromise(&pp, "lval2", (Rval) {
        xstrdup("rval2"), CF_SCALAR
    }, "lower classes2", false);

//getuid ConstraintAppendToPromise(&pp,"lval2",,CF_SCALAR,"lower classes2");

    /* Now copy promise and delete */

    pcopy = DeRefCopyPromise("diagnostic-scope", &pp);
    if (VERBOSE || DEBUG)
    {
        printf("-----------------------------------------------------------\n");
        printf("Raw test promises\n\n");
        ShowPromise(report_context, REPORT_OUTPUT_TYPE_TEXT, &pp, 4);
        ShowPromise(report_context, REPORT_OUTPUT_TYPE_HTML, &pp, 4);

        ShowPromise(report_context, REPORT_OUTPUT_TYPE_TEXT, pcopy, 6);
        ShowPromise(report_context, REPORT_OUTPUT_TYPE_HTML, pcopy, 6);
    }
    DeletePromise(pcopy);
}
Exemple #2
0
void TestExpandVariables(const ReportContext *report_context)
{
    Promise pp = { 0 }, *pcopy;
    Rlist *args, *listvars = NULL, *scalarvars = NULL;
    Constraint *cp;
    FnCall *fp;

    strcpy(CFWORKDIR, GetWorkDir());
    MapName(CFWORKDIR);

    /* Still have diagnostic scope */
    NewScope("control_common");

    printf("%d. Testing variable expansion\n", ++NR);
    pp.promiser = "the originator";
    pp.promisee = (Rval) {
        "the recipient with $(two)", CF_SCALAR
    };
    pp.classes = "proletariat";
    pp.offset.line = 12;
    pp.audit = NULL;
    pp.conlist = NULL;
    pp.agentsubtype = "none";

    pp.bundletype = "bundle_type";
    pp.bundle = "test_bundle";
    pp.ref = "commentary";
    pp.agentsubtype = xstrdup("files");
    pp.done = false;
    pp.next = NULL;
    pp.cache = NULL;
    pp.inode_cache = NULL;
    pp.this_server = NULL;
    pp.donep = &(pp.done);
    pp.conn = NULL;

    args = SplitStringAsRList("$(administrator)", ',');
    fp = NewFnCall("getuid", args);

    ConstraintAppendToPromise(&pp, "lval1", (Rval) {
        xstrdup("@(one)"), CF_SCALAR
    }, "lower classes1", false);
    ConstraintAppendToPromise(&pp, "lval2", (Rval) {
        xstrdup("$(four)"), CF_SCALAR
    }, "upper classes1", false);
    ConstraintAppendToPromise(&pp, "lval3", (Rval) {
        fp, CF_FNCALL
    }, "upper classes2", false);

    /* Now copy promise and delete */

    pcopy = DeRefCopyPromise("diagnostic", &pp);

    MapIteratorsFromRval("diagnostic", &scalarvars, &listvars, (Rval) {
        pcopy->promiser, CF_SCALAR
    }, NULL);

    if (pcopy->promisee.item != NULL)
    {
        MapIteratorsFromRval("diagnostic", &scalarvars, &listvars, pp.promisee, NULL);
    }

    for (cp = pcopy->conlist; cp != NULL; cp = cp->next)
    {
        MapIteratorsFromRval("diagnostic", &scalarvars, &listvars, cp->rval, NULL);
    }

    ExpandPromiseAndDo(cf_common, "diagnostic", pcopy, scalarvars, listvars, NULL, report_context);
    /* No cleanup */
}
Exemple #3
0
static void Apoptosis()
{
    Promise pp = { 0 };
    Rlist *signals = NULL, *owners = NULL;
    char mypid[32];
    static char promiser_buf[CF_SMALLBUF];

#if defined(__CYGWIN__) || defined(__MINGW32__)
    return;
#endif

    CfOut(cf_verbose, "", " !! Programmed pruning of the scheduler cluster");

#ifdef MINGW
    snprintf(promiser_buf, sizeof(promiser_buf), "cf-execd");     // using '\' causes regexp problems
#else
    snprintf(promiser_buf, sizeof(promiser_buf), "%s/bin/cf-execd", CFWORKDIR);
#endif

    pp.promiser = promiser_buf;
    pp.promisee = (Rval) {"cfengine", CF_SCALAR};
    pp.classes = "any";
    pp.offset.line = 0;
    pp.audit = NULL;
    pp.conlist = NULL;

    pp.bundletype = "agent";
    pp.bundle = "exec_apoptosis";
    pp.ref = "Programmed death";
    pp.agentsubtype = "processes";
    pp.done = false;
    pp.next = NULL;
    pp.cache = NULL;
    pp.inode_cache = NULL;
    pp.this_server = NULL;
    pp.donep = &(pp.done);
    pp.conn = NULL;

    GetCurrentUserName(mypid, 31);

    PrependRlist(&signals, "term", CF_SCALAR);
    PrependRlist(&owners, mypid, CF_SCALAR);

    ConstraintAppendToPromise(&pp, "signals", (Rval) {signals, CF_LIST}, "any", false);
    ConstraintAppendToPromise(&pp, "process_select", (Rval) {xstrdup("true"), CF_SCALAR}, "any", false);
    ConstraintAppendToPromise(&pp, "process_owner", (Rval) {owners, CF_LIST}, "any", false);
    ConstraintAppendToPromise(&pp, "ifelapsed", (Rval) {xstrdup("0"), CF_SCALAR}, "any", false);
    ConstraintAppendToPromise(&pp, "process_count", (Rval) {xstrdup("true"), CF_SCALAR}, "any", false);
    ConstraintAppendToPromise(&pp, "match_range", (Rval) {xstrdup("0,2"), CF_SCALAR}, "any", false);
    ConstraintAppendToPromise(&pp, "process_result", (Rval) {xstrdup("process_owner.process_count"), CF_SCALAR}, "any", false);

    CfOut(cf_verbose, "", " -> Looking for cf-execd processes owned by %s", mypid);

    if (LoadProcessTable(&PROCESSTABLE))
    {
        VerifyProcessesPromise(&pp);
    }

    DeleteItemList(PROCESSTABLE);

    if (pp.conlist)
    {
        DeleteConstraintList(pp.conlist);
    }

    CfOut(cf_verbose, "", " !! Pruning complete");
}
static void DoVerifyServices(Attributes a, Promise *pp, const ReportContext *report_context)
{
    FnCall *default_bundle = NULL;
    Rlist *args = NULL;

// Need to set up the default service pack to eliminate syntax

    if (GetConstraintValue("service_bundle", pp, CF_SCALAR) == NULL)
    {
        switch (a.service.service_policy)
        {
        case cfsrv_start:
            AppendRlist(&args, pp->promiser, CF_SCALAR);
            AppendRlist(&args, "start", CF_SCALAR);
            break;

        case cfsrv_restart:
            AppendRlist(&args, pp->promiser, CF_SCALAR);
            AppendRlist(&args, "restart", CF_SCALAR);
            break;

        case cfsrv_reload:
            AppendRlist(&args, pp->promiser, CF_SCALAR);
            AppendRlist(&args, "restart", CF_SCALAR);
            break;
            
        case cfsrv_stop:
        case cfsrv_disable:
        default:
            AppendRlist(&args, pp->promiser, CF_SCALAR);
            AppendRlist(&args, "stop", CF_SCALAR);
            break;

        }

        default_bundle = NewFnCall("default:standard_services", args);

        ConstraintAppendToPromise(pp, "service_bundle", (Rval) {default_bundle, CF_FNCALL}, "any", false);
        a.havebundle = true;
    }

// Set $(this.service_policy) for flexible bundle adaptation

    switch (a.service.service_policy)
    {
    case cfsrv_start:
        NewScalar("this", "service_policy", "start", cf_str);
        break;

    case cfsrv_restart:
        NewScalar("this", "service_policy", "restart", cf_str);
        break;

    case cfsrv_reload:
        NewScalar("this", "service_policy", "reload", cf_str);
        break;
        
    case cfsrv_stop:
    case cfsrv_disable:
    default:
        NewScalar("this", "service_policy", "stop", cf_str);
        break;
    }

    if (default_bundle && GetBundle(PolicyFromPromise(pp), default_bundle->name, "agent") == NULL)
    {
        cfPS(cf_inform, CF_FAIL, "", pp, a, " !! Service %s could not be invoked successfully\n", pp->promiser);
    }

    if (!DONTDO)
    {
        VerifyMethod("service_bundle", a, pp, report_context);  // Send list of classes to set privately?
    }
}