Forum: CFEngine Help Subject: Reading lines into an array only if class matches Author: sauer Link to topic: https://cfengine.com/forum/read.php?3,26231,26231#msg-26231
So, I have a couple of situations where I want to populate an exclude list from an external file. For example, I want to remove the suid/sgid bits from executable files which are group or world-writeable, unless the file is in an approved list. I'd like to maintain the file in an external file formatted like class:filename I only want "filename" to be an excluded file if the class is a class which is set on the current system. What I'm currently thinking is that I could read the whole file into an array like array = class, make an slist of all the elements in array, then make a second array like "skipfiles[$(files)]" string => $(files), ifvarclass => allfiles[$(files)] I've got two problems with this. One is that a couple of the situations where I want to do this will involve something like 175K lines in the file, and in previous testing, I've found that CFEngine doesn't seem to handle arrays over around 40-50K elements real well at all. It seems to do better with arrays defined from reading files than with arrays defined inside the .cf files, though. But I haven't tested either with the newest version, so maybe that's improved. Anyone know anything about that? The second problem is that the current built-ins seemingly require me to put the filename as the first element in the file if I want to use it as the array index. I'll eventually go open a feature request for a function which allows an arbitrary field to be the index, but I really need a solution sooner than I'll be able to deploy an updated version of CFEngine. This "use the full path as the first field" thing won't work real well, because what delimiter do I use which isn't also potentially valid in a filename? There isn't one; the slash is the only invalid filename character, and that'll be in the path. Maybe I can use newlines as the field delimiter, as I can deal with not handling filenames which contain a newline (even though it's valid), but what do I do for a record delimiter then? \n\s+\n to find a blank line? If I could leave the filename at the end of the line, things would be easier, but then I need to create another unique identifier as the first field so t he array population will work. I don't know. I'd appreciate any input on solutions to this problem, including completely different directions. :) Maybe I should have a scond promise to make a copy of the first file which only contains lines that match currently-defined classes? I'm not sure exactly how I'd do that, either... :) _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine