- add 0002-Do-not-segfault-on-type-checking-NULL-Rvals.patch
to prevent crash on syntax error - add 0007-Simplify-and-fix-parsing-of-etc-SuSE-release-fixes-i.patch * add 'suse' class for consistency with other vendor classes (fixes #5417) * 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 - merge cfengine-server with cfengine. A policy server only gets cfengine-masterfiles but is otherwise identical to a client. OBS-URL: https://build.opensuse.org/package/show/systemsmanagement/cfengine?expand=0&rev=89
This commit is contained in:
parent
3b8d16732a
commit
fac2b5148b
@ -1,188 +0,0 @@
|
||||
From 5edafd6237e80109f5d1ca8410ff9772dbc41635 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= <kkaempf@suse.de>
|
||||
Date: Fri, 4 Apr 2014 21:20:48 +0200
|
||||
Subject: [PATCH] Check /etc/os-release for distribution information
|
||||
|
||||
Vendor specific <vendor>-release files are deprecated in favor of
|
||||
generic /etc/os-release files.
|
||||
|
||||
This patch extracts product and version information from /etc/os-release
|
||||
and creates respective classes.
|
||||
---
|
||||
libenv/sysinfo.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 146 insertions(+)
|
||||
|
||||
diff --git a/libenv/sysinfo.c b/libenv/sysinfo.c
|
||||
index 9c89c57cbf5e..901791220855 100644
|
||||
--- a/libenv/sysinfo.c
|
||||
+++ b/libenv/sysinfo.c
|
||||
@@ -114,6 +114,7 @@ static time_t GetBootTimeFromUptimeCommand(time_t); // Last resort
|
||||
void CalculateDomainName(const char *nodename, const char *dnsname, char *fqname, char *uqname, char *domain);
|
||||
|
||||
#ifdef __linux__
|
||||
+static int Linux_Os_Release(EvalContext *ctx);
|
||||
static int Linux_Fedora_Version(EvalContext *ctx);
|
||||
static int Linux_Redhat_Version(EvalContext *ctx);
|
||||
static void Linux_Oracle_VM_Server_Version(EvalContext *ctx);
|
||||
@@ -931,6 +932,11 @@ static void OSClasses(EvalContext *ctx)
|
||||
/* Mandrake/Mandriva, Fedora and Oracle VM Server supply /etc/redhat-release, so
|
||||
we test for those distributions first */
|
||||
|
||||
+ if (stat("/etc/os-release", &statbuf) != -1)
|
||||
+ {
|
||||
+ Linux_Os_Release(ctx);
|
||||
+ }
|
||||
+
|
||||
if (stat("/etc/mandriva-release", &statbuf) != -1)
|
||||
{
|
||||
Linux_Mandriva_Version(ctx);
|
||||
@@ -1213,6 +1219,146 @@ static void OSClasses(EvalContext *ctx)
|
||||
/*********************************************************************************/
|
||||
|
||||
#ifdef __linux__
|
||||
+
|
||||
+static int Linux_Os_Release(EvalContext *ctx)
|
||||
+{
|
||||
+#define OS_REL_FILENAME "/etc/os-release"
|
||||
+
|
||||
+ char classbuf[CF_MAXVARSIZE];
|
||||
+
|
||||
+ Log(LOG_LEVEL_VERBOSE, "This appears to have an os-release.");
|
||||
+
|
||||
+ FILE *fp = fopen(OS_REL_FILENAME, "r");
|
||||
+ if (fp == NULL)
|
||||
+ {
|
||||
+ return 1;
|
||||
+ }
|
||||
+
|
||||
+ char vbuf[CF_BUFSIZE], strid[CF_MAXVARSIZE], strversion[CF_MAXVARSIZE];
|
||||
+
|
||||
+ int major = -1, minor = -1;
|
||||
+ char *strmajor = NULL, *strminor = NULL;
|
||||
+ while (fgets(vbuf, sizeof(vbuf), fp) != NULL)
|
||||
+ {
|
||||
+ char *nptr, *vptr; /* name, value ptrs */
|
||||
+
|
||||
+ nptr = strrchr(vbuf, '=');
|
||||
+ if (nptr == NULL)
|
||||
+ {
|
||||
+ continue;
|
||||
+ }
|
||||
+ vptr = nptr;
|
||||
+ /* search left of '=' for non-blank char */
|
||||
+ while (isspace(*(nptr-1)))
|
||||
+ {
|
||||
+ nptr--;
|
||||
+ }
|
||||
+ *nptr = '\0';
|
||||
+ /* search right of '=' for non-blank char */
|
||||
+ do
|
||||
+ {
|
||||
+ vptr++;
|
||||
+ }
|
||||
+ while (isspace(*vptr));
|
||||
+ /* value could be enclosed in " */
|
||||
+ if (*vptr == '"')
|
||||
+ {
|
||||
+ char *eos;
|
||||
+ eos = ++vptr;
|
||||
+ /* find closing " and remove it */
|
||||
+ while (*eos && *eos != '"')
|
||||
+ {
|
||||
+ eos++;
|
||||
+ }
|
||||
+ *eos = '\0';
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ char *eos = vptr + strlen(vptr);
|
||||
+ while (eos > vptr && isspace(*(eos-1)))
|
||||
+ {
|
||||
+ eos--;
|
||||
+ }
|
||||
+ *eos = '\0';
|
||||
+ }
|
||||
+ Log(LOG_LEVEL_VERBOSE, "Discovered nptr >%s<, vptr >%s<", vbuf, vptr);
|
||||
+ if (strcmp(vbuf, "ID") == 0)
|
||||
+ {
|
||||
+ strlcpy(strid, vptr, sizeof(strid));
|
||||
+ Log(LOG_LEVEL_VERBOSE, "Discovered ID '%s'", strid);
|
||||
+ }
|
||||
+
|
||||
+ if (strcmp(vbuf, "VERSION_ID") == 0)
|
||||
+ {
|
||||
+ strlcpy(strversion, vptr, sizeof(strversion));
|
||||
+ switch (sscanf(strversion, "%d.%d", &major, &minor))
|
||||
+ {
|
||||
+ case 1:
|
||||
+ strmajor = strversion;
|
||||
+ minor = -1;
|
||||
+ strminor = NULL;
|
||||
+ break;
|
||||
+ case 2:
|
||||
+ strmajor = strversion;
|
||||
+ strminor = strchr(strversion, '.');
|
||||
+ *strminor++ = '\0';
|
||||
+ break;
|
||||
+ default:
|
||||
+ UnexpectedError("Non-numeric VERSION_ID in /etc/os-release");
|
||||
+ strmajor = strminor = NULL;
|
||||
+ break;
|
||||
+ }
|
||||
+ Log(LOG_LEVEL_VERBOSE, "Discovered VERSION_ID '%s', strmajor '%s', strminor '%s'", strversion, strmajor, strminor);
|
||||
+ }
|
||||
+ }
|
||||
+ if (ferror(fp))
|
||||
+ {
|
||||
+ UnexpectedError("Failed to read line from stream");
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ assert(feof(fp));
|
||||
+ }
|
||||
+
|
||||
+ fclose(fp);
|
||||
+
|
||||
+ EvalContextClassPutHard(ctx, strid, "inventory,attribute_name=none,source=agent");
|
||||
+ int i;
|
||||
+ char *cptr;
|
||||
+ for (i = 0; i < strlen(strid); i++)
|
||||
+ {
|
||||
+ classbuf[i] = toupper(strid[i]);
|
||||
+ }
|
||||
+ if (strcmp(classbuf, "OPENSUSE") == 0)
|
||||
+ {
|
||||
+ strcpy(classbuf, "openSUSE");
|
||||
+ }
|
||||
+ cptr = classbuf + i;
|
||||
+
|
||||
+ Log(LOG_LEVEL_VERBOSE, "Discovered %s version %s.%s", classbuf, strmajor, strminor?strminor:"");
|
||||
+ EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
|
||||
+ if (strmajor != NULL)
|
||||
+ {
|
||||
+ *cptr++ = '_';
|
||||
+ strcpy(cptr, strmajor);
|
||||
+ cptr += strlen(strmajor);
|
||||
+ Log(LOG_LEVEL_VERBOSE, "Classbuf >%s<", classbuf);
|
||||
+ SetFlavour(ctx, classbuf);
|
||||
+ if (strminor != NULL)
|
||||
+ {
|
||||
+ *cptr++ = '_';
|
||||
+ strcpy(cptr, strminor);
|
||||
+ Log(LOG_LEVEL_VERBOSE, "Classbuf >%s<", classbuf);
|
||||
+ EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
|
||||
+ }
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ Log(LOG_LEVEL_VERBOSE, "Could not find a numeric OS release in %s", OS_REL_FILENAME);
|
||||
+ }
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
static void Linux_Oracle_VM_Server_Version(EvalContext *ctx)
|
||||
{
|
||||
char relstring[CF_MAXVARSIZE];
|
||||
--
|
||||
1.8.4.5
|
||||
|
@ -1,96 +0,0 @@
|
||||
From 66cfed74c4a14d89c9c7078c7ce1c16d26af5d1e Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= <kkaempf@suse.de>
|
||||
Date: Fri, 4 Apr 2014 22:03:29 +0200
|
||||
Subject: [PATCH] Evaluate /proc/1/cmdline and check for systemd
|
||||
|
||||
Set 'systemd' class eventually.
|
||||
---
|
||||
libenv/sysinfo.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
|
||||
1 file changed, 50 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/libenv/sysinfo.c b/libenv/sysinfo.c
|
||||
index 901791220855..64ca0aa5a880 100644
|
||||
--- a/libenv/sysinfo.c
|
||||
+++ b/libenv/sysinfo.c
|
||||
@@ -114,6 +114,7 @@ static time_t GetBootTimeFromUptimeCommand(time_t); // Last resort
|
||||
void CalculateDomainName(const char *nodename, const char *dnsname, char *fqname, char *uqname, char *domain);
|
||||
|
||||
#ifdef __linux__
|
||||
+static void Linux_Systemd(EvalContext *ctx);
|
||||
static int Linux_Os_Release(EvalContext *ctx);
|
||||
static int Linux_Fedora_Version(EvalContext *ctx);
|
||||
static int Linux_Redhat_Version(EvalContext *ctx);
|
||||
@@ -929,14 +930,17 @@ static void OSClasses(EvalContext *ctx)
|
||||
#ifdef __linux__
|
||||
struct stat statbuf;
|
||||
|
||||
-/* Mandrake/Mandriva, Fedora and Oracle VM Server supply /etc/redhat-release, so
|
||||
- we test for those distributions first */
|
||||
+ /* check for systemd init process */
|
||||
+ Linux_Systemd(ctx);
|
||||
|
||||
if (stat("/etc/os-release", &statbuf) != -1)
|
||||
{
|
||||
Linux_Os_Release(ctx);
|
||||
}
|
||||
|
||||
+/* Mandrake/Mandriva, Fedora and Oracle VM Server supply /etc/redhat-release, so
|
||||
+ we test for those distributions first */
|
||||
+
|
||||
if (stat("/etc/mandriva-release", &statbuf) != -1)
|
||||
{
|
||||
Linux_Mandriva_Version(ctx);
|
||||
@@ -1220,6 +1224,50 @@ static void OSClasses(EvalContext *ctx)
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
+static void Linux_Systemd(EvalContext *ctx)
|
||||
+{
|
||||
+ char proc1[CF_MAXVARSIZE];
|
||||
+ struct stat statbuf;
|
||||
+ char *slash;
|
||||
+
|
||||
+ if (!ReadLine("/proc/1/cmdline", proc1, sizeof(proc1)))
|
||||
+ {
|
||||
+ UnexpectedError("Failed to read /proc/1/cmdline");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ if (lstat(proc1, &statbuf) != 0)
|
||||
+ {
|
||||
+ UnexpectedError("Failed to stat %s", proc1);
|
||||
+ return;
|
||||
+ }
|
||||
+ if (S_ISLNK(statbuf.st_mode))
|
||||
+ {
|
||||
+ int len;
|
||||
+ len = readlink(proc1, proc1, sizeof(proc1));
|
||||
+ if (len <= 0)
|
||||
+ {
|
||||
+ UnexpectedError("Failed to readlink %s", proc1);
|
||||
+ return;
|
||||
+ }
|
||||
+ *(proc1 + len) = '\0';
|
||||
+ }
|
||||
+ Log(LOG_LEVEL_VERBOSE, "Init process: %s", proc1);
|
||||
+ slash = strrchr(proc1, '/');
|
||||
+ if (slash == NULL)
|
||||
+ {
|
||||
+ slash = proc1;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ slash++;
|
||||
+ }
|
||||
+ if (strcmp(slash, "systemd") == 0)
|
||||
+ {
|
||||
+ EvalContextClassPutHard(ctx, slash, "inventory,attribute_name=none,source=agent");
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
static int Linux_Os_Release(EvalContext *ctx)
|
||||
{
|
||||
#define OS_REL_FILENAME "/etc/os-release"
|
||||
--
|
||||
1.8.4.5
|
||||
|
84
0002-Do-not-segfault-on-type-checking-NULL-Rvals.patch
Normal file
84
0002-Do-not-segfault-on-type-checking-NULL-Rvals.patch
Normal file
@ -0,0 +1,84 @@
|
||||
From cc963ee8af0408d902c7956414c4d1c54a902805 Mon Sep 17 00:00:00 2001
|
||||
From: Sigurd Teigen <sigurd.teigen@cfengine.com>
|
||||
Date: Tue, 8 Apr 2014 12:53:04 -0400
|
||||
Subject: [PATCH 2/7] Do not segfault on type checking NULL Rvals.
|
||||
|
||||
Add unit test. Close #5416
|
||||
---
|
||||
diff -wruN -x '*~' -x '*.o' -x '*.a' -x '*.so' -x '*.so.[0-9]' -x autom4te.cache -x .deps -x .libs ../orig-core-3.6.0b2/libpromises/syntax.c ./libpromises/syntax.c
|
||||
--- ../orig-core-3.6.0b2/libpromises/syntax.c 2014-03-17 17:37:49.000000000 +0100
|
||||
+++ ./libpromises/syntax.c 2014-04-10 16:12:06.104406735 +0200
|
||||
@@ -253,10 +253,11 @@
|
||||
[SYNTAX_TYPE_MATCH_OK] = "OK",
|
||||
|
||||
[SYNTAX_TYPE_MATCH_ERROR_UNEXPANDED] = "Cannot check unexpanded value",
|
||||
- [SYNTAX_TYPE_MATCH_ERROR_RANGE_BRACKETED] = "Real range specification should not be enclosed in brackets - just \"a,b\"",
|
||||
- [SYNTAX_TYPE_MATCH_ERROR_RANGE_MULTIPLE_ITEMS] = "Range format specifier should be of form \"a,b\" but got multiple items",
|
||||
+ [SYNTAX_TYPE_MATCH_ERROR_RANGE_BRACKETED] = "Real range specification should not be enclosed in brackets - just 'a,b'",
|
||||
+ [SYNTAX_TYPE_MATCH_ERROR_RANGE_MULTIPLE_ITEMS] = "Range format specifier should be of form 'a,b'' but got multiple items",
|
||||
[SYNTAX_TYPE_MATCH_ERROR_GOT_SCALAR] = "Attempted to give a scalar to a non-scalar type",
|
||||
[SYNTAX_TYPE_MATCH_ERROR_GOT_LIST] = "Attempted to give a list to a non-list type",
|
||||
+ [SYNTAX_TYPE_MATCH_ERROR_GOT_NULL] = "Attempted to give a value of type null",
|
||||
|
||||
[SYNTAX_TYPE_MATCH_ERROR_STRING_UNIX_PERMISSION] = "Error parsing Unix permission string",
|
||||
|
||||
@@ -266,7 +267,7 @@
|
||||
[SYNTAX_TYPE_MATCH_ERROR_INT_PARSE] = "Cannot parse value as integer",
|
||||
[SYNTAX_TYPE_MATCH_ERROR_INT_OUT_OF_RANGE] = "Integer is out of range",
|
||||
|
||||
- [SYNTAX_TYPE_MATCH_ERROR_REAL_INF] = "Keyword \"inf\" has an integer value, cannot be used as real",
|
||||
+ [SYNTAX_TYPE_MATCH_ERROR_REAL_INF] = "Keyword 'inf' has an integer value, cannot be used as real",
|
||||
[SYNTAX_TYPE_MATCH_ERROR_REAL_OUT_OF_RANGE] = "Real value is out of range",
|
||||
|
||||
[SYNTAX_TYPE_MATCH_ERROR_OPTS_OUT_OF_RANGE] = "Selection is out of bounds",
|
||||
@@ -355,8 +356,10 @@
|
||||
return SYNTAX_TYPE_MATCH_OK;
|
||||
|
||||
case RVAL_TYPE_CONTAINER:
|
||||
- case RVAL_TYPE_NOPROMISEE:
|
||||
break;
|
||||
+
|
||||
+ case RVAL_TYPE_NOPROMISEE:
|
||||
+ return SYNTAX_TYPE_MATCH_ERROR_GOT_NULL;
|
||||
}
|
||||
|
||||
/* If we get here, we have a literal scalar type */
|
||||
diff -wruN -x '*~' -x '*.o' -x '*.a' -x '*.so' -x '*.so.[0-9]' -x autom4te.cache -x .deps -x .libs ../orig-core-3.6.0b2/libpromises/syntax.h ./libpromises/syntax.h
|
||||
--- ../orig-core-3.6.0b2/libpromises/syntax.h 2014-03-17 17:37:49.000000000 +0100
|
||||
+++ ./libpromises/syntax.h 2014-04-10 16:12:06.104406735 +0200
|
||||
@@ -46,6 +46,7 @@
|
||||
SYNTAX_TYPE_MATCH_ERROR_RANGE_MULTIPLE_ITEMS,
|
||||
SYNTAX_TYPE_MATCH_ERROR_GOT_SCALAR,
|
||||
SYNTAX_TYPE_MATCH_ERROR_GOT_LIST,
|
||||
+ SYNTAX_TYPE_MATCH_ERROR_GOT_NULL,
|
||||
|
||||
SYNTAX_TYPE_MATCH_ERROR_SCALAR_OUT_OF_RANGE,
|
||||
SYNTAX_TYPE_MATCH_ERROR_EMPTY_SCALAR_OUT_OF_RANGE,
|
||||
diff -wruN -x '*~' -x '*.o' -x '*.a' -x '*.so' -x '*.so.[0-9]' -x autom4te.cache -x .deps -x .libs ../orig-core-3.6.0b2/tests/unit/syntax_test.c ./tests/unit/syntax_test.c
|
||||
--- ../orig-core-3.6.0b2/tests/unit/syntax_test.c 2014-03-17 17:37:49.000000000 +0100
|
||||
+++ ./tests/unit/syntax_test.c 2014-04-10 16:13:24.055666621 +0200
|
||||
@@ -88,6 +88,13 @@
|
||||
assert_string_equal("delete_if_startwith_from_list", y->lval);
|
||||
}
|
||||
|
||||
+static void test_typecheck_null_rval(void)
|
||||
+{
|
||||
+ SyntaxTypeMatch err = CheckConstraintTypeMatch("whatever", (Rval) { NULL, RVAL_TYPE_NOPROMISEE },
|
||||
+ CF_DATA_TYPE_STRING, "abc", 0);
|
||||
+ assert_int_equal(SYNTAX_TYPE_MATCH_ERROR_GOT_NULL, err);
|
||||
+}
|
||||
+
|
||||
int main()
|
||||
{
|
||||
PRINT_TEST_BANNER();
|
||||
@@ -105,7 +112,9 @@
|
||||
unit_test(test_lookup_body_process_count),
|
||||
unit_test(test_lookup_body_delete_select),
|
||||
|
||||
- unit_test(test_lookup_constraint_edit_xml_set_attribute_attribute_value)
|
||||
+ unit_test(test_lookup_constraint_edit_xml_set_attribute_attribute_value),
|
||||
+
|
||||
+ unit_test(test_typecheck_null_rval)
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
304
0007-Simplify-and-fix-parsing-of-etc-SuSE-release-fixes-i.patch
Normal file
304
0007-Simplify-and-fix-parsing-of-etc-SuSE-release-fixes-i.patch
Normal file
@ -0,0 +1,304 @@
|
||||
From 882bf55c88e3fb6c38e2952fad272607a0900198 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= <kkaempf@suse.de>
|
||||
Date: Wed, 9 Apr 2014 17:00:23 +0200
|
||||
Subject: [PATCH 7/7] Simplify and fix parsing of /etc/SuSE-release (fixes
|
||||
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
|
||||
---
|
||||
diff -wruN -x '*~' -x '*.o' -x '*.a' -x '*.so' -x '*.so.[0-9]' -x autom4te.cache -x .deps -x .libs ../orig-core-3.6.0b2/libenv/sysinfo.c ./libenv/sysinfo.c
|
||||
--- ../orig-core-3.6.0b2/libenv/sysinfo.c 2014-03-17 17:37:49.000000000 +0100
|
||||
+++ ./libenv/sysinfo.c 2014-04-10 16:26:49.389330253 +0200
|
||||
@@ -1639,221 +1639,143 @@
|
||||
#define SUSE_SLED_ID "suse linux enterprise desktop"
|
||||
#define SUSE_RELEASE_FLAG "linux "
|
||||
|
||||
-/* The full string read in from SuSE-release */
|
||||
- char relstring[CF_MAXVARSIZE];
|
||||
char classbuf[CF_MAXVARSIZE];
|
||||
- char vbuf[CF_BUFSIZE], strversion[CF_MAXVARSIZE], strpatch[CF_MAXVARSIZE];
|
||||
-
|
||||
-/* Where the numerical release will be found */
|
||||
- char *release = NULL;
|
||||
- int i, version;
|
||||
- int major = -1;
|
||||
- char strmajor[CF_MAXVARSIZE];
|
||||
- int minor = -1;
|
||||
- char strminor[CF_MAXVARSIZE];
|
||||
- FILE *fp;
|
||||
+ char *vendor = "suse";
|
||||
|
||||
Log(LOG_LEVEL_VERBOSE, "This appears to be a SUSE system.");
|
||||
EvalContextClassPutHard(ctx, "SUSE", "inventory,attribute_name=none,source=agent");
|
||||
+ EvalContextClassPutHard(ctx, "suse", "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
|
||||
*/
|
||||
EvalContextClassPutHard(ctx, "SuSE", "inventory,attribute_name=none,source=agent");
|
||||
|
||||
-/* Grab the first line from the file and then close it. */
|
||||
+ /* Grab the first line from the SuSE-release file and then close it. */
|
||||
+ char relstring[CF_MAXVARSIZE];
|
||||
|
||||
- fp = ReadFirstLine(SUSE_REL_FILENAME, relstring, sizeof(relstring));
|
||||
+ FILE *fp = ReadFirstLine(SUSE_REL_FILENAME, relstring, sizeof(relstring));
|
||||
if (fp == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
- strversion[0] = '\0';
|
||||
- strpatch[0] = '\0';
|
||||
+ char vbuf[CF_BUFSIZE];
|
||||
|
||||
- for(;;)
|
||||
+ int major = -1, minor = -1;
|
||||
+ while (fgets(vbuf, sizeof(vbuf), fp) != NULL)
|
||||
{
|
||||
- if (fgets(vbuf, sizeof(vbuf), fp) == NULL)
|
||||
- {
|
||||
- if (ferror(fp))
|
||||
+ if (strncmp(vbuf, "VERSION", strlen("version")) == 0)
|
||||
{
|
||||
- UnexpectedError("Failed to read line from stream");
|
||||
- break;
|
||||
+ 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;
|
||||
}
|
||||
- else /* feof */
|
||||
+
|
||||
+ if (strncmp(vbuf, "PATCH", strlen("PATCH")) == 0)
|
||||
{
|
||||
- break;
|
||||
+ if (sscanf(vbuf, "PATCHLEVEL = %d", &minor) != 1)
|
||||
+ minor = -1;
|
||||
}
|
||||
}
|
||||
-
|
||||
- if (strncmp(vbuf, "VERSION", strlen("version")) == 0)
|
||||
+ if (ferror(fp))
|
||||
{
|
||||
- strncpy(strversion, vbuf, sizeof(strversion));
|
||||
- sscanf(strversion, "VERSION = %d", &major);
|
||||
+ UnexpectedError("Failed to read line from stream");
|
||||
}
|
||||
-
|
||||
- if (strncmp(vbuf, "PATCH", strlen("PATCH")) == 0)
|
||||
+ else
|
||||
{
|
||||
- strncpy(strpatch, vbuf, sizeof(strpatch));
|
||||
- sscanf(strpatch, "PATCHLEVEL = %d", &minor);
|
||||
- }
|
||||
+ assert(feof(fp));
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
- /* Check if it's a SUSE Enterprise version */
|
||||
-
|
||||
- Log(LOG_LEVEL_VERBOSE, "Looking for SUSE enterprise info in '%s'", relstring);
|
||||
-
|
||||
- /* Convert relstring to lowercase to handle rename of SuSE to
|
||||
- * SUSE with SUSE 10.0.
|
||||
- */
|
||||
-
|
||||
- for (i = 0; i < strlen(relstring); i++)
|
||||
- {
|
||||
- relstring[i] = tolower(relstring[i]);
|
||||
- }
|
||||
+ /* Check which SUSE/openSUSE product it is */
|
||||
|
||||
- /* Check if it's a SUSE Enterprise version (all in lowercase) */
|
||||
+ Log(LOG_LEVEL_VERBOSE, "Looking for SUSE product info in '%s'", relstring);
|
||||
|
||||
- if (!strncmp(relstring, SUSE_SLES8_ID, strlen(SUSE_SLES8_ID)))
|
||||
+ if (!strncasecmp(relstring, SUSE_SLES8_ID, strlen(SUSE_SLES8_ID)))
|
||||
{
|
||||
classbuf[0] = '\0';
|
||||
strcat(classbuf, "SLES8");
|
||||
EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
|
||||
}
|
||||
- else if (strncmp(relstring, "sles", 4) == 0)
|
||||
- {
|
||||
- Item *list, *ip;
|
||||
-
|
||||
- sscanf(relstring, "%[-_a-zA-Z0-9]", vbuf);
|
||||
- EvalContextClassPutHard(ctx, vbuf, "inventory,attribute_name=none,source=agent");
|
||||
-
|
||||
- list = SplitString(vbuf, '-');
|
||||
-
|
||||
- for (ip = list; ip != NULL; ip = ip->next)
|
||||
- {
|
||||
- EvalContextClassPutHard(ctx, ip->name, "inventory,attribute_name=none,source=agent");
|
||||
- }
|
||||
-
|
||||
- DeleteItemList(list);
|
||||
- }
|
||||
- else
|
||||
+ else if (!strncasecmp(relstring, SUSE_SLES_ID, strlen(SUSE_SLES_ID)))
|
||||
{
|
||||
- for (version = 9; version < 13; version++)
|
||||
+ EvalContextClassPutHard(ctx, "sles", "inventory,attribute_name=none,source=agent");
|
||||
+ if (major != -1)
|
||||
{
|
||||
- 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);
|
||||
+ snprintf(classbuf, CF_MAXVARSIZE, "SLES%d", major);
|
||||
EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
|
||||
}
|
||||
- else
|
||||
+ }
|
||||
+ else if (!strncasecmp(relstring, SUSE_SLED_ID, strlen(SUSE_SLED_ID)))
|
||||
{
|
||||
- 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)))
|
||||
+ EvalContextClassPutHard(ctx, "sled", "inventory,attribute_name=none,source=agent");
|
||||
+ if (major != -1)
|
||||
{
|
||||
- snprintf(classbuf, CF_MAXVARSIZE, "SLED%d", version);
|
||||
+ 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");
|
||||
}
|
||||
- }
|
||||
-
|
||||
- /* Determine release version. We assume that the version follows
|
||||
- * the string "SuSE Linux" or "SUSE LINUX".
|
||||
- */
|
||||
+ else if (strncasecmp(relstring, "sles", 4) == 0)
|
||||
+ {
|
||||
+ Item *list, *ip;
|
||||
|
||||
- release = strstr(relstring, SUSE_RELEASE_FLAG);
|
||||
+ sscanf(relstring, "%[-_a-zA-Z0-9]", vbuf);
|
||||
+ EvalContextClassPutHard(ctx, vbuf, "inventory,attribute_name=none,source=agent");
|
||||
|
||||
- if (release == NULL)
|
||||
- {
|
||||
- release = strstr(relstring, "opensuse");
|
||||
- }
|
||||
+ list = SplitString(vbuf, '-');
|
||||
|
||||
- if (release == NULL)
|
||||
+ for (ip = list; ip != NULL; ip = ip->next)
|
||||
{
|
||||
- release = strversion;
|
||||
+ EvalContextClassPutHard(ctx, ip->name, "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;
|
||||
+ DeleteItemList(list);
|
||||
}
|
||||
else
|
||||
{
|
||||
- if (strchr(release, '.'))
|
||||
- {
|
||||
- sscanf(release, "%*s %d.%d", &major, &minor);
|
||||
- sprintf(strmajor, "%d", major);
|
||||
- sprintf(strminor, "%d", minor);
|
||||
+ Log(LOG_LEVEL_WARNING, "Unknown product '%s' in /etc/SuSE-release", relstring);
|
||||
+ }
|
||||
|
||||
- if (major != -1 && minor != -1)
|
||||
+ if (major != -1)
|
||||
{
|
||||
- strcpy(classbuf, "SUSE");
|
||||
+ strcpy(classbuf, vendor);
|
||||
EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
|
||||
- strcat(classbuf, "_");
|
||||
- strcat(classbuf, strmajor);
|
||||
+ sprintf(classbuf + strlen(classbuf), "_%d", major);
|
||||
SetFlavour(ctx, classbuf);
|
||||
- strcat(classbuf, "_");
|
||||
- strcat(classbuf, strminor);
|
||||
+ if (minor != -1)
|
||||
+ {
|
||||
+ sprintf(classbuf + strlen(classbuf), "_%d", minor);
|
||||
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);
|
||||
+ sprintf(classbuf + strlen(classbuf), "_%d", major);
|
||||
EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
|
||||
- strcat(classbuf, "_");
|
||||
- strcat(classbuf, strminor);
|
||||
+ if (minor != -1)
|
||||
+ {
|
||||
+ sprintf(classbuf + strlen(classbuf), "_%d", minor);
|
||||
EvalContextClassPutHard(ctx, classbuf, "inventory,attribute_name=none,source=agent");
|
||||
-
|
||||
- Log(LOG_LEVEL_VERBOSE, "Discovered SUSE version %s", classbuf);
|
||||
- return 0;
|
||||
}
|
||||
+ Log(LOG_LEVEL_VERBOSE, "Discovered %s version %d.%d", vendor, major, minor);
|
||||
}
|
||||
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);
|
||||
- SetFlavour(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);
|
||||
-
|
||||
+ }
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,16 +1,25 @@
|
||||
-------------------------------------------------------------------
|
||||
Thu Apr 10 14:02:11 UTC 2014 - kkaempf@suse.com
|
||||
|
||||
- add 0002-Do-not-segfault-on-type-checking-NULL-Rvals.patch
|
||||
to prevent crash on syntax error
|
||||
|
||||
- add 0007-Simplify-and-fix-parsing-of-etc-SuSE-release-fixes-i.patch
|
||||
* add 'suse' class for consistency with other vendor classes
|
||||
(fixes #5417)
|
||||
* 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
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Fri Apr 4 19:36:47 UTC 2014 - kkaempf@suse.com
|
||||
|
||||
- move cf-serverd to cfengine, required for bootstrap
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Fri Apr 4 19:30:04 UTC 2014 - kkaempf@suse.com
|
||||
|
||||
- Parse /etc/os-release for product and version
|
||||
Add patch 0001-Check-etc-os-release-for-distribution-information.patch
|
||||
|
||||
- Parse /proc/1/cmdline to detect systemd
|
||||
0001-Evaluate-proc-1-cmdline-and-check-for-systemd.patch
|
||||
- merge cfengine-server with cfengine. A policy server only
|
||||
gets cfengine-masterfiles but is otherwise identical to
|
||||
a client.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Thu Apr 3 13:10:56 UTC 2014 - kkaempf@suse.com
|
||||
|
@ -75,11 +75,11 @@ Patch2: remove-am_subst_notmake.patch
|
||||
# kkaempf@suse.de
|
||||
Patch3: drop-revision.patch
|
||||
|
||||
# parse /etc/os-release for product and version information, kkaempf@suse.de
|
||||
Patch4: 0001-Check-etc-os-release-for-distribution-information.patch
|
||||
|
||||
# parse /proc/1/cmdline to detect systemd
|
||||
Patch5: 0001-Evaluate-proc-1-cmdline-and-check-for-systemd.patch
|
||||
# PATCH-FIX-UPSTREAM fix crash on syntax error
|
||||
Patch4: 0002-Do-not-segfault-on-type-checking-NULL-Rvals.patch
|
||||
# PATCH-FIX-UPSTREAM add 'suse' class for consistency with other vendor classes
|
||||
# PATCH-FEATURE-UPSTREAM better /etc/SuSE-release parsing, upstream #5423
|
||||
Patch5: 0007-Simplify-and-fix-parsing-of-etc-SuSE-release-fixes-i.patch
|
||||
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
||||
BuildRequires: bison
|
||||
@ -183,16 +183,6 @@ Group: Documentation/Other
|
||||
%description examples
|
||||
Lots of examples promises for CFEngine.
|
||||
|
||||
%package server
|
||||
Summary: CFEngine policy server master package
|
||||
Group: Productivity/Networking/System
|
||||
Requires: %{name} = %{version}-%{release}
|
||||
Requires: %{name}-masterfiles = %{version}
|
||||
|
||||
%description server
|
||||
This package contains the files and requirements of the cfengine policy server.
|
||||
|
||||
|
||||
%prep
|
||||
%setup -q -n %{srcname}-%{version}
|
||||
%if 0%{?suse_version} || 0%{?fedora_version} || 0%{?rhel_version}
|
||||
@ -228,7 +218,7 @@ CC=gcc CFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing" \
|
||||
--datadir=/var \
|
||||
--with-workdir=%{workdir} \
|
||||
--with-postgresql \
|
||||
%if 0%{?suse_version} != 1110 && 0%{?rhel_version} == 0
|
||||
%if 0%{?suse_version} != 1110 && 0%{?rhel_version} == 0 && 0%{?fedora_version} != 20
|
||||
--with-mysql \
|
||||
%endif
|
||||
--without-qdbm \
|
||||
@ -414,6 +404,7 @@ fi
|
||||
%{_sbindir}/cf-promises
|
||||
%{_sbindir}/cf-serverd
|
||||
%{_sbindir}/cf-upgrade
|
||||
%{_sbindir}/cf-runagent
|
||||
%{_sbindir}/rpmvercmp
|
||||
%if 0%{?suse_version} >= 1210
|
||||
%_unitdir/cf-execd.service
|
||||
@ -425,21 +416,15 @@ fi
|
||||
%{_sbindir}/rccf-monitord
|
||||
%{_sbindir}/rccf-serverd
|
||||
%endif
|
||||
%{_mandir}/man8/cf-serverd.8.*
|
||||
%if 0%{?suse_version} > 1010
|
||||
%config %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/cfengine
|
||||
%endif
|
||||
|
||||
%{_mandir}/man8/*
|
||||
%exclude %{_mandir}/man8/cf-runagent.8.*
|
||||
%dir %{basedir}
|
||||
%exclude %{basedir}/backup
|
||||
%exclude %{basedir}/config
|
||||
#%%exclude %%{basedir}/failsafe
|
||||
|
||||
%dir %{workdir}
|
||||
%{workdir}/*
|
||||
%exclude %{workdir}/bin/cf-runagent
|
||||
|
||||
%config(noreplace) /etc/cron.d/%{name}
|
||||
|
||||
@ -460,12 +445,4 @@ fi
|
||||
%defattr(-,root,root)
|
||||
%doc examples/*cf
|
||||
|
||||
%files server
|
||||
%defattr(-,root,root)
|
||||
%{basedir}/backup
|
||||
%{basedir}/config
|
||||
%{_sbindir}/cf-runagent
|
||||
%{workdir}/bin/cf-runagent
|
||||
%{_mandir}/man8/cf-runagent.8.*
|
||||
|
||||
%changelog
|
||||
|
Loading…
Reference in New Issue
Block a user