@@ -3782,6 +3782,97 @@ 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 )
3822
+ {
3823
+ return OSVersionMinorPut (ctx , NULL );
3824
+ }
3825
+ if (name == NULL )
3826
+ {
3827
+ return OSVersionMinorPut (ctx , NULL );
3828
+ }
3829
+ Item * version_tuple = SplitString (version_id , '.' );
3830
+ if (version_tuple == NULL )
3831
+ {
3832
+ return OSVersionMinorPut (ctx , NULL );
3833
+ }
3834
+ if (name != NULL && (StringStartsWith (name , "solaris" ) || StringStartsWith (name , "sunos" )))
3835
+ {
3836
+ OSVersionMinorPut (ctx , version_tuple -> name );
3837
+ return DeleteItemList (version_tuple );
3838
+ }
3839
+ if (version_tuple -> next == NULL )
3840
+ {
3841
+ OSVersionMinorPut (ctx , NULL );
3842
+ return DeleteItemList (version_tuple );
3843
+ }
3844
+ OSVersionMinorPut (ctx , version_tuple -> next -> name );
3845
+ return DeleteItemList (version_tuple );
3846
+
3847
+ #else
3848
+
3849
+ char * release = SafeStringDuplicate (VSYSNAME .release );
3850
+ char * major = NULL ;
3851
+ char * minor = NULL ;
3852
+ char * rel ;
3853
+ rel = FindNextInteger (release , & major );
3854
+ if (rel == NULL )
3855
+ {
3856
+ free (release );
3857
+ EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3858
+ "os_version_minor" ,
3859
+ "Unknown" ,
3860
+ CF_DATA_TYPE_STRING ,
3861
+ "source=agent" );
3862
+ return ;
3863
+ }
3864
+ rel = FindNextInteger (rel , & minor );
3865
+ EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3866
+ "os_version_minor" ,
3867
+ (minor == NULL ) ? "Unknown" : minor ,
3868
+ CF_DATA_TYPE_STRING ,
3869
+ "source=agent" );
3870
+ free (release );
3871
+
3872
+ #endif
3873
+ }
3874
+
3875
+
3785
3876
/*****************************************************************************/
3786
3877
3787
3878
void DetectEnvironment (EvalContext * ctx )
@@ -3796,4 +3887,5 @@ void DetectEnvironment(EvalContext *ctx)
3796
3887
GetDefVars (ctx );
3797
3888
SysOSNameHuman (ctx );
3798
3889
SysOsVersionMajor (ctx );
3890
+ SysOSVersionMinor (ctx );
3799
3891
}
0 commit comments