コード例 #1
0
ファイル: files_select.c プロジェクト: xrg/cfengine-core
int SelectLeaf(char *path, struct stat *sb, Attributes attr, Promise *pp)
{
    AlphaList leaf_attr;
    int result = true;
    Rlist *rp;

    InitAlphaList(&leaf_attr);

#ifdef MINGW
    if (attr.select.issymlinkto != NULL)
    {
        CfOut(cf_verbose, "",
              "files_select.issymlinkto is ignored on Windows (symbolic links are not supported by Windows)");
    }

    if (attr.select.groups != NULL)
    {
        CfOut(cf_verbose, "",
              "files_select.search_groups is ignored on Windows (file groups are not supported by Windows)");
    }

    if (attr.select.bsdflags != NULL)
    {
        CfOut(cf_verbose, "", "files_select.search_bsdflags is ignored on Windows");
    }
#endif /* MINGW */

    if (!attr.haveselect)
    {
        return true;
    }

    if (attr.select.name == NULL)
    {
        PrependAlphaList(&leaf_attr, "leaf_name");
    }

    for (rp = attr.select.name; rp != NULL; rp = rp->next)
    {
        if (SelectNameRegexMatch(path, rp->item))
        {
            PrependAlphaList(&leaf_attr, "leaf_name");
            break;
        }
    }

    if (attr.select.path == NULL)
    {
        PrependAlphaList(&leaf_attr, "leaf_path");
    }

    for (rp = attr.select.path; rp != NULL; rp = rp->next)
    {
        if (SelectPathRegexMatch(path, rp->item))
        {
            PrependAlphaList(&leaf_attr, "path_name");
            break;
        }
    }

    if (SelectTypeMatch(sb, attr.select.filetypes))
    {
        PrependAlphaList(&leaf_attr, "file_types");
    }

    if (attr.select.owners && SelectOwnerMatch(path, sb, attr.select.owners))
    {
        PrependAlphaList(&leaf_attr, "owner");
    }

    if (attr.select.owners == NULL)
    {
        PrependAlphaList(&leaf_attr, "owner");
    }

#ifdef MINGW
    PrependAlphaList(&leaf_attr, "group");

#else /* NOT MINGW */
    if (attr.select.groups && SelectGroupMatch(sb, attr.select.groups))
    {
        PrependAlphaList(&leaf_attr, "group");
    }

    if (attr.select.groups == NULL)
    {
        PrependAlphaList(&leaf_attr, "group");
    }
#endif /* NOT MINGW */

    if (SelectModeMatch(sb, attr.select.perms))
    {
        PrependAlphaList(&leaf_attr, "mode");
    }

#if defined HAVE_CHFLAGS
    if (SelectBSDMatch(sb, attr.select.bsdflags, pp))
    {
        PrependAlphaList(&leaf_attr, "bsdflags");
    }
#endif

    if (SelectTimeMatch(sb->st_atime, attr.select.min_atime, attr.select.max_atime))
    {
        PrependAlphaList(&leaf_attr, "atime");
    }

    if (SelectTimeMatch(sb->st_ctime, attr.select.min_ctime, attr.select.max_ctime))
    {
        PrependAlphaList(&leaf_attr, "ctime");
    }

    if (SelectSizeMatch(sb->st_size, attr.select.min_size, attr.select.max_size))
    {
        PrependAlphaList(&leaf_attr, "size");
    }

    if (SelectTimeMatch(sb->st_mtime, attr.select.min_mtime, attr.select.max_mtime))
    {
        PrependAlphaList(&leaf_attr, "mtime");
    }

    if (attr.select.issymlinkto && SelectIsSymLinkTo(path, attr.select.issymlinkto))
    {
        PrependAlphaList(&leaf_attr, "issymlinkto");
    }

    if (attr.select.exec_regex && SelectExecRegexMatch(path, attr.select.exec_regex, attr.select.exec_program))
    {
        PrependAlphaList(&leaf_attr, "exec_regex");
    }

    if (attr.select.exec_program && SelectExecProgram(path, attr.select.exec_program))
    {
        PrependAlphaList(&leaf_attr, "exec_program");
    }

    if ((result = EvalFileResult(attr.select.result, &leaf_attr)))
    {
        //NewClassesFromString(fp->defines);
    }

    CfDebug("Select result \"%s\"on %s was %d\n", attr.select.result, path, result);

    DeleteAlphaList(&leaf_attr);

    return result;
}
コード例 #2
0
ファイル: files_select.c プロジェクト: nperron/core
int SelectLeaf(EvalContext *ctx, char *path, struct stat *sb, FileSelect fs)
{
    int result = true;
    Rlist *rp;

    StringSet *leaf_attr = StringSetNew();

#ifdef __MINGW32__
    if (fs.issymlinkto != NULL)
    {
        Log(LOG_LEVEL_VERBOSE,
              "files_select.issymlinkto is ignored on Windows (symbolic links are not supported by Windows)");
    }

    if (fs.groups != NULL)
    {
        Log(LOG_LEVEL_VERBOSE,
              "files_select.search_groups is ignored on Windows (file groups are not supported by Windows)");
    }

    if (fs.bsdflags != NULL)
    {
        Log(LOG_LEVEL_VERBOSE, "files_select.search_bsdflags is ignored on Windows");
    }
#endif /* __MINGW32__ */

    if (fs.name == NULL)
    {
        StringSetAdd(leaf_attr, xstrdup("leaf_name"));
    }

    for (rp = fs.name; rp != NULL; rp = rp->next)
    {
        if (SelectNameRegexMatch(ctx, path, rp->item))
        {
            StringSetAdd(leaf_attr, xstrdup("leaf_name"));
            break;
        }
    }

    if (fs.path == NULL)
    {
        StringSetAdd(leaf_attr, xstrdup("leaf_path"));
    }

    for (rp = fs.path; rp != NULL; rp = rp->next)
    {
        if (SelectPathRegexMatch(ctx, path, rp->item))
        {
            StringSetAdd(leaf_attr, xstrdup("path_name"));
            break;
        }
    }

    if (SelectTypeMatch(sb, fs.filetypes))
    {
        StringSetAdd(leaf_attr, xstrdup("file_types"));
    }

    if ((fs.owners) && (SelectOwnerMatch(ctx, path, sb, fs.owners)))
    {
        StringSetAdd(leaf_attr, xstrdup("owner"));
    }

    if (fs.owners == NULL)
    {
        StringSetAdd(leaf_attr, xstrdup("owner"));
    }

#ifdef __MINGW32__
    StringSetAdd(leaf_attr, xstrdup("group"));

#else /* !__MINGW32__ */
    if ((fs.groups) && (SelectGroupMatch(ctx, sb, fs.groups)))
    {
        StringSetAdd(leaf_attr, xstrdup("group"));
    }

    if (fs.groups == NULL)
    {
        StringSetAdd(leaf_attr, xstrdup("group"));
    }
#endif /* !__MINGW32__ */

    if (SelectModeMatch(sb, fs.perms))
    {
        StringSetAdd(leaf_attr, xstrdup("mode"));
    }

#if defined HAVE_CHFLAGS
    if (SelectBSDMatch(sb, fs.bsdflags))
    {
        StringSetAdd(leaf_attr, xstrdup("bsdflags"));
    }
#endif

    if (SelectTimeMatch(sb->st_atime, fs.min_atime, fs.max_atime))
    {
        StringSetAdd(leaf_attr, xstrdup("atime"));
    }

    if (SelectTimeMatch(sb->st_ctime, fs.min_ctime, fs.max_ctime))
    {
        StringSetAdd(leaf_attr, xstrdup("ctime"));
    }

    if (SelectSizeMatch(sb->st_size, fs.min_size, fs.max_size))
    {
        StringSetAdd(leaf_attr, xstrdup("size"));
    }

    if (SelectTimeMatch(sb->st_mtime, fs.min_mtime, fs.max_mtime))
    {
        StringSetAdd(leaf_attr, xstrdup("mtime"));
    }

    if ((fs.issymlinkto) && (SelectIsSymLinkTo(ctx, path, fs.issymlinkto)))
    {
        StringSetAdd(leaf_attr, xstrdup("issymlinkto"));
    }

    if ((fs.exec_regex) && (SelectExecRegexMatch(ctx, path, fs.exec_regex, fs.exec_program)))
    {
        StringSetAdd(leaf_attr, xstrdup("exec_regex"));
    }

    if ((fs.exec_program) && (SelectExecProgram(path, fs.exec_program)))
    {
        StringSetAdd(leaf_attr, xstrdup("exec_program"));
    }

    result = EvalFileResult(fs.result, leaf_attr);

    Log(LOG_LEVEL_DEBUG, "Select result '%s' on '%s' was %d", fs.result, path, result);

    StringSetDestroy(leaf_attr);

    return result;
}