@@ -161,6 +161,10 @@ void CalculateDomainName(const char *nodename, const char *dnsname,
161
161
char * uqname , size_t uqname_size ,
162
162
char * domain , size_t domain_size );
163
163
164
+ #ifdef __APPLE__
165
+ static void Apple_Version (EvalContext * ctx );
166
+ #endif
167
+
164
168
#ifdef __linux__
165
169
static int Linux_Fedora_Version (EvalContext * ctx );
166
170
static int Linux_Redhat_Version (EvalContext * ctx );
@@ -1179,7 +1183,7 @@ static void OSReleaseParse(EvalContext *ctx, const char *file_path)
1179
1183
{
1180
1184
alias = "redhat" ;
1181
1185
}
1182
- else if (StringEqual (os_release_id , "opensuse" ) ||
1186
+ else if (StringEqual (os_release_id , "opensuse" ) ||
1183
1187
StringEqual (os_release_id , "sles" ))
1184
1188
{
1185
1189
alias = "suse" ;
@@ -1410,6 +1414,10 @@ static void OSClasses(EvalContext *ctx)
1410
1414
1411
1415
#else
1412
1416
1417
+ #ifdef __APPLE__
1418
+ Apple_Version (ctx );
1419
+ #endif
1420
+
1413
1421
char vbuff [CF_MAXVARSIZE ];
1414
1422
1415
1423
#ifdef _AIX
@@ -1419,6 +1427,7 @@ static void OSClasses(EvalContext *ctx)
1419
1427
#endif
1420
1428
1421
1429
1430
+ #ifndef __APPLE__
1422
1431
for (char * sp = vbuff ; * sp != '\0' ; sp ++ )
1423
1432
{
1424
1433
if (* sp == '-' )
@@ -1431,6 +1440,7 @@ static void OSClasses(EvalContext *ctx)
1431
1440
char context [CF_BUFSIZE ];
1432
1441
snprintf (context , CF_BUFSIZE , "%s_%s" , VSYSNAME .sysname , vbuff );
1433
1442
SetFlavor (ctx , context );
1443
+ #endif
1434
1444
1435
1445
1436
1446
#ifdef __hpux
@@ -1593,6 +1603,10 @@ static void OSClasses(EvalContext *ctx)
1593
1603
{
1594
1604
snprintf (vbuff , CF_BUFSIZE , "/var/cron/tabs/%s" , user_name );
1595
1605
}
1606
+ else if (EvalContextClassGet (ctx , NULL , "macos" ))
1607
+ {
1608
+ snprintf (vbuff , CF_BUFSIZE , "/usr/lib/cron/tabs/%s" , user_name );
1609
+ }
1596
1610
else
1597
1611
{
1598
1612
snprintf (vbuff , CF_BUFSIZE , "/var/spool/cron/crontabs/%s" , user_name );
@@ -1641,6 +1655,93 @@ static void OSClasses(EvalContext *ctx)
1641
1655
1642
1656
/*********************************************************************************/
1643
1657
1658
+ #ifdef __APPLE__
1659
+ static void Apple_Version (EvalContext * ctx )
1660
+ {
1661
+ FILE * pp = NULL ;
1662
+
1663
+ Log (LOG_LEVEL_VERBOSE , "This appears to be an apple system." );
1664
+ Log (LOG_LEVEL_VERBOSE , "Looking for product name and version..." );
1665
+ if ((!FileCanOpen ("/usr/bin/sw_vers" , "r" ) || ((pp = cf_popen ("/usr/bin/sw_vers" , "r" , true)) == NULL )))
1666
+ {
1667
+ Log (LOG_LEVEL_ERR , "Could not open and run /usr/bin/sw_vers to find macOS system version information." );
1668
+ return ;
1669
+ }
1670
+
1671
+ size_t line_size = CF_BUFSIZE ;
1672
+ char * line = xmalloc (line_size );
1673
+ int revcomps = 0 ;
1674
+ unsigned int major , minor , patch ;
1675
+ char * flavor = NULL , * product_name = NULL , * r ;
1676
+
1677
+ while (CfReadLine (& line , & line_size , pp ) != -1 )
1678
+ {
1679
+ if (STARTSWITH (line , "ProductName:" ))
1680
+ {
1681
+ r = strrchr (line , '\t' );
1682
+ if (r == NULL || ++ r == NULL )
1683
+ {
1684
+ continue ;
1685
+ }
1686
+ product_name = SafeStringDuplicate (r );
1687
+ ToLowerStrInplace (r );
1688
+ flavor = SafeStringDuplicate (r );
1689
+ EvalContextClassPutHard (
1690
+ ctx ,
1691
+ r ,
1692
+ "inventory,attribute_name=none,source=agent,derived-from=sw_vers" );
1693
+ }
1694
+ else if (STARTSWITH (line , "ProductVersion:" ))
1695
+ {
1696
+ r = strrchr (line , '\t' );
1697
+ if (r == NULL || ++ r == NULL )
1698
+ {
1699
+ continue ;
1700
+ }
1701
+ revcomps = sscanf (r , "%u.%u.%u" , & major , & minor , & patch );
1702
+ }
1703
+ }
1704
+
1705
+ if (flavor == NULL )
1706
+ {
1707
+ free (line );
1708
+ cf_pclose (pp );
1709
+ return ;
1710
+ }
1711
+
1712
+ char buf [CF_BUFSIZE ];
1713
+
1714
+ if (revcomps > 0 )
1715
+ {
1716
+ NDEBUG_UNUSED int ret = snprintf (buf , sizeof (buf ), "%s_%u" , flavor , major );
1717
+ assert (ret >= 0 && (size_t ) ret < sizeof (buf ));
1718
+ Log (LOG_LEVEL_VERBOSE , "This appears to be a %s %u system." , product_name , major );
1719
+ SetFlavor (ctx , buf );
1720
+ }
1721
+
1722
+ if (revcomps > 1 )
1723
+ {
1724
+ NDEBUG_UNUSED int ret = snprintf (buf , sizeof (buf ), "%s_%u_%u" , flavor , major , minor );
1725
+ assert (ret >= 0 && (size_t ) ret < sizeof (buf ));
1726
+ Log (LOG_LEVEL_VERBOSE , "This appears to be a %s %u.%u system." , product_name , major , minor );
1727
+ EvalContextClassPutHard (ctx , buf , "inventory,attribute_name=none,source=agent" );
1728
+ }
1729
+
1730
+ if (revcomps > 2 )
1731
+ {
1732
+ NDEBUG_UNUSED int ret = snprintf (buf , sizeof (buf ), "%s_%u_%u_%u" , flavor , major , minor , patch );
1733
+ assert (ret >= 0 && (size_t ) ret < sizeof (buf ));
1734
+ Log (LOG_LEVEL_VERBOSE , "This appears to be a %s %u.%u.%u system." , product_name , major , minor , patch );
1735
+ EvalContextClassPutHard (ctx , buf , "inventory,attribute_name=none,source=agent" );
1736
+ }
1737
+
1738
+ free (line );
1739
+ free (flavor );
1740
+ free (product_name );
1741
+ cf_pclose (pp );
1742
+ }
1743
+ #endif
1744
+
1644
1745
#ifdef __linux__
1645
1746
static void Linux_Oracle_VM_Server_Version (EvalContext * ctx )
1646
1747
{
@@ -3583,13 +3684,13 @@ static void SysOSNameHuman(EvalContext *ctx)
3583
3684
3584
3685
/**
3585
3686
* Find next integer from string in place. Leading zero's are included.
3586
- *
3687
+ *
3587
3688
* @param [in] str string to extract next integer from
3588
3689
* @param [out] num pointer to start of next integer or %NULL if no integer
3589
3690
* number was found
3590
- *
3691
+ *
3591
3692
* @return pointer to the remaining string in `str` or %NULL if no remainder
3592
- *
3693
+ *
3593
3694
* @note `str` will be mutated
3594
3695
*/
3595
3696
static char * FindNextInteger (char * str , char * * num )
@@ -3657,8 +3758,8 @@ static void SysOsVersionMajor(EvalContext *ctx)
3657
3758
}
3658
3759
else
3659
3760
{
3660
- EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3661
- "os_version_major" , major ,
3761
+ EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3762
+ "os_version_major" , major ,
3662
3763
CF_DATA_TYPE_STRING ,
3663
3764
"source=agent,derived-from=flavor" );
3664
3765
}
0 commit comments