Example #1
0
File: unix.c Project: rdparker/core
int Unix_DoAllSignals(Item *siglist, Attributes a, Promise *pp)
{
    Item *ip;
    Rlist *rp;
    pid_t pid;
    int killed = false;

    CfDebug("DoSignals(%s)\n", pp->promiser);

    if (siglist == NULL)
    {
        return 0;
    }

    if (a.signals == NULL)
    {
        CfOut(cf_verbose, "", " -> No signals to send for %s\n", pp->promiser);
        return 0;
    }

    for (ip = siglist; ip != NULL; ip = ip->next)
    {
        pid = ip->counter;

        for (rp = a.signals; rp != NULL; rp = rp->next)
        {
            int signal = Signal2Int(rp->item);

            if (!DONTDO)
            {
                if (signal == SIGKILL || signal == SIGTERM)
                {
                    killed = true;
                }

                if (kill((pid_t) pid, signal) < 0)
                {
                    cfPS(cf_verbose, CF_FAIL, "kill", pp, a,
                         " !! Couldn't send promised signal \'%s\' (%d) to pid %jd (might be dead)\n", ScalarValue(rp),
                         signal, (intmax_t)pid);
                }
                else
                {
                    cfPS(cf_inform, CF_CHG, "", pp, a, " -> Signalled '%s' (%d) to process %jd (%s)\n",
                         ScalarValue(rp), signal, (intmax_t)pid, ip->name);
                }
            }
            else
            {
                CfOut(cf_error, "", " -> Need to keep signal promise \'%s\' in process entry %s",
                      ScalarValue(rp), ip->name);
            }
        }
    }

    return killed;
}
Example #2
0
static void test_last(void **state)
{
    Rlist *l = NULL;
    assert_true(RlistLast(l) == NULL);
    AppendRlist(&l, "a", CF_SCALAR);
    assert_string_equal("a", ScalarValue(RlistLast(l)));
    AppendRlist(&l, "b", CF_SCALAR);
    assert_string_equal("b", ScalarValue(RlistLast(l)));
    DeleteRlist(l);
}
Example #3
0
static int CheckRegistrySanity(Attributes a, Promise *pp)
{
    bool retval = true;

    ValidateRegistryPromiser(pp->promiser, a, pp);

    if ((a.database.operation) && (strcmp(a.database.operation, "create") == 0))
    {
        if (a.database.rows == NULL)
        {
            CfOut(cf_inform, "", "No row values promised for the MS registry database");
        }

        if (a.database.columns != NULL)
        {
            CfOut(cf_error, "", "Columns are only used to delete promised values for the MS registry database");
            retval = false;
        }
    }

    if ((a.database.operation)
        && ((strcmp(a.database.operation, "delete") == 0) || (strcmp(a.database.operation, "drop") == 0)))
    {
        if (a.database.columns == NULL)
        {
            CfOut(cf_inform, "", "No columns were promised deleted in the MS registry database");
        }

        if (a.database.rows != NULL)
        {
            CfOut(cf_error, "", "Rows cannot be deleted in the MS registry database, only entire columns");
            retval = false;
        }
    }

    for (Rlist *rp = a.database.rows; rp != NULL; rp = rp->next)
    {
        if (CountChar(ScalarValue(rp), ',') != 2)
        {
            CfOut(cf_error, "", "Registry row format should be NAME,REG_SZ,VALUE, not \"%s\"", ScalarValue(rp));
            retval = false;
        }
    }

    for (Rlist *rp = a.database.columns; rp != NULL; rp = rp->next)
    {
        if (CountChar(rp->item, ',') > 0)
        {
            CfOut(cf_error, "", "MS registry column format should be NAME only in deletion");
            retval = false;
        }
    }

    return retval;
}
Example #4
0
static void CheckAgentAccess(Rlist *list, const Rlist *input_files)
{
    struct stat sb;
    uid_t uid;
    int access = false;

    uid = getuid();

    for (const Rlist *rp = list; rp != NULL; rp = rp->next)
    {
        if (Str2Uid(rp->item, NULL, NULL) == uid)
        {
            return;
        }
    }

    for (const Rlist *rp = input_files; rp != NULL; rp = rp->next)
    {
        cfstat(rp->item, &sb);

        if (ACCESSLIST)
        {
            for (const Rlist *rp2 = ACCESSLIST; rp2 != NULL; rp2 = rp2->next)
            {
                if (Str2Uid(rp2->item, NULL, NULL) == sb.st_uid)
                {
                    access = true;
                    break;
                }
            }

            if (!access)
            {
                CfOut(cf_error, "", "File %s is not owned by an authorized user (security exception)",
                      ScalarValue(rp));
                exit(1);
            }
        }
        else if (CFPARANOID && IsPrivileged())
        {
            if (sb.st_uid != getuid())
            {
                CfOut(cf_error, "", "File %s is not owned by uid %ju (security exception)", ScalarValue(rp),
                      (uintmax_t)getuid());
                exit(1);
            }
        }
    }

    FatalError("You are denied access to run this policy");
}
Example #5
0
static void XmlExportVariables(Writer *writer, const char *scope)
{
    char *filebuffer = NULL;
    Rlist *rp = NULL;
    Rlist *list = NULL;

/* START XML ELEMENT -- VARIABLE*-SCOPE */
    XmlAttribute scope_name_attr = { "name", scope };
    XmlStartTag(writer, XMLTAG_VARSCOPE, 1, scope_name_attr);

/* XML ELEMENT -- INTRO */
    filebuffer = ReadTexinfoFileF("varcontexts/%s_intro.texinfo", scope);
    XmlTag(writer, XMLTAG_INTRO, filebuffer, 0);
    free(filebuffer);

    HashToList(GetScope(scope), &list);
    list = AlphaSortRListNames(list);
    for (rp = list; rp != NULL; rp = rp->next)
    {
        /* START XML ELEMENT -- VARIABLE */
        XmlAttribute var_name_attr = { "name", ScalarValue(rp) };
        XmlStartTag(writer, XMLTAG_VARIABLE, 1, var_name_attr);

        /* XML ELEMENT -- LONG-DESCRIPTION */
        filebuffer = ReadTexinfoFileF("vars/%s_%s.texinfo", scope, ScalarValue(rp));
        XmlTag(writer, XMLTAG_LONGDESCRIPTION, filebuffer, 0);
        free(filebuffer);

        /* END XML ELEMENT -- VARIABLE */
        XmlEndTag(writer, XMLTAG_VARIABLE);
    }
    DeleteRlist(list);

/* END XML ELEMENT -- VARIABLE-SCOPE */
    XmlEndTag(writer, XMLTAG_VARSCOPE);
}
Example #6
0
static void VerifyInferencePromise(Promise *pp)
{
    Attributes a = { {0} };
    Rlist *rpp, *rpq;

    if (!IsDefinedClass(pp->classes))
    {
        CfOut(cf_verbose, "", " -> Skipping inference for \"%s\" as class \"%s\" is not defined", pp->promiser,
              pp->classes);
        return;
    }

    a = GetInferencesAttributes(pp);

    for (rpp = a.precedents; rpp != NULL; rpp = rpp->next)
    {
        for (rpq = a.qualifiers; rpq != NULL; rpq = rpq->next)
        {
            CfOut(cf_verbose, "", " -> Add inference: (%s,%s,%s)\n", ScalarValue(rpp), ScalarValue(rpq), pp->promiser);
            AddInference(&INFERENCES, pp->promiser, rpp->item, rpq->item);
        }
    }
}
Example #7
0
static int SelectModeMatch(struct stat *lstatptr, Rlist *list)
{
    mode_t newperm, plus, minus;
    Rlist *rp;

    for (rp = list; rp != NULL; rp = rp->next)
    {
        plus = 0;
        minus = 0;

        if (!ParseModeString(rp->item, &plus, &minus))
        {
            CfOut(cf_error, "", " !! Problem validating a mode string \"%s\" in search filter", ScalarValue(rp));
            continue;
        }

        newperm = (lstatptr->st_mode & 07777);
        newperm |= plus;
        newperm &= ~minus;

        if ((newperm & 07777) == (lstatptr->st_mode & 07777))
        {
            return true;
        }
    }

    return false;
}
Example #8
0
void XmlExportType(Writer *writer, enum cfdatatype dtype, const void *range)
{
    Rlist *list = NULL;
    Rlist *rp = NULL;

/* START XML ELEMENT -- TYPE */
    XmlAttribute type_name_attr = { "name", CF_DATATYPES[dtype] };
    XmlStartTag(writer, XMLTAG_TYPE, 1, type_name_attr);

    switch (dtype)
    {
    case cf_body:
        /* EXPORT CONSTRAINTS */
        XmlExportConstraints(writer, (BodySyntax *) range);
        break;

    case cf_int:
    case cf_real:
    case cf_ilist:
    case cf_rlist:
    case cf_irange:
    case cf_rrange:
        if (range != NULL)
        {
            /* START XML ELEMENT -- RANGE */
            XmlStartTag(writer, XMLTAG_RANGE, 0);

            /* XML ELEMENT -- MIN/MAX */
            int i = 0;

            list = SplitStringAsRList((char *) range, ',');
            for (rp = list; rp != NULL; rp = rp->next, i++)
            {
                if (i == 0)
                {
                    XmlTag(writer, XMLTAG_MIN, ScalarValue(rp), 0);
                }
                else
                {
                    XmlTag(writer, XMLTAG_MAX, ScalarValue(rp), 0);
                }
            }
            DeleteRlist(list);

            /* END XML ELEMENT -- RANGE */
            XmlEndTag(writer, XMLTAG_RANGE);

            break;
        }

    case cf_opts:
    case cf_olist:
        if (range != NULL)
        {
            /* START XML ELEMENT -- OPTIONS */
            XmlStartTag(writer, XMLTAG_OPTIONS, 0);

            /* XML ELEMENT -- VALUE */
            list = SplitStringAsRList((char *) range, ',');
            for (rp = list; rp != NULL; rp = rp->next)
            {
                XmlTag(writer, XMLTAG_VALUE, ScalarValue(rp), 0);
            }
            DeleteRlist(list);

            /* END XML ELEMENT -- OPTIONS */
            XmlEndTag(writer, XMLTAG_OPTIONS);

            break;
        }

    case cf_str:
    case cf_slist:
    case cf_class:
    case cf_clist:
        /* XML ELEMENT -- ACCEPTED-VALUES */
        if (strlen((char *) range) == 0)
        {
            XmlTag(writer, XMLTAG_ACCEPTEDVALS, "arbitrary string", 0);
        }
        else
        {
            XmlTag(writer, XMLTAG_ACCEPTEDVALS, (char *) range, 0);
        }

        break;

    case cf_bundle:
    case cf_notype:
    case cf_counter:
        /* NONE */
        break;
    }

/* END XML ELEMENT -- TYPE */
    XmlEndTag(writer, XMLTAG_TYPE);
}
Example #9
0
static int CheckACLSyntax(char *file, Acl acl, Promise *pp)
{
    int valid = true;
    int deny_support = false;
    int mask_support = false;
    char *valid_ops = NULL;
    char *valid_nperms = NULL;
    Rlist *rp;

// set unset fields to defautls
    SetACLDefaults(file, &acl);

// find valid values for op

    switch (acl.acl_method)
    {
    case cfacl_overwrite:
        valid_ops = CF_VALID_OPS_METHOD_OVERWRITE;
        break;

    case cfacl_append:
        valid_ops = CF_VALID_OPS_METHOD_APPEND;
        break;

    default:
        // never executed: should be set to a default value by now
        break;
    }

    switch (acl.acl_type)
    {
    case cfacl_generic:        // generic ACL type: cannot include native or deny-type permissions
        valid_nperms = "";
        deny_support = false;
        mask_support = false;
        break;

    case cfacl_posix:
        valid_nperms = CF_VALID_NPERMS_POSIX;
        deny_support = false;   // posix does not support deny-type permissions
        mask_support = true;    // mask-ACE is allowed in POSIX
        break;

    case cfacl_ntfs:
        valid_nperms = CF_VALID_NPERMS_NTFS;
        deny_support = true;
        mask_support = false;
        break;

    default:
        // never executed: should be set to a default value by now
        break;
    }

// check that acl_directory_inherit is set to a valid value

    if (!CheckDirectoryInherit(file, &acl, pp))
    {
        return false;
    }

    for (rp = acl.acl_entries; rp != NULL; rp = rp->next)
    {
        valid = CheckACESyntax(ScalarValue(rp), valid_ops, valid_nperms, deny_support, mask_support, pp);

        if (!valid)             // wrong syntax in this ace
        {
            CfOut(cf_error, "", "The ACE \"%s\" contains errors", ScalarValue(rp));
            PromiseRef(cf_error, pp);
            break;
        }
    }

    for (rp = acl.acl_inherit_entries; rp != NULL; rp = rp->next)
    {
        valid = CheckACESyntax(rp->item, valid_ops, valid_nperms, deny_support, mask_support, pp);

        if (!valid)             // wrong syntax in this ace
        {
            CfOut(cf_error, "", "The ACE \"%s\" contains errors", ScalarValue(rp));
            PromiseRef(cf_error, pp);
            break;
        }
    }

    return valid;
}
Example #10
0
void KeepControlPromises(Policy *policy)
{
    Rval retval;
    Rlist *rp;

    Seq *constraints = ControlBodyConstraints(policy, AGENT_TYPE_AGENT);
    if (constraints)
    {
        for (size_t i = 0; i < SeqLength(constraints); i++)
        {
            Constraint *cp = SeqAt(constraints, i);

            if (IsExcluded(cp->classes, NULL))
            {
                continue;
            }

            if (GetVariable("control_common", cp->lval, &retval) != DATA_TYPE_NONE)
            {
                /* Already handled in generic_agent */
                continue;
            }

            if (GetVariable("control_agent", cp->lval, &retval) == DATA_TYPE_NONE)
            {
                CfOut(cf_error, "", "Unknown lval %s in agent control body", cp->lval);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_maxconnections].lval) == 0)
            {
                CFA_MAXTHREADS = (int) Str2Int(retval.item);
                CfOut(cf_verbose, "", "SET maxconnections = %d\n", CFA_MAXTHREADS);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_checksum_alert_time].lval) == 0)
            {
                CF_PERSISTENCE = (int) Str2Int(retval.item);
                CfOut(cf_verbose, "", "SET checksum_alert_time = %d\n", CF_PERSISTENCE);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_agentfacility].lval) == 0)
            {
                SetFacility(retval.item);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_agentaccess].lval) == 0)
            {
                ACCESSLIST = (Rlist *) retval.item;
                CheckAgentAccess(ACCESSLIST, InputFiles(policy));
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_refresh_processes].lval) == 0)
            {
                Rlist *rp;

                if (VERBOSE)
                {
                    printf("%s> SET refresh_processes when starting: ", VPREFIX);

                    for (rp = (Rlist *) retval.item; rp != NULL; rp = rp->next)
                    {
                        printf(" %s", (char *) rp->item);
                        PrependItem(&PROCESSREFRESH, rp->item, NULL);
                    }

                    printf("\n");
                }

                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_abortclasses].lval) == 0)
            {
                Rlist *rp;

                CfOut(cf_verbose, "", "SET Abort classes from ...\n");

                for (rp = (Rlist *) retval.item; rp != NULL; rp = rp->next)
                {
                    char name[CF_MAXVARSIZE] = "";

                    strncpy(name, rp->item, CF_MAXVARSIZE - 1);

                    AddAbortClass(name, cp->classes);
                }

                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_abortbundleclasses].lval) == 0)
            {
                Rlist *rp;

                CfOut(cf_verbose, "", "SET Abort bundle classes from ...\n");

                for (rp = (Rlist *) retval.item; rp != NULL; rp = rp->next)
                {
                    char name[CF_MAXVARSIZE] = "";

                    strncpy(name, rp->item, CF_MAXVARSIZE - 1);

                    if (!IsItemIn(ABORTBUNDLEHEAP, name))
                    {
                        AppendItem(&ABORTBUNDLEHEAP, name, cp->classes);
                    }
                }

                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_addclasses].lval) == 0)
            {
                Rlist *rp;

                CfOut(cf_verbose, "", "-> Add classes ...\n");

                for (rp = (Rlist *) retval.item; rp != NULL; rp = rp->next)
                {
                    CfOut(cf_verbose, "", " -> ... %s\n", ScalarValue(rp));
                    NewClass(rp->item, NULL);
                }

                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_auditing].lval) == 0)
            {
                CfOut(cf_verbose, "", "This option does nothing and is retained for compatibility reasons");
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_alwaysvalidate].lval) == 0)
            {
                ALWAYS_VALIDATE = GetBoolean(retval.item);
                CfOut(cf_verbose, "", "SET alwaysvalidate = %d\n", ALWAYS_VALIDATE);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_allclassesreport].lval) == 0)
            {
                ALLCLASSESREPORT = GetBoolean(retval.item);
                CfOut(cf_verbose, "", "SET allclassesreport = %d\n", ALLCLASSESREPORT);
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_secureinput].lval) == 0)
            {
                CFPARANOID = GetBoolean(retval.item);
                CfOut(cf_verbose, "", "SET secure input = %d\n", CFPARANOID);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_binarypaddingchar].lval) == 0)
            {
                CfOut(cf_verbose, "", "binarypaddingchar is obsolete and does nothing\n");
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_bindtointerface].lval) == 0)
            {
                strncpy(BINDINTERFACE, retval.item, CF_BUFSIZE - 1);
                CfOut(cf_verbose, "", "SET bindtointerface = %s\n", BINDINTERFACE);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_hashupdates].lval) == 0)
            {
                bool enabled = GetBoolean(retval.item);

                SetChecksumUpdates(enabled);
                CfOut(cf_verbose, "", "SET ChecksumUpdates %d\n", enabled);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_exclamation].lval) == 0)
            {
                CfOut(cf_verbose, "", "exclamation control is deprecated and does not do anything\n");
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_childlibpath].lval) == 0)
            {
                char output[CF_BUFSIZE];

                snprintf(output, CF_BUFSIZE, "LD_LIBRARY_PATH=%s", (char *) retval.item);
                if (putenv(xstrdup(output)) == 0)
                {
                    CfOut(cf_verbose, "", "Setting %s\n", output);
                }
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_defaultcopytype].lval) == 0)
            {
                DEFAULT_COPYTYPE = (char *) retval.item;
                CfOut(cf_verbose, "", "SET defaultcopytype = %s\n", DEFAULT_COPYTYPE);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_fsinglecopy].lval) == 0)
            {
                SINGLE_COPY_LIST = (Rlist *) retval.item;
                CfOut(cf_verbose, "", "SET file single copy list\n");
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_fautodefine].lval) == 0)
            {
                SetFileAutoDefineList(ListRvalValue(retval));
                CfOut(cf_verbose, "", "SET file auto define list\n");
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_dryrun].lval) == 0)
            {
                DONTDO = GetBoolean(retval.item);
                CfOut(cf_verbose, "", "SET dryrun = %c\n", DONTDO);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_inform].lval) == 0)
            {
                INFORM = GetBoolean(retval.item);
                CfOut(cf_verbose, "", "SET inform = %c\n", INFORM);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_verbose].lval) == 0)
            {
                VERBOSE = GetBoolean(retval.item);
                CfOut(cf_verbose, "", "SET inform = %c\n", VERBOSE);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_repository].lval) == 0)
            {
                SetRepositoryLocation(retval.item);
                CfOut(cf_verbose, "", "SET repository = %s\n", ScalarRvalValue(retval));
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_skipidentify].lval) == 0)
            {
                bool enabled = GetBoolean(retval.item);

                SetSkipIdentify(enabled);
                CfOut(cf_verbose, "", "SET skipidentify = %d\n", (int) enabled);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_suspiciousnames].lval) == 0)
            {

                for (rp = (Rlist *) retval.item; rp != NULL; rp = rp->next)
                {
                    AddFilenameToListOfSuspicious(ScalarValue(rp));
                    CfOut(cf_verbose, "", "-> Considering %s as suspicious file", ScalarValue(rp));
                }

                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_repchar].lval) == 0)
            {
                char c = *(char *) retval.item;

                SetRepositoryChar(c);
                CfOut(cf_verbose, "", "SET repchar = %c\n", c);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_mountfilesystems].lval) == 0)
            {
                CF_MOUNTALL = GetBoolean(retval.item);
                CfOut(cf_verbose, "", "SET mountfilesystems = %d\n", CF_MOUNTALL);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_editfilesize].lval) == 0)
            {
                EDITFILESIZE = Str2Int(retval.item);
                CfOut(cf_verbose, "", "SET EDITFILESIZE = %d\n", EDITFILESIZE);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_ifelapsed].lval) == 0)
            {
                VIFELAPSED = Str2Int(retval.item);
                CfOut(cf_verbose, "", "SET ifelapsed = %d\n", VIFELAPSED);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_expireafter].lval) == 0)
            {
                VEXPIREAFTER = Str2Int(retval.item);
                CfOut(cf_verbose, "", "SET ifelapsed = %d\n", VEXPIREAFTER);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_timeout].lval) == 0)
            {
                CONNTIMEOUT = Str2Int(retval.item);
                CfOut(cf_verbose, "", "SET timeout = %jd\n", (intmax_t) CONNTIMEOUT);
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_max_children].lval) == 0)
            {
                CFA_BACKGROUND_LIMIT = Str2Int(retval.item);
                CfOut(cf_verbose, "", "SET MAX_CHILDREN = %d\n", CFA_BACKGROUND_LIMIT);
                if (CFA_BACKGROUND_LIMIT > 10)
                {
                    CfOut(cf_error, "", "Silly value for max_children in agent control promise (%d > 10)",
                          CFA_BACKGROUND_LIMIT);
                    CFA_BACKGROUND_LIMIT = 1;
                }
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_syslog].lval) == 0)
            {
                CfOut(cf_verbose, "", "SET syslog = %d\n", GetBoolean(retval.item));
                continue;
            }

            if (strcmp(cp->lval, CFA_CONTROLBODY[cfa_environment].lval) == 0)
            {
                Rlist *rp;

                CfOut(cf_verbose, "", "SET environment variables from ...\n");

                for (rp = (Rlist *) retval.item; rp != NULL; rp = rp->next)
                {
                    if (putenv(rp->item) != 0)
                    {
                        CfOut(cf_error, "putenv", "Failed to set environment variable %s", ScalarValue(rp));
                    }
                }

                continue;
            }
        }
    }

    if (GetVariable("control_common", CFG_CONTROLBODY[cfg_lastseenexpireafter].lval, &retval) != DATA_TYPE_NONE)
    {
        LASTSEENEXPIREAFTER = Str2Int(retval.item) * 60;
    }

    if (GetVariable("control_common", CFG_CONTROLBODY[cfg_fips_mode].lval, &retval) != DATA_TYPE_NONE)
    {
        FIPS_MODE = GetBoolean(retval.item);
        CfOut(cf_verbose, "", "SET FIPS_MODE = %d\n", FIPS_MODE);
    }

    if (GetVariable("control_common", CFG_CONTROLBODY[cfg_syslog_port].lval, &retval) != DATA_TYPE_NONE)
    {
        SetSyslogPort(Str2Int(retval.item));
        CfOut(cf_verbose, "", "SET syslog_port to %s", ScalarRvalValue(retval));
    }

    if (GetVariable("control_common", CFG_CONTROLBODY[cfg_syslog_host].lval, &retval) != DATA_TYPE_NONE)
    {
        SetSyslogHost(Hostname2IPString(retval.item));
        CfOut(cf_verbose, "", "SET syslog_host to %s", Hostname2IPString(retval.item));
    }

