@@ -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 );
@@ -1183,7 +1187,7 @@ static void OSReleaseParse(EvalContext *ctx, const char *file_path)
1183
1187
{
1184
1188
alias = "redhat" ;
1185
1189
}
1186
- else if (StringEqual (os_release_id , "opensuse" ) ||
1190
+ else if (StringEqual (os_release_id , "opensuse" ) ||
1187
1191
StringEqual (os_release_id , "sles" ))
1188
1192
{
1189
1193
alias = "suse" ;
@@ -1414,6 +1418,10 @@ static void OSClasses(EvalContext *ctx)
1414
1418
1415
1419
#else
1416
1420
1421
+ #ifdef __APPLE__
1422
+ Apple_Version (ctx );
1423
+ #endif
1424
+
1417
1425
char vbuff [CF_MAXVARSIZE ];
1418
1426
1419
1427
#ifdef _AIX
@@ -1423,6 +1431,7 @@ static void OSClasses(EvalContext *ctx)
1423
1431
#endif
1424
1432
1425
1433
1434
+ #ifndef __APPLE__
1426
1435
for (char * sp = vbuff ; * sp != '\0' ; sp ++ )
1427
1436
{
1428
1437
if (* sp == '-' )
@@ -1435,6 +1444,7 @@ static void OSClasses(EvalContext *ctx)
1435
1444
char context [CF_BUFSIZE ];
1436
1445
snprintf (context , CF_BUFSIZE , "%s_%s" , VSYSNAME .sysname , vbuff );
1437
1446
SetFlavor (ctx , context );
1447
+ #endif
1438
1448
1439
1449
1440
1450
#ifdef __hpux
@@ -1597,6 +1607,10 @@ static void OSClasses(EvalContext *ctx)
1597
1607
{
1598
1608
snprintf (vbuff , CF_BUFSIZE , "/var/cron/tabs/%s" , user_name );
1599
1609
}
1610
+ else if (EvalContextClassGet (ctx , NULL , "macos" ))
1611
+ {
1612
+ snprintf (vbuff , CF_BUFSIZE , "/usr/lib/cron/tabs/%s" , user_name );
1613
+ }
1600
1614
else
1601
1615
{
1602
1616
snprintf (vbuff , CF_BUFSIZE , "/var/spool/cron/crontabs/%s" , user_name );
@@ -1645,6 +1659,93 @@ static void OSClasses(EvalContext *ctx)
1645
1659
1646
1660
/*********************************************************************************/
1647
1661
1662
+ #ifdef __APPLE__
1663
+ static void Apple_Version (EvalContext * ctx )
1664
+ {
1665
+ FILE * pp = NULL ;
1666
+
1667
+ Log (LOG_LEVEL_VERBOSE , "This appears to be an apple system." );
1668
+ Log (LOG_LEVEL_VERBOSE , "Looking for product name and version..." );
1669
+ if ((!FileCanOpen ("/usr/bin/sw_vers" , "r" ) || ((pp = cf_popen ("/usr/bin/sw_vers" , "r" , true)) == NULL )))
1670
+ {
1671
+ Log (LOG_LEVEL_ERR , "Could not open and run /usr/bin/sw_vers to find macOS system version information." );
1672
+ return ;
1673
+ }
1674
+
1675
+ size_t line_size = CF_BUFSIZE ;
1676
+ char * line = xmalloc (line_size );
1677
+ int revcomps = 0 ;
1678
+ unsigned int major , minor , patch ;
1679
+ char * flavor = NULL , * product_name = NULL , * r ;
1680
+
1681
+ while (CfReadLine (& line , & line_size , pp ) != -1 )
1682
+ {
1683
+ if (STARTSWITH (line , "ProductName:" ))
1684
+ {
1685
+ r = strrchr (line , '\t' );
1686
+ if (r == NULL || ++ r == NULL )
1687
+ {
1688
+ continue ;
1689
+ }
1690
+ product_name = SafeStringDuplicate (r );
1691
+ ToLowerStrInplace (r );
1692
+ flavor = SafeStringDuplicate (r );
1693
+ EvalContextClassPutHard (
1694
+ ctx ,
1695
+ r ,
1696
+ "inventory,attribute_name=none,source=agent,derived-from=sw_vers" );
1697
+ }
1698
+ else if (STARTSWITH (line , "ProductVersion:" ))
1699
+ {
1700
+ r = strrchr (line , '\t' );
1701
+ if (r == NULL || ++ r == NULL )
1702
+ {
1703
+ continue ;
1704
+ }
1705
+ revcomps = sscanf (r , "%u.%u.%u" , & major , & minor , & patch );
1706
+ }
1707
+ }
1708
+
1709
+ if (flavor == NULL )
1710
+ {
1711
+ free (line );
1712
+ cf_pclose (pp );
1713
+ return ;
1714
+ }
1715
+
1716
+ char buf [CF_BUFSIZE ];
1717
+
1718
+ if (revcomps > 0 )
1719
+ {
1720
+ NDEBUG_UNUSED int ret = snprintf (buf , sizeof (buf ), "%s_%u" , flavor , major );
1721
+ assert (ret >= 0 && (size_t ) ret < sizeof (buf ));
1722
+ Log (LOG_LEVEL_VERBOSE , "This appears to be a %s %u system." , product_name , major );
1723
+ SetFlavor (ctx , buf );
1724
+ }
1725
+
1726
+ if (revcomps > 1 )
1727
+ {
1728
+ NDEBUG_UNUSED int ret = snprintf (buf , sizeof (buf ), "%s_%u_%u" , flavor , major , minor );
1729
+ assert (ret >= 0 && (size_t ) ret < sizeof (buf ));
1730
+ Log (LOG_LEVEL_VERBOSE , "This appears to be a %s %u.%u system." , product_name , major , minor );
1731
+ EvalContextClassPutHard (ctx , buf , "inventory,attribute_name=none,source=agent" );
1732
+ }
1733
+
1734
+ if (revcomps > 2 )
1735
+ {
1736
+ NDEBUG_UNUSED int ret = snprintf (buf , sizeof (buf ), "%s_%u_%u_%u" , flavor , major , minor , patch );
1737
+ assert (ret >= 0 && (size_t ) ret < sizeof (buf ));
1738
+ Log (LOG_LEVEL_VERBOSE , "This appears to be a %s %u.%u.%u system." , product_name , major , minor , patch );
1739
+ EvalContextClassPutHard (ctx , buf , "inventory,attribute_name=none,source=agent" );
1740
+ }
1741
+
1742
+ free (line );
1743
+ free (flavor );
1744
+ free (product_name );
1745
+ cf_pclose (pp );
1746
+ }
1747
+ #endif
1748
+
1648
1749
#ifdef __linux__
1649
1750
static void Linux_Oracle_VM_Server_Version (EvalContext * ctx )
1650
1751
{
@@ -3587,13 +3688,13 @@ static void SysOSNameHuman(EvalContext *ctx)
3587
3688
3588
3689
/**
3589
3690
* Find next integer from string in place. Leading zero's are included.
3590
- *
3691
+ *
3591
3692
* @param [in] str string to extract next integer from
3592
3693
* @param [out] num pointer to start of next integer or %NULL if no integer
3593
3694
* number was found
3594
- *
3695
+ *
3595
3696
* @return pointer to the remaining string in `str` or %NULL if no remainder
3596
- *
3697
+ *
3597
3698
* @note `str` will be mutated
3598
3699
*/
3599
3700
static char * FindNextInteger (char * str , char * * num )
@@ -3661,8 +3762,8 @@ static void SysOsVersionMajor(EvalContext *ctx)
3661
3762
}
3662
3763
else
3663
3764
{
3664
- EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3665
- "os_version_major" , major ,
3765
+ EvalContextVariablePutSpecial (ctx , SPECIAL_SCOPE_SYS ,
3766
+ "os_version_major" , major ,
3666
3767
CF_DATA_TYPE_STRING ,
3667
3768
"source=agent,derived-from=flavor" );
3668
3769
}
0 commit comments