Exemplo n.º 1
0
void ShowAssoc(CfAssoc *cp)
{
    printf("ShowAssoc: lval = %s\n", cp->lval);
    printf("ShowAssoc: rval = ");
    ShowRval(stdout, cp->rval);
    printf("\nShowAssoc: dtype = %s\n", CF_DATATYPES[cp->dtype]);
}
Exemplo n.º 2
0
static void PrintVariablesInScope(FILE *fp, Scope *scope)
{
    HashIterator i = HashIteratorInit(scope->hashtable);
    CfAssoc *assoc;

    while ((assoc = HashIteratorNext(&i)))
    {
        fprintf(fp, "%8s %c %s = ", CF_DATATYPES[assoc->dtype], assoc->rval.rtype, assoc->lval);
        ShowRval(fp, assoc->rval);
        fprintf(fp, "\n");
    }
}
Exemplo n.º 3
0
Arquivo: args.c Projeto: fbettag/core
void ArgTemplate(FnCall *fp, const FnCallArg *argtemplate, Rlist *realargs)
{
    int argnum, i;
    Rlist *rp = fp->args;
    char id[CF_BUFSIZE], output[CF_BUFSIZE];
    const FnCallType *fn = FindFunction(fp->name);

    snprintf(id, CF_MAXVARSIZE, "built-in FnCall %s-arg", fp->name);

    for (argnum = 0; rp != NULL && argtemplate[argnum].pattern != NULL; argnum++)
    {
        if (rp->type != CF_FNCALL)
        {
            /* Nested functions will not match to lval so don't bother checking */
            CheckConstraintTypeMatch(id, (Rval) {rp->item, rp->type}, argtemplate[argnum].dtype, argtemplate[argnum].pattern, 1);
        }

        rp = rp->next;
    }

    if (argnum != RlistLen(realargs) && !fn->varargs)
    {
        snprintf(output, CF_BUFSIZE, "Argument template mismatch handling function %s(", fp->name);
        ReportError(output);
        ShowRlist(stderr, realargs);
        fprintf(stderr, ")\n");

        for (i = 0, rp = realargs; i < argnum; i++)
        {
            printf("  arg[%d] range %s\t", i, argtemplate[i].pattern);
            if (rp != NULL)
            {
                ShowRval(stdout, (Rval) {rp->item, rp->type});
                rp = rp->next;
            }
            else
            {
                printf(" ? ");
            }
            printf("\n");
        }

        FatalError("Bad arguments");
    }

    for (rp = realargs; rp != NULL; rp = rp->next)
    {
        CfDebug("finalarg: %s\n", (char *) rp->item);
    }

    CfDebug("End ArgTemplate\n");
}
Exemplo n.º 4
0
void PromiseBanner(Promise *pp)
{
    char handle[CF_MAXVARSIZE];
    const char *sp;

    if ((sp = GetConstraintValue("handle", pp, RVAL_TYPE_SCALAR)) || (sp = PromiseID(pp)))
    {
        strncpy(handle, sp, CF_MAXVARSIZE - 1);
    }
    else
    {
        strcpy(handle, "(enterprise only)");
    }

    CfOut(cf_verbose, "", "\n");
    CfOut(cf_verbose, "", "    .........................................................\n");

    if (VERBOSE || DEBUG)
    {
        printf("%s>     Promise's handle: %s\n", VPREFIX, handle);
        printf("%s>     Promise made by: \"%s\"", VPREFIX, pp->promiser);
    }

    if (pp->promisee.item)
    {
        if (VERBOSE)
        {
            printf("\n%s>     Promise made to (stakeholders): ", VPREFIX);
            ShowRval(stdout, pp->promisee);
        }
    }

    if (VERBOSE)
    {
        printf("\n");
    }

    if (pp->ref)
    {
        CfOut(cf_verbose, "", "\n");
        CfOut(cf_verbose, "", "    Comment:  %s\n", pp->ref);
    }

    CfOut(cf_verbose, "", "    .........................................................\n");
    CfOut(cf_verbose, "", "\n");
}
Exemplo n.º 5
0
void PromiseBanner(struct Promise *pp)

