cfengine/0001-Simplify-and-fix-parsing-of-etc-SuSE-release-fixes-i.patch

267 lines
11 KiB
Diff
Raw Normal View History

From 00f764ed46713ea95a26836404b93aa6df899b59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= <kkaempf@suse.de>
Date: Fri, 11 Apr 2014 09:25:05 +0200
Subject: [PATCH 1/3] Simplify and fix parsing of /etc/SuSE-release (fixes
- Update to 3.6.1 New features: - Introduced Solaris and AIX support into the 3.6 series, with many associated build and bug fixes. Changes: - Short-circuit evaluation of classes promises if class is already set (Redmine #5241) - fix to assume all non-specified return codes are failed in commands promises (Redmine #5986) - cf-serverd logs reconfiguration message to NOTICE (was INFO) so that it's always logged in syslog Bug fixes: - File monitoring has been completely rewritten (changes attribute in files promise), which eliminates many bugs, particularly regarding files that are deleted. Upgrading will keep all monitoring data, but downgrading again will reinitialize the DB, so all files will be reported as if they were new. (Redmine #2917) - $(this.promiser) expands in files promises for 'transformer', 'edit_template', 'copy_from.source', 'file_select.exec_program', 'classes' and 'action' bodies (Redmine #1554, #1496, #3530, #1563) - 'body changes' notifies about disappeared files in file monitoring (Redmine #2917) - Set not-kept classes when files or commands promise should be repaired, but is warn-only (Redmine #2359) - Fixed CFEngine template producing a zero-sized file (Redmine #6088) - Add 0-9 A-Z _ to allowed context of module protocol (Redmine #6063) - Extend ps command column width on Solaris and filter on zone rather than adding it to the ps output. - Fixed strftime() function on Solaris when called with certain specifiers. OBS-URL: https://build.opensuse.org/package/show/systemsmanagement/cfengine?expand=0&rev=101
2014-07-29 09:09:25 +00:00
issue #5423)
This patch is a simplification of sysinfo.c:Linux_Suse_Version()
to achieve the following
- distinction between "SUSE Linux Enterprise Server" (sles) and "... Desktop" (sled)
- distinction between SUSE Linux Enterprise products (suse) and openSUSE (opensuse)
- extract version from VERSION and PATCHLEVEL lines instead of
first line of /etc/SuSE-release
- verified for sles version 9,10,11,12; sled versions 10,11,12, openSUSE 13.1
---
- Update to 3.12.0 (LTS) New Features: - Add a --key-type option to specify RSA key size to cf-key - New hash_to_int policy function (CFE-2733) - Issue a warning on ignored locking attributes (CFE-2748) - Add IPv6 hard classes with the "ipv6_" prefix (CFE-2310) - Introduce "missing_ok" attribute in body copy_from This allows to ignore missing sources in file copy operations (CFE-2365) - Enable Xen hypervisor detection on all x86 platforms (CFE-2203) - Add sys.policy_entry variables (CFE-2572) - Added inline_mustache template method (CFE-1846) - New component cf-net (cf-net is a CLI for the CFEngine network protocol, useful for debugging, testing etc) and accompanying policy variable sys.cf_net containing path to cf-net binary - Added --log-level option to all components This allows you to specify any log level (info, verbose, debug etc.). It is also less strict, allowing different spelling. As an example, --log-level i, --log-level INFO, --log-level inform are all the same. - Added special behavior for bundles named __main__ If the bundle is defined in the entry policy it will be defined as main. If the bundle is defined elsewhere, it will be removed. This makes it easy to make importable library policy which can also be executed directly. - See https://github.com/cfengine/core/blob/3.12.x/ChangeLog for other changes and bug fixes - drop 0003-CFE-2629-Openssl-1.1-compatibility.patch (upstream) drop reproducible.patch (upstream) OBS-URL: https://build.opensuse.org/package/show/systemsmanagement/cfengine?expand=0&rev=174
2018-07-03 08:05:49 +00:00
libenv/sysinfo.c | 187 +++++++++++++++--------------------------------
1 file changed, 60 insertions(+), 127 deletions(-)
diff --git a/libenv/sysinfo.c b/libenv/sysinfo.c
index 8a3d4f05174f..a6b1618c6a70 100644
--- a/libenv/sysinfo.c
+++ b/libenv/sysinfo.c
@@ -1963,6 +1963,7 @@ static int Linux_Suse_Version(EvalContext *ctx)
#define SUSE_RELEASE_FLAG "linux "
char classbuf[CF_MAXVARSIZE];
+ char *vendor = "suse";
Log(LOG_LEVEL_VERBOSE, "This appears to be a SUSE system.");
EvalContextClassPutHard(ctx, "SUSE", "inventory,attribute_name=none,source=agent");
@@ -1982,23 +1983,26 @@ static int Linux_Suse_Version(EvalContext *ctx)
return 1;
}
- char vbuf[CF_BUFSIZE], strversion[CF_MAXVARSIZE], strpatch[CF_MAXVARSIZE];
- strversion[0] = '\0';
- strpatch[0] = '\0';
+ char vbuf[CF_BUFSIZE];
int major = -1, minor = -1;
while (fgets(vbuf, sizeof(vbuf), fp) != NULL)
{
if (strncmp(vbuf, "VERSION", strlen("version")) == 0)
{
- strlcpy(strversion, vbuf, sizeof(strversion));
- sscanf(vbuf, "VERSION = %d", &major);
+ int res;
+ res = sscanf(vbuf, "VERSION = %d.%d", &major, &minor);
+ Log(LOG_LEVEL_VERBOSE, "VERSION sscanf returned %d.", res);
+ if (res < 1)
+ major = -1;
+ else if (res < 2)
+ minor = -1;
}
if (strncmp(vbuf, "PATCH", strlen("PATCH")) == 0)
{
- strlcpy(strpatch, vbuf, sizeof(strpatch));
- sscanf(vbuf, "PATCHLEVEL = %d", &minor);
+ if (sscanf(vbuf, "PATCHLEVEL = %d", &minor) != 1)
+ minor = -1;
}
}
if (ferror(fp))
@@ -2012,28 +2016,38 @@ static int Linux_Suse_Version(EvalContext *ctx)
fclose(fp);
- /* Check if it's a SUSE Enterprise version */
+ /* Check which SUSE/openSUSE product it is */
- Log(LOG_LEVEL_VERBOSE, "Looking for SUSE enterprise info in '%s'", relstring);
+ Log(LOG_LEVEL_VERBOSE, "Looking for SUSE product info in '%s'", relstring);
- /* Convert relstring to lowercase to handle rename of SuSE to
- * SUSE with SUSE 10.0.
- */
-
- for (int i = 0; i < strlen(relstring); i++)
+ if (!strncasecmp(relstring, SUSE_SLES8_ID, strlen(SUSE_SLES8_ID)))
{
- relstring[i] = tolower(relstring[i]);
+ EvalContextClassPutHard(ctx, "SLES8", "inventory,attribute_name=none,source=agent");
}
-
- /* Check if it's a SUSE Enterprise version (all in lowercase) */
-
- if (!strncmp(relstring, SUSE_SLES8_ID, strlen(SUSE_SLES8_ID)))
+ else if (!strncasecmp(relstring, SUSE_SLES_ID, strlen(SUSE_SLES_ID)))
{
- classbuf[0] = '\0';
- strcat(classbuf, "SLES8");
- EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
+ EvalContextClassPutHard(ctx, "sles", "inventory,attribute_name=none,source=agent");
+ if (major != -1)
+ {
+ snprintf(classbuf, CF_MAXVARSIZE, "SLES%d", major);
+ EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
+ }
+ }
+ else if (!strncasecmp(relstring, SUSE_SLED_ID, strlen(SUSE_SLED_ID)))
+ {
+ EvalContextClassPutHard(ctx, "sled", "inventory,attribute_name=none,source=agent");
+ if (major != -1)
+ {
+ snprintf(classbuf, CF_MAXVARSIZE, "SLED%d", major);
+ EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
+ }
+ }
+ else if (!strncasecmp(relstring, "opensuse", strlen("opensuse")))
+ {
+ vendor = "opensuse";
+ EvalContextClassPutHard(ctx, vendor, "inventory,attribute_name=none,source=agent");
}
- else if (strncmp(relstring, "sles", 4) == 0)
+ else if (strncasecmp(relstring, "sles", 4) == 0)
{
Item *list, *ip;
@@ -2051,120 +2065,39 @@ static int Linux_Suse_Version(EvalContext *ctx)
}
else
{
- for (int version = 9; version < 13; version++)
- {
- snprintf(vbuf, CF_BUFSIZE, "%s %d ", SUSE_SLES_ID, version);
- Log(LOG_LEVEL_DEBUG, "Checking for SUSE [%s]", vbuf);
-
- if (!strncmp(relstring, vbuf, strlen(vbuf)))
- {
- snprintf(classbuf, CF_MAXVARSIZE, "SLES%d", version);
- EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
- }
- else
- {
- snprintf(vbuf, CF_BUFSIZE, "%s %d ", SUSE_SLED_ID, version);
- Log(LOG_LEVEL_DEBUG, "Checking for SUSE [%s]", vbuf);
-
- if (!strncmp(relstring, vbuf, strlen(vbuf)))
- {
- snprintf(classbuf, CF_MAXVARSIZE, "SLED%d", version);
- EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
- }
- }
- }
+ Log(LOG_LEVEL_WARNING, "Unknown product '%s' in /etc/SuSE-release", relstring);
}
- /* Determine release version. We assume that the version follows
- * the string "SuSE Linux" or "SUSE LINUX".
- */
-
- char *release = strstr(relstring, SUSE_RELEASE_FLAG);
- if (release == NULL)
+ if (major != -1)
{
- release = strstr(relstring, "opensuse");
- if (release == NULL)
+ strncpy(classbuf, vendor, CF_MAXVARSIZE);
+ EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
+ snprintf(classbuf + strlen(classbuf), CF_MAXVARSIZE - strlen(classbuf), "_%d", major);
+ SetFlavour(ctx, classbuf);
+ if (minor != -1)
{
- release = strversion;
+ snprintf(classbuf + strlen(classbuf), CF_MAXVARSIZE - strlen(classbuf), "_%d", minor);
+ EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
}
- }
-
- if (release == NULL)
- {
- Log(LOG_LEVEL_VERBOSE,
- "Could not find a numeric OS release in %s",
- SUSE_REL_FILENAME);
- return 2;
+ /* The correct spelling for SUSE is "SUSE" but CFEngine used to use "SuSE".
+ * Keep this for backwards compatibility until CFEngine 3.7
+ */
+ strncpy(classbuf, "SuSE", CF_MAXVARSIZE);
+ EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
+ snprintf(classbuf + strlen(classbuf), CF_MAXVARSIZE - strlen(classbuf), "_%d", major);
+ EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
+ if (minor != -1)
+ {
+ snprintf(classbuf + strlen(classbuf), CF_MAXVARSIZE - strlen(classbuf), "_%d", minor);
+ EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
+ }
+ Log(LOG_LEVEL_VERBOSE, "Discovered %s version %d.%d", vendor, major, minor);
}
else
{
- char strmajor[PRINTSIZE(major)], strminor[PRINTSIZE(minor)];
- if (strchr(release, '.'))
- {
- sscanf(release, "%*s %d.%d", &major, &minor);
- Update to 3.6.1 New features: - Introduced Solaris and AIX support into the 3.6 series, with many associated build and bug fixes. Changes: - Short-circuit evaluation of classes promises if class is already set (Redmine #5241) - fix to assume all non-specified return codes are failed in commands promises (Redmine #5986) - cf-serverd logs reconfiguration message to NOTICE (was INFO) so that it's always logged in syslog Bug fixes: - File monitoring has been completely rewritten (changes attribute in files promise), which eliminates many bugs, particularly regarding files that are deleted. Upgrading will keep all monitoring data, but downgrading again will reinitialize the DB, so all files will be reported as if they were new. (Redmine #2917) - $(this.promiser) expands in files promises for 'transformer', 'edit_template', 'copy_from.source', 'file_select.exec_program', 'classes' and 'action' bodies (Redmine #1554, #1496, #3530, #1563) - 'body changes' notifies about disappeared files in file monitoring (Redmine #2917) - Set not-kept classes when files or commands promise should be repaired, but is warn-only (Redmine #2359) - Fixed CFEngine template producing a zero-sized file (Redmine #6088) - Add 0-9 A-Z _ to allowed context of module protocol (Redmine #6063) - Extend ps command column width on Solaris and filter on zone rather than adding it to the ps output. - Fixed strftime() function on Solaris when called with certain specifiers. OBS-URL: https://build.opensuse.org/package/show/systemsmanagement/cfengine?expand=0&rev=101
2014-07-29 09:09:25 +00:00
- xsnprintf(strmajor, sizeof(strmajor), "%d", major);
- xsnprintf(strminor, sizeof(strminor), "%d", minor);
-
- if (major != -1 && minor != -1)
- {
- strcpy(classbuf, "SUSE");
- EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
- strcat(classbuf, "_");
- strcat(classbuf, strmajor);
- Update to 3.12.0 (LTS) New Features: - Add a --key-type option to specify RSA key size to cf-key - New hash_to_int policy function (CFE-2733) - Issue a warning on ignored locking attributes (CFE-2748) - Add IPv6 hard classes with the "ipv6_" prefix (CFE-2310) - Introduce "missing_ok" attribute in body copy_from This allows to ignore missing sources in file copy operations (CFE-2365) - Enable Xen hypervisor detection on all x86 platforms (CFE-2203) - Add sys.policy_entry variables (CFE-2572) - Added inline_mustache template method (CFE-1846) - New component cf-net (cf-net is a CLI for the CFEngine network protocol, useful for debugging, testing etc) and accompanying policy variable sys.cf_net containing path to cf-net binary - Added --log-level option to all components This allows you to specify any log level (info, verbose, debug etc.). It is also less strict, allowing different spelling. As an example, --log-level i, --log-level INFO, --log-level inform are all the same. - Added special behavior for bundles named __main__ If the bundle is defined in the entry policy it will be defined as main. If the bundle is defined elsewhere, it will be removed. This makes it easy to make importable library policy which can also be executed directly. - See https://github.com/cfengine/core/blob/3.12.x/ChangeLog for other changes and bug fixes - drop 0003-CFE-2629-Openssl-1.1-compatibility.patch (upstream) drop reproducible.patch (upstream) OBS-URL: https://build.opensuse.org/package/show/systemsmanagement/cfengine?expand=0&rev=174
2018-07-03 08:05:49 +00:00
- SetFlavor(ctx, classbuf);
- strcat(classbuf, "_");
- strcat(classbuf, strminor);
- EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
-
- /* The correct spelling for SUSE is "SUSE" but CFEngine used to use "SuSE".
- * Keep this for backwards compatibility until CFEngine 3.7
- */
- strcpy(classbuf, "SuSE");
- EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
- strcat(classbuf, "_");
- strcat(classbuf, strmajor);
- EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
- strcat(classbuf, "_");
- strcat(classbuf, strminor);
- EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
-
- Log(LOG_LEVEL_VERBOSE, "Discovered SUSE version %s", classbuf);
- return 0;
- }
- }
- else
- {
- sscanf(strversion, "VERSION = %s", strmajor);
- sscanf(strpatch, "PATCHLEVEL = %s", strminor);
-
- if (major != -1 && minor != -1)
- {
- strcpy(classbuf, "SLES");
- EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
- strcat(classbuf, "_");
- strcat(classbuf, strmajor);
- EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
- strcat(classbuf, "_");
- strcat(classbuf, strminor);
- EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
-
- snprintf(classbuf, CF_MAXVARSIZE, "SUSE_%d", major);
- Update to 3.12.0 (LTS) New Features: - Add a --key-type option to specify RSA key size to cf-key - New hash_to_int policy function (CFE-2733) - Issue a warning on ignored locking attributes (CFE-2748) - Add IPv6 hard classes with the "ipv6_" prefix (CFE-2310) - Introduce "missing_ok" attribute in body copy_from This allows to ignore missing sources in file copy operations (CFE-2365) - Enable Xen hypervisor detection on all x86 platforms (CFE-2203) - Add sys.policy_entry variables (CFE-2572) - Added inline_mustache template method (CFE-1846) - New component cf-net (cf-net is a CLI for the CFEngine network protocol, useful for debugging, testing etc) and accompanying policy variable sys.cf_net containing path to cf-net binary - Added --log-level option to all components This allows you to specify any log level (info, verbose, debug etc.). It is also less strict, allowing different spelling. As an example, --log-level i, --log-level INFO, --log-level inform are all the same. - Added special behavior for bundles named __main__ If the bundle is defined in the entry policy it will be defined as main. If the bundle is defined elsewhere, it will be removed. This makes it easy to make importable library policy which can also be executed directly. - See https://github.com/cfengine/core/blob/3.12.x/ChangeLog for other changes and bug fixes - drop 0003-CFE-2629-Openssl-1.1-compatibility.patch (upstream) drop reproducible.patch (upstream) OBS-URL: https://build.opensuse.org/package/show/systemsmanagement/cfengine?expand=0&rev=174
2018-07-03 08:05:49 +00:00
- SetFlavor(ctx, classbuf);
-
- /* The correct spelling for SUSE is "SUSE" but CFEngine used to use "SuSE".
- * Keep this for backwards compatibility until CFEngine 3.7
- */
- snprintf(classbuf, CF_MAXVARSIZE, "SuSE_%d", major);
- EvalContextClassPutHard(ctx, classbuf, "source=agent");
-
- Log(LOG_LEVEL_VERBOSE, "Discovered SUSE version %s", classbuf);
- return 0;
- }
- }
+ Log(LOG_LEVEL_VERBOSE, "Could not find a numeric OS release in %s", SUSE_REL_FILENAME);
}
- Log(LOG_LEVEL_VERBOSE, "Could not find a numeric OS release in %s", SUSE_REL_FILENAME);
-
return 0;
}
--
2.24.0