Exemplo n.º 1
0
static int SelectOwnerMatch(char *path, struct stat *lstatptr, Rlist *crit)
{
    AlphaList leafattrib;
    Rlist *rp;
    char ownerName[CF_BUFSIZE];
    int gotOwner;

    InitAlphaList(&leafattrib);

#ifndef MINGW                   // no uids on Windows
    char buffer[CF_SMALLBUF];
    sprintf(buffer, "%jd", (uintmax_t) lstatptr->st_uid);
    PrependAlphaList(&leafattrib, buffer);
#endif /* MINGW */

    gotOwner = GetOwnerName(path, lstatptr, ownerName, sizeof(ownerName));

    if (gotOwner)
    {
        PrependAlphaList(&leafattrib, ownerName);
    }
    else
    {
        PrependAlphaList(&leafattrib, "none");
    }

    for (rp = crit; rp != NULL; rp = rp->next)
    {
        if (EvalFileResult((char *) rp->item, &leafattrib))
        {
            CfDebug(" - ? Select owner match\n");
            DeleteAlphaList(&leafattrib);
            return true;
        }

        if (gotOwner && FullTextMatch((char *) rp->item, ownerName))
        {
            CfDebug(" - ? Select owner match\n");
            DeleteAlphaList(&leafattrib);
            return true;
        }

#ifndef MINGW
        if (FullTextMatch((char *) rp->item, buffer))
        {
            CfDebug(" - ? Select owner match\n");
            DeleteAlphaList(&leafattrib);
            return true;
        }
#endif /* NOT MINGW */
    }

    DeleteAlphaList(&leafattrib);
    return false;
}
Exemplo n.º 2
0
static int SelectOwnerMatch(EvalContext *ctx, char *path, struct stat *lstatptr, Rlist *crit)
{
    Rlist *rp;
    char ownerName[CF_BUFSIZE];
    int gotOwner;

    StringSet *leafattrib = StringSetNew();

#ifndef __MINGW32__                   // no uids on Windows
    char buffer[CF_SMALLBUF];
    snprintf(buffer, CF_SMALLBUF, "%jd", (uintmax_t) lstatptr->st_uid);
    StringSetAdd(leafattrib, xstrdup(buffer));
#endif /* __MINGW32__ */

    gotOwner = GetOwnerName(path, lstatptr, ownerName, sizeof(ownerName));

    if (gotOwner)
    {
        StringSetAdd(leafattrib, xstrdup(ownerName));
    }
    else
    {
        StringSetAdd(leafattrib, xstrdup("none"));
    }

    for (rp = crit; rp != NULL; rp = rp->next)
    {
        if (EvalFileResult((char *) rp->item, leafattrib))
        {
            Log(LOG_LEVEL_DEBUG, "Select owner match");
            StringSetDestroy(leafattrib);
            return true;
        }

        if (gotOwner && (FullTextMatch(ctx, RlistScalarValue(rp), ownerName)))
        {
            Log(LOG_LEVEL_DEBUG, "Select owner match");
            StringSetDestroy(leafattrib);
            return true;
        }

#ifndef __MINGW32__
        if (FullTextMatch(ctx, RlistScalarValue(rp), buffer))
        {
            Log(LOG_LEVEL_DEBUG, "Select owner match");
            StringSetDestroy(leafattrib);
            return true;
        }
#endif /* !__MINGW32__ */
    }

    StringSetDestroy(leafattrib);
    return false;
}
Exemplo n.º 3
0
static int SelectGroupMatch(struct stat *lstatptr, Rlist *crit)
{
    AlphaList leafattrib;
    char buffer[CF_SMALLBUF];
    struct group *gr;
    Rlist *rp;

    InitAlphaList(&leafattrib);

    sprintf(buffer, "%jd", (uintmax_t) lstatptr->st_gid);
    PrependAlphaList(&leafattrib, buffer);

    if ((gr = getgrgid(lstatptr->st_gid)) != NULL)
    {
        PrependAlphaList(&leafattrib, gr->gr_name);
    }
    else
    {
        PrependAlphaList(&leafattrib, "none");
    }

    for (rp = crit; rp != NULL; rp = rp->next)
    {
        if (EvalFileResult((char *) rp->item, &leafattrib))
        {
            CfDebug(" - ? Select group match\n");
            DeleteAlphaList(&leafattrib);
            return true;
        }

        if (gr && FullTextMatch((char *) rp->item, gr->gr_name))
        {
            CfDebug(" - ? Select owner match\n");
            DeleteAlphaList(&leafattrib);
            return true;
        }

        if (FullTextMatch((char *) rp->item, buffer))
        {
            CfDebug(" - ? Select owner match\n");
            DeleteAlphaList(&leafattrib);
            return true;
        }
    }

    DeleteAlphaList(&leafattrib);
    return false;
}
Exemplo n.º 4
0
static int SelectGroupMatch(EvalContext *ctx, struct stat *lstatptr, Rlist *crit)
{
    char buffer[CF_SMALLBUF];
    struct group *gr;
    Rlist *rp;

    StringSet *leafattrib = StringSetNew();

    snprintf(buffer, CF_SMALLBUF, "%jd", (uintmax_t) lstatptr->st_gid);
    StringSetAdd(leafattrib, xstrdup(buffer));

    if ((gr = getgrgid(lstatptr->st_gid)) != NULL)
    {
        StringSetAdd(leafattrib, xstrdup(gr->gr_name));
    }
    else
    {
        StringSetAdd(leafattrib, xstrdup("none"));
    }

    for (rp = crit; rp != NULL; rp = rp->next)
    {
        if (EvalFileResult((char *) rp->item, leafattrib))
        {
            Log(LOG_LEVEL_DEBUG, "Select group match");
            StringSetDestroy(leafattrib);
            return true;
        }

        if (gr && (FullTextMatch(ctx, (char *) rp->item, gr->gr_name)))
        {
            Log(LOG_LEVEL_DEBUG, "Select group match");
            StringSetDestroy(leafattrib);
            return true;
        }

        if (FullTextMatch(ctx, (char *) rp->item, buffer))
        {
            Log(LOG_LEVEL_DEBUG, "Select group match");
            StringSetDestroy(leafattrib);
            return true;
        }
    }

    StringSetDestroy(leafattrib);
    return false;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
static int SelectTypeMatch(struct stat *lstatptr, Rlist *crit)
{
    AlphaList leafattrib;
    Rlist *rp;

    InitAlphaList(&leafattrib);

    if (S_ISREG(lstatptr->st_mode))
    {
        PrependAlphaList(&leafattrib, "reg");
        PrependAlphaList(&leafattrib, "plain");
    }

    if (S_ISDIR(lstatptr->st_mode))
    {
        PrependAlphaList(&leafattrib, "dir");
    }

#ifndef MINGW
    if (S_ISLNK(lstatptr->st_mode))
    {
        PrependAlphaList(&leafattrib, "symlink");
    }

    if (S_ISFIFO(lstatptr->st_mode))
    {
        PrependAlphaList(&leafattrib, "fifo");
    }

    if (S_ISSOCK(lstatptr->st_mode))
    {
        PrependAlphaList(&leafattrib, "socket");
    }

    if (S_ISCHR(lstatptr->st_mode))
    {
        PrependAlphaList(&leafattrib, "char");
    }

    if (S_ISBLK(lstatptr->st_mode))
    {
        PrependAlphaList(&leafattrib, "block");
    }
#endif /* NOT MINGW */

#ifdef HAVE_DOOR_CREATE
    if (S_ISDOOR(lstatptr->st_mode))
    {
        PrependAlphaList(&leafattrib, "door");
    }
#endif

    for (rp = crit; rp != NULL; rp = rp->next)
    {
        if (EvalFileResult((char *) rp->item, &leafattrib))
        {
            DeleteAlphaList(&leafattrib);
            return true;
        }
    }

    DeleteAlphaList(&leafattrib);
    return false;
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
static int SelectTypeMatch(struct stat *lstatptr, Rlist *crit)
{
    Rlist *rp;

    StringSet *leafattrib = StringSetNew();

    if (S_ISREG(lstatptr->st_mode))
    {
        StringSetAdd(leafattrib, xstrdup("reg"));
        StringSetAdd(leafattrib, xstrdup("plain"));
    }

    if (S_ISDIR(lstatptr->st_mode))
    {
        StringSetAdd(leafattrib, xstrdup("dir"));
    }

#ifndef __MINGW32__
    if (S_ISLNK(lstatptr->st_mode))
    {
        StringSetAdd(leafattrib, xstrdup("symlink"));
    }

    if (S_ISFIFO(lstatptr->st_mode))
    {
        StringSetAdd(leafattrib, xstrdup("fifo"));
    }

    if (S_ISSOCK(lstatptr->st_mode))
    {
        StringSetAdd(leafattrib, xstrdup("socket"));
    }

    if (S_ISCHR(lstatptr->st_mode))
    {
        StringSetAdd(leafattrib, xstrdup("char"));
    }

    if (S_ISBLK(lstatptr->st_mode))
    {
        StringSetAdd(leafattrib, xstrdup("block"));
    }
#endif /* !__MINGW32__ */

#ifdef HAVE_DOOR_CREATE
    if (S_ISDOOR(lstatptr->st_mode))
    {
        StringSetAdd(leafattrib, xstrdup("door"));
    }
#endif

    for (rp = crit; rp != NULL; rp = rp->next)
    {
        if (EvalFileResult((char *) rp->item, leafattrib))
        {
            StringSetDestroy(leafattrib);
            return true;
        }
    }

    StringSetDestroy(leafattrib);
    return false;
}