@@ -3782,6 +3782,93 @@ static void SysOsVersionMajor(EvalContext *ctx)
3782
3782
free (flavor );
3783
3783
}
3784
3784
3785
+ /*****************************************************************************/
3786
+
3787
+ static const char * OSReleaseGet (EvalContext * ctx , const char * field )
3788
+ {
3789
+ DataType type_out ;
3790
+ const JsonElement * os_rel = EvalContextVariableGetSpecial (
3791
+ ctx , SPECIAL_SCOPE_SYS , "os_release" , & type_out );
3792
+
3793
+ if (type_out != CF_DATA_TYPE_CONTAINER )
3794
+ {
3795
+ return NULL ;
3796
+ }
3797
+ const JsonElement * child = JsonObjectGet (os_rel , field );
3798
+ if (child == NULL )
3799
+ {
3800
+ return NULL ;
3801
+ }
3802
+ const char * result = JsonPrimitiveGetAsString (child );
3803
+ return result ;
3804
+ }
3805
+
3806
+ static void OSVersionMinorPut (EvalContext * ctx , const char * minor )
3807
+ {
3808
+ EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3809
+ "os_version_minor" ,
3810
+ (minor == NULL ) ? "Unknown" : minor ,
3811
+ CF_DATA_TYPE_STRING ,
3812
+ "source=agent,derived-from=os_release" );
3813
+ }
3814
+
3815
+ static void SysOSVersionMinor (EvalContext * ctx )
3816
+ {
3817
+ #ifndef __MINGW32__
3818
+
3819
+ const char * version_id = OSReleaseGet (ctx , "VERSION_ID" );
3820
+ const char * name = OSReleaseGet (ctx , "NAME" );
3821
+ if ((version_id == NULL ) || (name == NULL ))
3822
+ {
3823
+ return OSVersionMinorPut (ctx , NULL );
3824
+ }
3825
+ Item * version_tuple = SplitString (version_id , '.' );
3826
+ if (version_tuple == NULL )
3827
+ {
3828
+ return OSVersionMinorPut (ctx , NULL );
3829
+ }
3830
+ if (StringStartsWith (name , "solaris" ) || StringStartsWith (name , "sunos" ))
3831
+ {
3832
+ OSVersionMinorPut (ctx , version_tuple -> name );
3833
+ return DeleteItemList (version_tuple );
3834
+ }
3835
+ if (version_tuple -> next == NULL )
3836
+ {
3837
+ OSVersionMinorPut (ctx , NULL );
3838
+ return DeleteItemList (version_tuple );
3839
+ }
3840
+ OSVersionMinorPut (ctx , version_tuple -> next -> name );
3841
+ return DeleteItemList (version_tuple );
3842
+
3843
+ #else
3844
+
3845
+ char * release = SafeStringDuplicate (VSYSNAME .release );
3846
+ char * major = NULL ;
3847
+ char * minor = NULL ;
3848
+ char * rel ;
3849
+ rel = FindNextInteger (release , & major );
3850
+ if (rel == NULL )
3851
+ {
3852
+ free (release );
3853
+ EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3854
+ "os_version_minor" ,
3855
+ "Unknown" ,
3856
+ CF_DATA_TYPE_STRING ,
3857
+ "source=agent" );
3858
+ return ;
3859
+ }
3860
+ rel = FindNextInteger (rel , & minor );
3861
+ EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3862
+ "os_version_minor" ,
3863
+ (minor == NULL ) ? "Unknown" : minor ,
3864
+ CF_DATA_TYPE_STRING ,
3865
+ "source=agent" );
3866
+ free (release );
3867
+
3868
+ #endif
3869
+ }
3870
+
3871
+
3785
3872
/*****************************************************************************/
3786
3873
3787
3874
void DetectEnvironment (EvalContext * ctx )
@@ -3796,4 +3883,5 @@ void DetectEnvironment(EvalContext *ctx)
3796
3883
GetDefVars (ctx );
3797
3884
SysOSNameHuman (ctx );
3798
3885
SysOsVersionMajor (ctx );
3886
+ SysOSVersionMinor (ctx );
3799
3887
}
0 commit comments