-
Notifications
You must be signed in to change notification settings - Fork 36
Add support for negative values of the "instance" element of the textfilecontent54_object and textfilecontent54_state elements #146
base: master
Are you sure you want to change the base?
Conversation
the textfilecontent54_object and textfilecontent54_state elements
+1 to this. A very useful change that doesn't break compatibility because it defines undefined behavior. |
Shouldn't this be changing the independent schema instead of introducing a new file? It's very difficult to see what the actual change is. |
See also, #18 |
Question for you Martin, Let's say that there are 5 instances of a match in a file. If the object is constructed with -1, then will the matching item have (a) 5, or (b) -1? I am thinking (a) -- the item's instance value should be the same as it was originally. However, the way you've documented the instance entity of the textfilecontent54_state actually implies that scanners should produce TWO items for every instance found: one with the original value, and another with the negative value. That is the only way that permitting a negative number in the state will work reliably, as I think we should not permit the collection methodology to dictate the usability of a state. And if we were to do that, of course, we'd break any content that's actually counting the number of items, and potentially also any content that's using variable values based on textfilecontent54_item components. LMKWYT! |
For that matter... what to do, with a negative object/instance value and an operation like "greater than" or "less than"? I would say, perhaps we should require use of the "equals" operator in conjunction with a negative number (and enforce with a schematron rule), or assume in the case of negative numbers that the values end at 0? Say you wanted all but the last value. You could use "less than" -1. Say that you want only the last three values. You might think to use "greater than or equals" -3, but you certainly wouldn't want to start getting item matches with positive instance values! Did you have any thoughts about how to deal with these cases? |
Hmm, now I understand why the previous similar proposal had a new @iankko I had the impression that negative instance will only be allowed in |
If this proposal somehow only applied to the state entity, it would be the only state entity in the entire OVAL language that would require special item-set-aware processing, and I'd object to it on those grounds. My idea to make this proposal workable is to restrict negative values to the textfilecontent54_object/instance ONLY, with the following documentation for that object entity:
See beginning at line 1430: |
I prefer the idea of a direction directive. And for convenience, it would be nice to have some immediate indicator directive to specify using the first or last, which would be identical to first: instance=1 direction=forward or last: instance=1 direction=reverse |
I could add a "behavior" attribute. That would require adding an entity to the item/state types containing the direction, as adding an attribute to an item/state entity would deviate from the current operating conventions of the language, and hence wouldn't be appropriate for a minor version update. The major difference between the approaches would be how the items would combine, originating from different directions, when they are used together in the context of sets. The approach of permitting a negative value for the object instance makes it possible for identical item instances to be identified as such in sets, whereas that would not be possible if we use a behavior. |
@solind : I'm not sure what that would look like. Would you mind giving a specific example, perhaps using object_etc_security_limitsd_conf_maxlogins_exists from https://github.com/OpenSCAP/scap-security-guide/pull/1487/files |
What what would look like? With the existing proposal, to find the last instance of a pattern, you create this object:
This would produce the following item:
Using a behavior, the object would look like this:
Which would produce an item looking like this:
Notice such an item is quite distinct from a representation of the exact same line that would be produced by a different object:
So, it would not be possible for these items to match one-another if used in a set. Does that make sense? |
Thanks, @solind . Yes, it makes sense. Of the two, behaviors direction="backwards" will certainly be easier for a newbie to understand. I suspect that it would result in fewer errors in the long term, due to human factors, even among experts. |
@iankko, @mpreisler, any comment? I'd personally prefer the negative object instance entity because it remains potentially useful in sets (and because I already implemented the change in the 5.11.2 branch, so, less new work for me), but I could be talked into the change if there's a consensus. |
Hi David, AFAIK Wouldn't new |
The issue here is sometimes it might be necessary for the content author to specify they want last item in the object, not just in the state. That's why the proposal touches / changes both. |
In the light of the above I agree the negative indices might be confusing when used in connection with greater than or less than operations.
Correct.
Agree here too.
The original proposal was thinking about negative index like But having said the above I realize this Python notation might be confusing to "traditional" meaning of Long story short, after reviewing the proposal I agree the While on the topic of adding attributes to the |
I meant a new "direction" attribute in the existing behavior entity. A corresponding direction entity must then be added to the state and item types, as illustrated by the examples I provided. |
Yeah, got this once have looked at all the comments. Ignore that comment. Thanks. |
The issue I have with adding a direction to the behaviors is that it exposes the direction as a "first-class" concept -- something that will always show up in the item results themselves. Whereas just allowing the object to have a negative instance number to count back from the end feels like more of a convenient "trick". I'd think 99% of the time, you'll use the test as it currently exists, or use These are all easy to implement, that's not the issue. It's just a question of how polluted and overloaded we want to make the textfilecontent54_object. And I'm really not sure about adding a sorting behavior. Sorting seems like something that should be handled by a function, not by the textfilecontent54_object. Maybe we should have a SelectFunctionType instead? For example, this function would let you order the items for some object by one field, selecting the (first or last) value of another field:
|
In certain scenarios it is necessary to obtain not the first, but the last match of a specific match in the
<textfilecontent54_object>
and<textfilecontent54_state>
elements.This situation happens when the textfilecontent file allows multiple occurrences of the same directive to be present, and have different values. And at the end, value of the directive specified as the last one is truly used for the configuration of the system. Examples of such configuration files:
/etc/login.defs
,/etc/profile
,/etc/bashrc
,/etc/csh.cshrc
There are more configuration files / services following this behavioral pattern. More representatives of them can be provided upon request if necessary.
The
instance
element of<textfilecontent54_object>
and<textfilecontent54_state>
allows to specify particular match, that should be retrieved (first match will have value of1
, second value of2
, and so on.) But since when retrievingtextfilecontent54
file content it is not know, how many instances of specific directive will be present, it's currently not possible to obtain the last one (that will be taken in effect).Therefore we propose enhancement of the
instance
element of the<textfilecontent54_object>
and<textfilecontent54_state>
complex elements to support also negative values with the meaning as follows:-1
,-2
,Additional Information: It was not necessary to change the current OVAL datatype for the
<instance>
element, since the current type (oval-def:EntityObjectIntType
) is able to handle also negative numbers. Therefore we enhanced just the documentation for the<instance>
element of these two complex element to documented the desired / modified behavior.Regards, Jan