{ char *sp,handle[CF_MAXVARSIZE];

if ((sp = GetConstraint("handle",pp,CF_SCALAR)) || (sp = PromiseID(pp)))
   {
   strncpy(handle,sp,CF_MAXVARSIZE-1);
   }
else
   {
   strcpy(handle,"(enterprise only)");
   }

CfOut(cf_verbose,"","\n");
CfOut(cf_verbose,"","    .........................................................\n");

if (VERBOSE||DEBUG)
   {
   printf ("%s>     Promise handle: %s\n",VPREFIX,handle);
   printf ("%s>     Promise made by: %s",VPREFIX,pp->promiser);
   }

if (pp->promisee)
   {
   if (VERBOSE)
      {
      printf(" -> ");
      ShowRval(stdout,pp->promisee,pp->petype);
      }
   }

if (VERBOSE)
   {
   printf("\n");
   }

if (pp->ref)
   {
   CfOut(cf_verbose,"","\n");
   CfOut(cf_verbose,"","    Comment:  %s\n",pp->ref);
   }

CfOut(cf_verbose,"","    .........................................................\n");
CfOut(cf_verbose,"","\n");
}
Exemplo n.º 6
0
static void PrintVariablesInScopeHtml(FILE *fp, Scope *scope)
{
    HashIterator i = HashIteratorInit(scope->hashtable);
    CfAssoc *assoc;

    fprintf(fp, "<table class=border width=600>\n");
    fprintf(fp, "<tr><th>dtype</th><th>rtype</th><th>identifier</th><th>Rvalue</th></tr>\n");

    while ((assoc = HashIteratorNext(&i)))
    {
        fprintf(fp, "<tr><th>%8s</th><td> %c</td><td> %s</td><td> ", CF_DATATYPES[assoc->dtype], assoc->rval.rtype,
                assoc->lval);
        ShowRval(fp, assoc->rval);
        fprintf(fp, "</td></tr>\n");
    }

    fprintf(fp, "</table>\n");
}
Exemplo n.º 7
0
void ShowBody(Body *body, int indent)
{
    Rlist *rp;
    Constraint *cp;

    fprintf(FREPORT_TXT, "%s body for type %s", body->name, body->type);
    fprintf(FREPORT_HTML, " %s%s%s ", CFH[cfx_blocktype][cfb], body->type, CFH[cfx_blocktype][cfe]);

    fprintf(FREPORT_HTML, "%s%s%s", CFH[cfx_blockid][cfb], body->name, CFH[cfx_blockid][cfe]);

    if (body->args == NULL)
    {
        fprintf(FREPORT_HTML, "%s(no parameters)%s\n", CFH[cfx_args][cfb], CFH[cfx_args][cfe]);
        fprintf(FREPORT_TXT, "(no parameters)\n");
    }
    else
    {
        fprintf(FREPORT_HTML, "(");
        fprintf(FREPORT_TXT, "\n");

        for (rp = body->args; rp != NULL; rp = rp->next)
        {
            if (rp->type != CF_SCALAR)
            {
                FatalError("ShowBody - non-scalar parameter container");
            }

            fprintf(FREPORT_HTML, "%s%s%s,\n", CFH[cfx_args][cfb], (char *) rp->item, CFH[cfx_args][cfe]);
            Indent(indent);
            fprintf(FREPORT_TXT, "arg %s\n", (char *) rp->item);
        }

        fprintf(FREPORT_HTML, ")");
        fprintf(FREPORT_TXT, "\n");
    }

    Indent(indent);
    fprintf(FREPORT_TXT, "{\n");

    for (cp = body->conlist; cp != NULL; cp = cp->next)
    {
        fprintf(FREPORT_HTML, "%s.....%s%s => ", CFH[cfx_lval][cfb], cp->lval, CFH[cfx_lval][cfe]);
        Indent(indent);
        fprintf(FREPORT_TXT, "%s => ", cp->lval);

        fprintf(FREPORT_HTML, "\'%s", CFH[cfx_rval][cfb]);

        ShowRval(FREPORT_HTML, cp->rval);       /* literal */
        ShowRval(FREPORT_TXT, cp->rval);        /* literal */

        fprintf(FREPORT_HTML, "\'%s", CFH[cfx_rval][cfe]);

        if (cp->classes != NULL)
        {
            fprintf(FREPORT_HTML, " if sub-body context %s%s%s\n", CFH[cfx_class][cfb], cp->classes,
                    CFH[cfx_class][cfe]);
            fprintf(FREPORT_TXT, " if sub-body context %s\n", cp->classes);
        }
        else
        {
            fprintf(FREPORT_TXT, "\n");
        }
    }

    Indent(indent);
    fprintf(FREPORT_TXT, "}\n");
}
Exemplo n.º 8
0
void ShowPromiseInReport(const char *version, Promise *pp, int indent)
{
    Constraint *cp;
    Body *bp;
    Rlist *rp;
    FnCall *fp;

    fprintf(FREPORT_HTML, "%s\n", CFH[cfx_line][cfb]);
    fprintf(FREPORT_HTML, "%s\n", CFH[cfx_promise][cfb]);
    fprintf(FREPORT_HTML, "Promise type is %s%s%s, ", CFH[cfx_subtype][cfb], pp->agentsubtype, CFH[cfx_subtype][cfe]);
    fprintf(FREPORT_HTML, "<a href=\"#class_context\">context</a> is %s%s%s <br><hr>\n\n", CFH[cfx_class][cfb],
            pp->classes, CFH[cfx_class][cfe]);

    if (pp->promisee.item)
    {
        fprintf(FREPORT_HTML, "Resource object %s\'%s\'%s promises %s (about %s) to", CFH[cfx_object][cfb],
                pp->promiser, CFH[cfx_object][cfe], CFH[cfx_object][cfb], pp->agentsubtype);
        ShowRval(FREPORT_HTML, pp->promisee);
        fprintf(FREPORT_HTML, "%s\n\n", CFH[cfx_object][cfe]);
    }
    else
    {
        fprintf(FREPORT_HTML,
                "Resource object %s\'%s\'%s make the promise to default promisee 'cf-%s' (about %s)...\n\n",
                CFH[cfx_object][cfb], pp->promiser, CFH[cfx_object][cfe], pp->bundletype, pp->agentsubtype);
    }

    Indent(indent);
    if (pp->promisee.item != NULL)
    {
        fprintf(FREPORT_TXT, "%s promise by \'%s\' -> ", pp->agentsubtype, pp->promiser);
        ShowRval(FREPORT_TXT, pp->promisee);
        fprintf(FREPORT_TXT, " if context is %s\n\n", pp->classes);
    }
    else
    {
        fprintf(FREPORT_TXT, "%s promise by \'%s\' (implicit) if context is %s\n\n", pp->agentsubtype, pp->promiser,
                pp->classes);
    }

    for (cp = pp->conlist; cp != NULL; cp = cp->next)
    {
        fprintf(FREPORT_HTML, "%s%s%s => ", CFH[cfx_lval][cfb], cp->lval, CFH[cfx_lval][cfe]);
        Indent(indent + 3);
        fprintf(FREPORT_TXT, "%10s => ", cp->lval);

        switch (cp->rval.rtype)
        {
        case CF_SCALAR:
            if ((bp = IsBody(BODIES, (char *) cp->rval.item)))
            {
                ShowBody(bp, 15);
            }
            else
            {
                fprintf(FREPORT_HTML, "%s", CFH[cfx_rval][cfb]);
                ShowRval(FREPORT_HTML, cp->rval);       /* literal */
                fprintf(FREPORT_HTML, "%s", CFH[cfx_rval][cfe]);

                ShowRval(FREPORT_TXT, cp->rval);        /* literal */
            }
            break;

        case CF_LIST:

            rp = (Rlist *) cp->rval.item;
            fprintf(FREPORT_HTML, "%s", CFH[cfx_rval][cfb]);
            ShowRlist(FREPORT_HTML, rp);
            fprintf(FREPORT_HTML, "%s", CFH[cfx_rval][cfe]);
            ShowRlist(FREPORT_TXT, rp);
            break;

        case CF_FNCALL:
            fp = (FnCall *) cp->rval.item;

            if ((bp = IsBody(BODIES, fp->name)))
            {
                ShowBody(bp, 15);
            }
            else
            {
                ShowRval(FREPORT_HTML, cp->rval);       /* literal */
                ShowRval(FREPORT_TXT, cp->rval);        /* literal */
            }
            break;
        }

        if (cp->rval.rtype != CF_FNCALL)
        {
            Indent(indent);
            fprintf(FREPORT_HTML,
                    " , if body <a href=\"#class_context\">context</a> <span class=\"context\">%s</span>\n",
                    cp->classes);
            fprintf(FREPORT_TXT, " if body context %s\n", cp->classes);
        }
    }

    if (pp->audit)
    {
        Indent(indent);
        fprintf(FREPORT_HTML,
                "<p><small>Promise (version %s) belongs to bundle <b>%s</b> (type %s) in \'<i>%s</i>\' near line %zu</small></p>\n",
                version, pp->bundle, pp->bundletype, pp->audit->filename, pp->offset.line);
    }

    fprintf(FREPORT_HTML, "%s\n", CFH[cfx_promise][cfe]);
    fprintf(FREPORT_HTML, "%s\n", CFH[cfx_line][cfe]);

    if (pp->audit)
    {
        Indent(indent);
        fprintf(FREPORT_TXT, "Promise (version %s) belongs to bundle \'%s\' (type %s) in file \'%s\' near line %zu\n",
                version, pp->bundle, pp->bundletype, pp->audit->filename, pp->offset.line);
        fprintf(FREPORT_TXT, "\n\n");
    }
    else
    {
        Indent(indent);
        fprintf(FREPORT_TXT, "Promise (version %s) belongs to bundle \'%s\' (type %s) near line %zu\n\n", version,
                pp->bundle, pp->bundletype, pp->offset.line);
    }
}
Exemplo n.º 9
0
Arquivo: vars.c Projeto: rdparker/core
enum cfdatatype GetVariable(const char *scope, const char *lval, Rval *returnv)
{
    Scope *ptr = NULL;
    char scopeid[CF_MAXVARSIZE], vlval[CF_MAXVARSIZE], sval[CF_MAXVARSIZE];
    char expbuf[CF_EXPANDSIZE];
    CfAssoc *assoc;

