@@ -2164,6 +2164,17 @@ static int Linux_Redhat_Version(EvalContext *ctx)
2164
2164
}
2165
2165
}
2166
2166
2167
+ // On CentOS 7, os-release VERSION_ID only shows the major version.
2168
+ // This updates it with major.minor from /etc/redhat-release
2169
+ if (minor >= 0 )
2170
+ {
2171
+ EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
2172
+ "os_version_minor" ,
2173
+ strminor ,
2174
+ CF_DATA_TYPE_STRING ,
2175
+ "source=agent,derived-from=redhat_release" );
2176
+ }
2177
+
2167
2178
return 0 ;
2168
2179
}
2169
2180
@@ -3782,6 +3793,97 @@ static void SysOsVersionMajor(EvalContext *ctx)
3782
3793
free (flavor );
3783
3794
}
3784
3795
3796
+ /*****************************************************************************/
3797
+
3798
+ static const char * OSReleaseGet (EvalContext * ctx , const char * field )
3799
+ {
3800
+ DataType type_out ;
3801
+ const JsonElement * os_rel = EvalContextVariableGetSpecial (
3802
+ ctx , SPECIAL_SCOPE_SYS , "os_release" , & type_out );
3803
+
3804
+ if (type_out != CF_DATA_TYPE_CONTAINER )
3805
+ {
3806
+ return NULL ;
3807
+ }
3808
+ const JsonElement * child = JsonObjectGet (os_rel , field );
3809
+ if (child == NULL )
3810
+ {
3811
+ return NULL ;
3812
+ }
3813
+ const char * result = JsonPrimitiveGetAsString (child );
3814
+ return result ;
3815
+ }
3816
+
3817
+ static void OSVersionMinorPut (EvalContext * ctx , const char * minor )
3818
+ {
3819
+ const char * value = (const char * ) EvalContextVariableGetSpecial (ctx , SPECIAL_SCOPE_SYS , "os_version_minor" , CF_DATA_TYPE_STRING );
3820
+ if (value == NULL )
3821
+ {
3822
+ EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3823
+ "os_version_minor" ,
3824
+ (minor == NULL ) ? "Unknown" : minor ,
3825
+ CF_DATA_TYPE_STRING ,
3826
+ "source=agent,derived-from=os_release" );
3827
+ }
3828
+ }
3829
+
3830
+ static void SysOSVersionMinor (EvalContext * ctx )
3831
+ {
3832
+ #ifndef __MINGW32__
3833
+
3834
+ const char * version_id = OSReleaseGet (ctx , "VERSION_ID" );
3835
+ const char * name = OSReleaseGet (ctx , "NAME" );
3836
+ if ((version_id == NULL ) || (name == NULL ))
3837
+ {
3838
+ return OSVersionMinorPut (ctx , NULL );
3839
+ }
3840
+ Item * version_tuple = SplitString (version_id , '.' );
3841
+ if (version_tuple == NULL )
3842
+ {
3843
+ return OSVersionMinorPut (ctx , NULL );
3844
+ }
3845
+ if (StringStartsWith (name , "solaris" ) || StringStartsWith (name , "sunos" ))
3846
+ {
3847
+ OSVersionMinorPut (ctx , version_tuple -> name );
3848
+ return DeleteItemList (version_tuple );
3849
+ }
3850
+ if (version_tuple -> next == NULL )
3851
+ {
3852
+ OSVersionMinorPut (ctx , NULL );
3853
+ return DeleteItemList (version_tuple );
3854
+ }
3855
+ OSVersionMinorPut (ctx , version_tuple -> next -> name );
3856
+ return DeleteItemList (version_tuple );
3857
+
3858
+ #else
3859
+
3860
+ char * release = SafeStringDuplicate (VSYSNAME .release );
3861
+ char * major = NULL ;
3862
+ char * minor = NULL ;
3863
+ char * rel ;
3864
+ rel = FindNextInteger (release , & major );
3865
+ if (rel == NULL )
3866
+ {
3867
+ free (release );
3868
+ EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3869
+ "os_version_minor" ,
3870
+ "Unknown" ,
3871
+ CF_DATA_TYPE_STRING ,
3872
+ "source=agent" );
3873
+ return ;
3874
+ }
3875
+ rel = FindNextInteger (rel , & minor );
3876
+ EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3877
+ "os_version_minor" ,
3878
+ (minor == NULL ) ? "Unknown" : minor ,
3879
+ CF_DATA_TYPE_STRING ,
3880
+ "source=agent" );
3881
+ free (release );
3882
+
3883
+ #endif
3884
+ }
3885
+
3886
+
3785
3887
/*****************************************************************************/
3786
3888
3787
3889
void DetectEnvironment (EvalContext * ctx )
@@ -3796,4 +3898,5 @@ void DetectEnvironment(EvalContext *ctx)
3796
3898
GetDefVars (ctx );
3797
3899
SysOSNameHuman (ctx );
3798
3900
SysOsVersionMajor (ctx );
3901
+ SysOSVersionMinor (ctx );
3799
3902
}
0 commit comments