#ifdef HAVE_NOVA
    Nova_Initialize();
#endif
}
Example #11
0
static void VerifyOccurrencePromises(Promise *pp)
{
    Attributes a = { {0} };
    char name[CF_BUFSIZE];
    enum representations rep_type;
    Rlist *contexts, *rp;

    a = GetOccurrenceAttributes(pp);

    if (a.rep_type)
    {
        rep_type = String2Representation(a.rep_type);
    }
    else
    {
        rep_type = cfk_url;
    }

    if (a.represents == NULL)
    {
        if (rep_type == cfk_literal)
        {
            CfOut(cf_error, "", " ! Occurrence of text information \"%s\" does not promise any topics to represent",
                  pp->promiser);
        }
        else
        {
            CfOut(cf_error, "",
                  " ! Occurrence or reference to information \"%s\" does not promise any topics to represent",
                  pp->promiser);
        }
        return;
    }

    contexts = SplitContextExpression(pp->classes, pp);

    for (rp = contexts; rp != NULL; rp = rp->next)
    {
        CfOut(cf_verbose, "", " -> New occurrence promise for \"%s\" about context \"%s\"", pp->promiser,
              ScalarValue(rp));

        switch (rep_type)
        {
        case cfk_file:

            if (a.web_root == NULL || a.path_root == NULL)
            {
                CfOut(cf_error, "", " !! File pattern but no complete url mapping path_root -> web_root");
                return;
            }

            strncpy(name, a.path_root, CF_BUFSIZE - 1);

            if (!JoinPath(name, pp->promiser))
            {
                CfOut(cf_error, "", " !! Unable to form pathname in search for local files");
                return;
            }

            // FIXME - this should pass rp->item instead of pp->classes if we want to keep this

            LocateFilePromiserGroup(name, pp, VerifyOccurrenceGroup);
            break;

        default:

            AddOccurrence(&OCCURRENCES, pp->promiser, a.represents, rep_type, rp->item);
            break;
        }
    }

    DeleteRlist(contexts);
}
Example #12
0
static void VerifyTopicPromise(Promise *pp)
{
    char id[CF_BUFSIZE];
    Attributes a = { {0} };
    Topic *tp = NULL, *otp;
    Rlist *rp, *rps, *contexts;
    char *handle = (char *) GetConstraintValue("handle", pp, CF_SCALAR);

    a = GetTopicsAttributes(pp);

    CfOut(cf_verbose, "", " -> Attempting to install topic %s::%s \n", pp->classes, pp->promiser);

// Add a standard reserved word

    contexts = SplitContextExpression(pp->classes, pp);

    for (rp = contexts; rp != NULL; rp = rp->next)
    {
        if ((tp = InsertTopic(pp->promiser, rp->item)) == NULL)
        {
            return;
        }

        CfOut(cf_verbose, "", " -> New topic promise for \"%s\" about context \"%s\"", pp->promiser, ScalarValue(rp));

        if (a.fwd_name && a.bwd_name)
        {
            AddTopicAssociation(tp, &(tp->associations), a.fwd_name, a.bwd_name, a.associates, true, rp->item,
                                pp->promiser);
        }

        // Handle all synonyms as associations

        if (a.synonyms)
        {
            for (rps = a.synonyms; rps != NULL; rps = rps->next)
            {
                otp = IdempInsertTopic(rps->item);
                CfOut(cf_verbose, "", " ---> %s is a synonym for %s", ScalarValue(rps), tp->topic_name);
            }

            AddTopicAssociation(tp, &(tp->associations), KM_SYNONYM, KM_SYNONYM, a.synonyms, true, rp->item,
                                pp->promiser);
        }

        // Handle all generalizations as associations

        if (a.general)
        {
            for (rps = a.general; rps != NULL; rps = rps->next)
            {
                otp = IdempInsertTopic(rps->item);
                CfOut(cf_verbose, "", " ---> %s is a generalization for %s", ScalarValue(rps), tp->topic_name);
            }

            AddTopicAssociation(tp, &(tp->associations), KM_GENERALIZES_B, KM_GENERALIZES_F, a.general, true, rp->item,
                                pp->promiser);
        }

        if (handle)
        {
            char synonym[CF_BUFSIZE];

            snprintf(synonym, CF_BUFSIZE - 1, "handles::%s", handle);
            otp = IdempInsertTopic(synonym);
            PrependRScalar(&(a.synonyms), otp->topic_name, CF_SCALAR);
        }

        // Treat comments as occurrences of information.

        if (pp->ref)
        {
            Rlist *list = NULL;

            snprintf(id, CF_MAXVARSIZE, "%s.%s", pp->classes, CanonifyName(pp->promiser));
            PrependRScalar(&list, "description", CF_SCALAR);
            AddOccurrence(&OCCURRENCES, pp->ref, list, cfk_literal, id);
            DeleteRlist(list);
        }

        if (handle)
        {
            Rlist *list = NULL;

            PrependRScalar(&list, handle, CF_SCALAR);
            AddTopicAssociation(tp, &(tp->associations), "is the promise of", "stands for", list, true, rp->item,
                                pp->promiser);
            DeleteRlist(list);
            list = NULL;
            snprintf(id, CF_MAXVARSIZE, "%s.%s", pp->classes, handle);
            PrependRScalar(&list, "description", CF_SCALAR);
            AddOccurrence(&OCCURRENCES, pp->ref, list, cfk_literal, id);
            DeleteRlist(list);
        }
    }

    DeleteRlist(contexts);
}
Example #13
0
static void AddTopicAssociation(Topic *this_tp, TopicAssociation **list, char *fwd_name, char *bwd_name,
                                Rlist *passociates, int ok_to_add_inverse, char *from_context, char *from_topic)
{
    TopicAssociation *ta = NULL, *texist;
    char fwd_context[CF_MAXVARSIZE];
    Rlist *rp;
    Topic *new_tp;
    char contexttopic[CF_BUFSIZE], ntopic[CF_BUFSIZE], ncontext[CF_BUFSIZE];

    strncpy(ntopic, NormalizeTopic(from_topic), CF_BUFSIZE - 1);
    strncpy(ncontext, NormalizeTopic(from_context), CF_BUFSIZE - 1);
    snprintf(contexttopic, CF_MAXVARSIZE, "%s::%s", ncontext, ntopic);
    strncpy(fwd_context, CanonifyName(fwd_name), CF_MAXVARSIZE - 1);

    if (passociates == NULL || passociates->item == NULL)
    {
        CfOut(cf_error, "", " !! A topic must have at least one associate in association %s", fwd_name);
        return;
    }

    if ((texist = AssociationExists(*list, fwd_name, bwd_name)) == NULL)
    {
        ta = xcalloc(1, sizeof(TopicAssociation));

        ta->fwd_name = xstrdup(fwd_name);

        if (bwd_name)
        {
            ta->bwd_name = xstrdup(bwd_name);
        }

        ta->fwd_context = xstrdup(fwd_context);

        ta->next = *list;
        *list = ta;
    }
    else
    {
        ta = texist;
    }

/* Association now exists, so add new members */

    if (ok_to_add_inverse)
    {
        CfOut(cf_verbose, "", " -> BEGIN add fwd associates for %s::%s", ncontext, ntopic);
    }
    else
    {
        CfOut(cf_verbose, "", "  ---> BEGIN reverse associations %s::%s", ncontext, ntopic);
    }

// First make sure topics pointed to exist so that they can point to us also

    for (rp = passociates; rp != NULL; rp = rp->next)
    {
        char normalform[CF_BUFSIZE] = { 0 };

        strncpy(normalform, NormalizeTopic(rp->item), CF_BUFSIZE - 1);
        new_tp = IdempInsertTopic(normalform);

        if (strcmp(contexttopic, normalform) == 0)
        {
            CfOut(cf_verbose, "", " ! Excluding self-reference to %s", ScalarValue(rp));
            continue;
        }

        if (ok_to_add_inverse)
        {
            CfOut(cf_verbose, "", " --> Adding '%s' with id %d as an associate of '%s::%s'", normalform, new_tp->id,
                  this_tp->topic_context, this_tp->topic_name);
        }
        else
        {
            CfOut(cf_verbose, "", " ---> Reverse '%s' with id %d as an associate of '%s::%s' (inverse)", normalform,
                  new_tp->id, this_tp->topic_context, this_tp->topic_name);
        }

        if (!IsItemIn(ta->associates, normalform))
        {
            PrependFullItem(&(ta->associates), normalform, NULL, new_tp->id, 0);

            if (ok_to_add_inverse)
            {
                // inverse is from normalform to ncontext::ntopic
                char rev[CF_BUFSIZE], ndt[CF_BUFSIZE], ndc[CF_BUFSIZE];
                Rlist *rlist = 0;

                snprintf(rev, CF_BUFSIZE - 1, "%s::%s", ncontext, ntopic);
                PrependRScalar(&rlist, rev, CF_SCALAR);

                // Stupid to have to declassify + reclassify, but ..
                DeClassifyTopic(normalform, ndt, ndc);
                AddTopicAssociation(new_tp, &(new_tp->associations), bwd_name, fwd_name, rlist, false, ndc, ndt);
                DeleteRlist(rlist);
            }
        }
        else
        {
            CfOut(cf_verbose, "", " -> Already in %s::%s's associate list", ncontext, ntopic);
        }

        CF_EDGES++;
    }

    if (ok_to_add_inverse)
    {
        CfOut(cf_verbose, "", " -> END add fwd associates for %s::%s", ncontext, ntopic);
    }
    else
    {
        CfOut(cf_verbose, "", "  ---> END reverse associations %s::%s", ncontext, ntopic);
    }
}