    CfDebug("\nGetVariable(%s,%s) type=(to be determined)\n", scope, lval);

    if (lval == NULL)
    {
        *returnv = (Rval) {NULL, CF_SCALAR};
        return cf_notype;
    }

    if (!IsExpandable(lval))
    {
        strncpy(sval, lval, CF_MAXVARSIZE - 1);
    }
    else
    {
        if (ExpandScalar(lval, expbuf))
        {
            strncpy(sval, expbuf, CF_MAXVARSIZE - 1);
        }
        else
        {
            /* C type system does not allow us to express the fact that returned
               value may contain immutable string. */
            *returnv = (Rval) {(char *) lval, CF_SCALAR};
            CfDebug("Couldn't expand array-like variable (%s) due to undefined dependencies\n", lval);
            return cf_notype;
        }
    }

    if (IsQualifiedVariable(sval))
    {
        scopeid[0] = '\0';
        sscanf(sval, "%[^.].%s", scopeid, vlval);
        CfDebug("Variable identifier %s is prefixed with scope id %s\n", vlval, scopeid);
        ptr = GetScope(scopeid);
    }
    else
    {
        strlcpy(vlval, sval, sizeof(vlval));
        strlcpy(scopeid, scope, sizeof(scopeid));
    }

    CfDebug("Looking for %s.%s\n", scopeid, vlval);

    if (ptr == NULL)
    {
        /* Assume current scope */
        strcpy(vlval, lval);
        ptr = GetScope(scopeid);
    }

    if (ptr == NULL)
    {
        CfDebug("Scope for variable \"%s.%s\" does not seem to exist\n", scope, lval);
        /* C type system does not allow us to express the fact that returned
           value may contain immutable string. */
        *returnv = (Rval) {(char *) lval, CF_SCALAR};
        return cf_notype;
    }

    CfDebug("GetVariable(%s,%s): using scope '%s' for variable '%s'\n", scopeid, vlval, ptr->scope, vlval);

    assoc = HashLookupElement(ptr->hashtable, vlval);

    if (assoc == NULL)
    {
        CfDebug("No such variable found %s.%s\n\n", scopeid, lval);
        /* C type system does not allow us to express the fact that returned
           value may contain immutable string. */
        *returnv = (Rval) {(char *) lval, CF_SCALAR};
        return cf_notype;
    }

    CfDebug("return final variable type=%s, value={\n", CF_DATATYPES[assoc->dtype]);

    if (DEBUG)
    {
        ShowRval(stdout, assoc->rval);
    }
    CfDebug("}\n");

    *returnv = assoc->rval;
    return assoc->dtype;
}
Exemplo n.º 10
0
Arquivo: syntax.c Projeto: dnaeon/core
void CheckSelection(char *type, char *name, char *lval, Rval rval)
{
    int lmatch = false;
    int i, j, k, l;
    SubTypeSyntax *ss;
    const BodySyntax *bs, *bs2;
    char output[CF_BUFSIZE];

    CfDebug("CheckSelection(%s,%s,", type, lval);

    if (DEBUG)
    {
        ShowRval(stdout, rval);
    }

    CfDebug(")\n");

/* Check internal control bodies etc */

    for (i = 0; CF_ALL_BODIES[i].subtype != NULL; i++)
    {
        if (strcmp(CF_ALL_BODIES[i].subtype, name) == 0 && strcmp(type, CF_ALL_BODIES[i].btype) == 0)
        {
            CfDebug("Found matching a body matching (%s,%s)\n", type, name);

            bs = CF_ALL_BODIES[i].bs;

            for (l = 0; bs[l].lval != NULL; l++)
            {
                if (strcmp(lval, bs[l].lval) == 0)
                {
                    CfDebug("Matched syntatically correct body (lval) item = (%s)\n", lval);

                    if (bs[l].dtype == cf_body)
                    {
                        CfDebug("Constraint syntax ok, but definition of body is elsewhere\n");
                        return;
                    }
                    else if (bs[l].dtype == cf_bundle)
                    {
                        CfDebug("Constraint syntax ok, but definition of bundle is elsewhere\n");
                        return;
                    }
                    else
                    {
                        CheckConstraintTypeMatch(lval, rval, bs[l].dtype, (char *) (bs[l].range), 0);
                        return;
                    }
                }
            }

        }
    }

/* Now check the functional modules - extra level of indirection */

    for (i = 0; i < CF3_MODULES; i++)
    {
        CfDebug("Trying function module %d for matching lval %s\n", i, lval);

        if ((ss = CF_ALL_SUBTYPES[i]) == NULL)
        {
            continue;
        }

        for (j = 0; ss[j].subtype != NULL; j++)
        {
            if ((bs = ss[j].bs) == NULL)
            {
                continue;
            }

            CfDebug("\nExamining subtype %s\n", ss[j].subtype);

            for (l = 0; bs[l].range != NULL; l++)
            {
                if (bs[l].dtype == cf_body)
                {
                    bs2 = (const BodySyntax *) (bs[l].range);

                    if (bs2 == NULL || bs2 == (void *) CF_BUNDLE)
                    {
                        continue;
                    }

                    for (k = 0; bs2[k].dtype != cf_notype; k++)
                    {
                        /* Either module defined or common */

                        if (strcmp(ss[j].subtype, type) == 0 && strcmp(ss[j].subtype, "*") != 0)
                        {
                            snprintf(output, CF_BUFSIZE, "lval %s belongs to promise type \'%s:\' but this is '\%s\'\n",
                                     lval, ss[j].subtype, type);
                            ReportError(output);
                            return;
                        }

                        if (strcmp(lval, bs2[k].lval) == 0)
                        {
                            CfDebug("Matched\n");
                            CheckConstraintTypeMatch(lval, rval, bs2[k].dtype, (char *) (bs2[k].range), 0);
                            return;
                        }
                    }
                }
            }
        }
    }

    if (!lmatch)
    {
        snprintf(output, CF_BUFSIZE, "Constraint lvalue \"%s\" is not allowed in \'%s\' constraint body", lval, type);
        ReportError(output);
    }
}
Exemplo n.º 11
0
Arquivo: syntax.c Projeto: dnaeon/core
void CheckConstraint(char *type, char *name, char *lval, Rval rval, SubTypeSyntax ss)
{
    int lmatch = false;
    int i, l, allowed = false;
    const BodySyntax *bs;
    char output[CF_BUFSIZE];

    CfDebug("CheckConstraint(%s,%s,", type, lval);

    if (DEBUG)
    {
        ShowRval(stdout, rval);
    }

    CfDebug(")\n");

    if (ss.subtype != NULL)     /* In a bundle */
    {
        if (strcmp(ss.subtype, type) == 0)
        {
            CfDebug("Found type %s's body syntax\n", type);

            bs = ss.bs;

            for (l = 0; bs[l].lval != NULL; l++)
            {
                CfDebug("CMP-bundle # (%s,%s)\n", lval, bs[l].lval);

                if (strcmp(lval, bs[l].lval) == 0)
                {
                    /* If we get here we have found the lval and it is valid
                       for this subtype */

                    lmatch = true;
                    CfDebug("Matched syntatically correct bundle (lval,rval) item = (%s) to its rval\n", lval);

                    if (bs[l].dtype == cf_body)
                    {
                        CfDebug("Constraint syntax ok, but definition of body is elsewhere %s=%c\n", lval, rval.rtype);
                        PrependRlist(&BODYPARTS, rval.item, rval.rtype);
                        return;
                    }
                    else if (bs[l].dtype == cf_bundle)
                    {
                        CfDebug("Constraint syntax ok, but definition of relevant bundle is elsewhere %s=%c\n", lval,
                                rval.rtype);
                        PrependRlist(&SUBBUNDLES, rval.item, rval.rtype);
                        return;
                    }
                    else
                    {
                        CheckConstraintTypeMatch(lval, rval, bs[l].dtype, (char *) (bs[l].range), 0);
                        return;
                    }
                }
            }
        }
    }

/* Now check the functional modules - extra level of indirection
   Note that we only check body attributes relative to promise type.
   We can enter any promise types in any bundle, but only recognized
   types will be dealt with. */

    for (i = 0; CF_COMMON_BODIES[i].lval != NULL; i++)
    {
        CfDebug("CMP-common # %s,%s\n", lval, CF_COMMON_BODIES[i].lval);

        if (strcmp(lval, CF_COMMON_BODIES[i].lval) == 0)
        {
            CfDebug("Found a match for lval %s in the common constraint attributes\n", lval);
            return;
        }
    }

    for (i = 0; CF_COMMON_EDITBODIES[i].lval != NULL; i++)
    {
        CfDebug("CMP-common # %s,%s\n", lval, CF_COMMON_EDITBODIES[i].lval);

        if (strcmp(lval, CF_COMMON_EDITBODIES[i].lval) == 0)
        {
            CfDebug("Found a match for lval %s in the common edit constraint attributes\n", lval);
            return;
        }
    }

// Now check if it is in the common list...

    if (!lmatch || !allowed)
    {
        snprintf(output, CF_BUFSIZE, "Constraint lvalue \'%s\' is not allowed in bundle category \'%s\'", lval, type);
        ReportError(output);
    }
}
Exemplo n.º 12
0
static void KeepPromiseBundles(Policy *policy, GenericAgentConfig *config, const ReportContext *report_context)
{
    Bundle *bp;
    Rlist *rp, *params;
    FnCall *fp;
    char *name;
    Rval retval;
    int ok = true;

    if (config->bundlesequence)
    {
        CfOut(cf_inform, "", " >> Using command line specified bundlesequence");
        retval = (Rval) { config->bundlesequence, RVAL_TYPE_LIST };
    }
    else if (GetVariable("control_common", "bundlesequence", &retval) == DATA_TYPE_NONE)
    {
        // TODO: somewhat frenzied way of telling user about an error
        CfOut(cf_error, "", " !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        CfOut(cf_error, "", " !! No bundlesequence in the common control body");
        CfOut(cf_error, "", " !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        exit(1);
    }

    // TODO: should've been checked a long time ago, remove?
    if (retval.type != RVAL_TYPE_LIST)
    {
        FatalError("Promised bundlesequence was not a list");
    }

    for (rp = (Rlist *) retval.item; rp != NULL; rp = rp->next)
    {
        switch (rp->type)
        {
        case RVAL_TYPE_SCALAR:
            name = (char *) rp->item;
            params = NULL;

            if (strcmp(name, CF_NULL_VALUE) == 0)
            {
                continue;
            }

            break;
        case RVAL_TYPE_FNCALL:
            fp = (FnCall *) rp->item;
            name = (char *) fp->name;
            params = (Rlist *) fp->args;
            break;

        default:
            name = NULL;
            params = NULL;
            CfOut(cf_error, "", "Illegal item found in bundlesequence: ");
            ShowRval(stdout, (Rval) {rp->item, rp->type});
            printf(" = %c\n", rp->type);
            ok = false;
            break;
        }

        if (!config->ignore_missing_bundles)
        {
            if (!(PolicyGetBundle(policy, NULL, "agent", name) || (PolicyGetBundle(policy, NULL, "common", name))))
            {
                CfOut(cf_error, "", "Bundle \"%s\" listed in the bundlesequence was not found\n", name);
                ok = false;
            }
        }
    }

    if (!ok)
    {
        FatalError("Errors in agent bundles");
    }

    if (VERBOSE || DEBUG)
    {
        printf("%s> -> Bundlesequence => ", VPREFIX);
        ShowRval(stdout, retval);
        printf("\n");
    }

/* If all is okay, go ahead and evaluate */

    for (rp = (Rlist *) retval.item; rp != NULL; rp = rp->next)
    {
        switch (rp->type)
        {
        case RVAL_TYPE_FNCALL:
            fp = (FnCall *) rp->item;
            name = (char *) fp->name;
            params = (Rlist *) fp->args;
            break;
        default:
            name = (char *) rp->item;
            params = NULL;
            break;
        }

        if ((bp = PolicyGetBundle(policy, NULL, "agent", name)) || (bp = PolicyGetBundle(policy, NULL, "common", name)))
        {
            char ns[CF_BUFSIZE];
            snprintf(ns,CF_BUFSIZE,"%s_meta", name);
            NewScope(ns);

            SetBundleOutputs(bp->name);
            AugmentScope(bp->name, bp->ns, bp->args, params);
            BannerBundle(bp, params);
            THIS_BUNDLE = bp->name;
            DeletePrivateClassContext();        // Each time we change bundle
            ScheduleAgentOperations(bp, report_context);
            ResetBundleOutputs(bp->name);
        }
    }
}
Exemplo n.º 13
0
void KeepPromiseBundles()
    
{ struct Bundle *bp;
  struct Rlist *rp,*params;
  struct FnCall *fp;
  char rettype,*name;
  void *retval;
  int ok = true;

if (CBUNDLESEQUENCE)
   {
   CfOut(cf_inform,""," >> Using command line specified bundlesequence");
   retval = CBUNDLESEQUENCE;
   rettype = CF_LIST;
   }
else if (GetVariable("control_common","bundlesequence",&retval,&rettype) == cf_notype)
   {
   CfOut(cf_error,""," !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
   CfOut(cf_error,""," !! No bundlesequence in the common control body");
   CfOut(cf_error,""," !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
   exit(1);
   }

if (rettype != CF_LIST)
   {
   FatalError("Promised bundlesequence was not a list");
   }

for (rp = (struct Rlist *)retval; rp != NULL; rp=rp->next)
   {
   switch (rp->type)
      {
      case CF_SCALAR:
          name = (char *)rp->item;
          params = NULL;

          if (strcmp(name,CF_NULL_VALUE) == 0)
             {
             continue;
             }
          
          break;
      case CF_FNCALL:
          fp = (struct FnCall *)rp->item;
          name = (char *)fp->name;
          params = (struct Rlist *)fp->args;
          break;
          
      default:
          name = NULL;
          params = NULL;
          CfOut(cf_error,"","Illegal item found in bundlesequence: ");
          ShowRval(stdout,rp->item,rp->type);
          printf(" = %c\n",rp->type);
          ok = false;
          break;
      }

   if (!IGNORE_MISSING_BUNDLES)
      {
      if (!(GetBundle(name,"agent")||(GetBundle(name,"common"))))
         {
         CfOut(cf_error,"","Bundle \"%s\" listed in the bundlesequence was not found\n",name);
         ok = false;
         }
      }
   }

if (!ok)
   {
   FatalError("Errors in agent bundles");
   }

if (VERBOSE || DEBUG)
   {
   printf("%s> -> Bundlesequence => ",VPREFIX);
   ShowRval(stdout,retval,rettype);
   printf("\n");
   }

/* If all is okay, go ahead and evaluate */

for (rp = (struct Rlist *)retval; rp != NULL; rp=rp->next)
   {
   switch (rp->type)
      {
      case CF_FNCALL:
          fp = (struct FnCall *)rp->item;
          name = (char *)fp->name;
          params = (struct Rlist *)fp->args;
          break;
      default:
          name = (char *)rp->item;
          params = NULL;
          break;
      }

   if ((bp = GetBundle(name,"agent")) || (bp = GetBundle(name,"common")))
      {
      SetBundleOutputs(bp->name);
      AugmentScope(bp->name,bp->args,params);
      BannerBundle(bp,params);
      THIS_BUNDLE = bp->name;
      DeletePrivateClassContext(); // Each time we change bundle
      ScheduleAgentOperations(bp);
      ResetBundleOutputs(bp->name);
      }
   }
}
Exemplo n.º 14
0
static bool VerifyBundleSequence(enum cfagenttype agent)

{ struct Rlist *rp,*params;
  char rettype,*name;
  void *retval = NULL;
  int ok = true;
  struct FnCall *fp;

if ((THIS_AGENT_TYPE != cf_agent) && 
    (THIS_AGENT_TYPE != cf_know) && 
    (THIS_AGENT_TYPE != cf_common))
   {
   return true;
   }

if (CBUNDLESEQUENCE)
   {
   return true;
   }

if (GetVariable("control_common","bundlesequence",&retval,&rettype) == cf_notype)
   {
   CfOut(cf_error,""," !!! No bundlesequence in the common control body");
   return false;
   }

if (rettype != CF_LIST)
   {
   FatalError("Promised bundlesequence was not a list");
   }

if ((agent != cf_agent) && (agent != cf_common))
   {
   return true;
   }

for (rp = (struct Rlist *)retval; rp != NULL; rp=rp->next)
   {
   switch (rp->type)
      {
      case CF_SCALAR:
         name = (char *)rp->item;
         params = NULL;
         break;

      case CF_FNCALL:
         fp = (struct FnCall *)rp->item;
         name = (char *)fp->name;
         params = (struct Rlist *)fp->args;
         break;

      default:
         name = NULL;
         params = NULL;
         CfOut(cf_error,"","Illegal item found in bundlesequence: ");
         ShowRval(stdout,rp->item,rp->type);
         printf(" = %c\n",rp->type);
         ok = false;
         break;
      }

   if (strcmp(name,CF_NULL_VALUE) == 0)
      {
      continue;
      }

   if (!IGNORE_MISSING_BUNDLES && !GetBundle(name,NULL))
      {
      CfOut(cf_error,"","Bundle \"%s\" listed in the bundlesequence is not a defined bundle\n",name);
      ok = false;
      }
   }

return ok;
}
Exemplo n.º 15
0
static void KeepPromiseBundles()
{
    Bundle *bp;
    SubType *sp;
    Promise *pp;
    Rlist *rp, *params;
    FnCall *fp;
    char *name;
    Rval retval;
    int ok = true;
    enum typesequence type;

    if (GetVariable("control_common", "bundlesequence", &retval) == cf_notype)
    {
        CfOut(cf_error, "", " !! No bundlesequence in the common control body");
        exit(1);
    }

    for (rp = (Rlist *) retval.item; rp != NULL; rp = rp->next)
    {
        switch (rp->type)
        {
        case CF_SCALAR:
            name = (char *) rp->item;
            params = NULL;
            break;
        case CF_FNCALL:
            fp = (FnCall *) rp->item;
            name = (char *) fp->name;
            params = (Rlist *) fp->args;
            break;

        default:
            name = NULL;
            params = NULL;
            CfOut(cf_error, "", " !! Illegal item found in bundlesequence: ");
            ShowRval(stdout, (Rval) {rp->item, rp->type});
            printf(" = %c\n", rp->type);
            ok = false;
            break;
        }

        if (!(GetBundle(name, "knowledge") || (GetBundle(name, "common"))))
        {
            CfOut(cf_error, "", " !! Bundle \"%s\" listed in the bundlesequence was not found\n", name);
            ok = false;
        }
    }

    if (!ok)
    {
        FatalError("Errors in knowledge bundles");
    }

/* If all is okay, go ahead and evaluate */

    for (type = 0; TYPESEQUENCE[type] != NULL; type++)
    {
        for (rp = (Rlist *) retval.item; rp != NULL; rp = rp->next)
        {
            switch (rp->type)
            {
            case CF_FNCALL:
                fp = (FnCall *) rp->item;
                name = (char *) fp->name;
                params = (Rlist *) fp->args;
                break;
            default:
                name = (char *) rp->item;
                params = NULL;
                break;
            }

            if ((bp = GetBundle(name, "knowledge")) || (bp = GetBundle(name, "common")))
            {
                BannerBundle(bp, params);
                AugmentScope(bp->name, bp->args, params);
                DeletePrivateClassContext();    // Each time we change bundle      
            }

            if ((sp = GetSubTypeForBundle(TYPESEQUENCE[type], bp)) == NULL)
            {
                continue;
            }

            BannerSubType(bp->name, sp->name, 1);

            for (pp = sp->promiselist; pp != NULL; pp = pp->next)
            {
                ExpandPromise(cf_know, bp->name, pp, KeepKnowledgePromise);
            }
        }
    }
}