commit:     df2c32b5b39e04b224ac686bdd9845bb893d5ede
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Wed Jul 12 20:19:48 2017 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Wed Jul 12 20:21:13 2017 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=df2c32b5

sys-apps/systemd: backport fix for CVE-2017-1000082

Bug: https://bugs.gentoo.org/623532
Package-Manager: Portage-2.3.6_p16, Repoman-2.3.2_p84

 ...ragment-refuse-units-with-errors-in-RootD.patch | 117 ++++++
 ...ragment-refuse-units-with-errors-in-certa.patch | 339 +++++++++++++++
 sys-apps/systemd/systemd-233-r4.ebuild             | 463 +++++++++++++++++++++
 3 files changed, 919 insertions(+)

diff --git 
a/sys-apps/systemd/files/233-0002-core-load-fragment-refuse-units-with-errors-in-RootD.patch
 
b/sys-apps/systemd/files/233-0002-core-load-fragment-refuse-units-with-errors-in-RootD.patch
new file mode 100644
index 00000000000..fe30ef9ff61
--- /dev/null
+++ 
b/sys-apps/systemd/files/233-0002-core-load-fragment-refuse-units-with-errors-in-RootD.patch
@@ -0,0 +1,117 @@
+From 433e7893c6c0f6cbc98d8911fc5149ee9beedb79 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbys...@in.waw.pl>
+Date: Thu, 6 Jul 2017 13:54:42 -0400
+Subject: [PATCH 2/3] core/load-fragment: refuse units with errors in
+ RootDirectory/RootImage/DynamicUser
+
+Behaviour of the service is completely different with the option off, so the
+service would probably mess up state on disk and do unexpected things.
+---
+ src/core/load-fragment-gperf.gperf.m4 |  6 +++---
+ src/core/load-fragment.c              |  7 +++++--
+ src/shared/conf-parser.c              | 16 +++++++++++-----
+ 3 files changed, 19 insertions(+), 10 deletions(-)
+
+diff --git a/src/core/load-fragment-gperf.gperf.m4 
b/src/core/load-fragment-gperf.gperf.m4
+index cb9e6fea2..d0868bf40 100644
+--- a/src/core/load-fragment-gperf.gperf.m4
++++ b/src/core/load-fragment-gperf.gperf.m4
+@@ -18,8 +18,8 @@ struct ConfigPerfItem;
+ m4_dnl Define the context options only once
+ m4_define(`EXEC_CONTEXT_CONFIG_ITEMS',
+ `$1.WorkingDirectory,            config_parse_working_directory,     0,       
                      offsetof($1, exec_context)
+-$1.RootDirectory,                config_parse_unit_path_printf,      0,       
                      offsetof($1, exec_context.root_directory)
+-$1.RootImage,                    config_parse_unit_path_printf,      0,       
                      offsetof($1, exec_context.root_image)
++$1.RootDirectory,                config_parse_unit_path_printf,      true,    
                      offsetof($1, exec_context.root_directory)
++$1.RootImage,                    config_parse_unit_path_printf,      true,    
                      offsetof($1, exec_context.root_image)
+ $1.User,                         config_parse_user_group,            0,       
                      offsetof($1, exec_context.user)
+ $1.Group,                        config_parse_user_group,            0,       
                      offsetof($1, exec_context.group)
+ $1.SupplementaryGroups,          config_parse_user_group_strv,       0,       
                      offsetof($1, exec_context.supplementary_groups)
+@@ -35,7 +35,7 @@ $1.UMask,                        config_parse_mode,          
        0,
+ $1.Environment,                  config_parse_environ,               0,       
                      offsetof($1, exec_context.environment)
+ $1.EnvironmentFile,              config_parse_unit_env_file,         0,       
                      offsetof($1, exec_context.environment_files)
+ $1.PassEnvironment,              config_parse_pass_environ,          0,       
                      offsetof($1, exec_context.pass_environment)
+-$1.DynamicUser,                  config_parse_bool,                  0,       
                      offsetof($1, exec_context.dynamic_user)
++$1.DynamicUser,                  config_parse_bool,                  true,    
                      offsetof($1, exec_context.dynamic_user)
+ $1.StandardInput,                config_parse_exec_input,            0,       
                      offsetof($1, exec_context)
+ $1.StandardOutput,               config_parse_exec_output,           0,       
                      offsetof($1, exec_context)
+ $1.StandardError,                config_parse_exec_output,           0,       
                      offsetof($1, exec_context)
+diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
+index 5b7471c0d..ae4ec5cf0 100644
+--- a/src/core/load-fragment.c
++++ b/src/core/load-fragment.c
+@@ -242,6 +242,7 @@ int config_parse_unit_path_printf(
+         _cleanup_free_ char *k = NULL;
+         Unit *u = userdata;
+         int r;
++        bool fatal = ltype;
+ 
+         assert(filename);
+         assert(lvalue);
+@@ -250,8 +251,10 @@ int config_parse_unit_path_printf(
+ 
+         r = unit_full_printf(u, rvalue, &k);
+         if (r < 0) {
+-                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to 
resolve unit specifiers on %s, ignoring: %m", rvalue);
+-                return 0;
++                log_syntax(unit, LOG_ERR, filename, line, r,
++                           "Failed to resolve unit specifiers on %s%s: %m",
++                           fatal ? "" : ", ignoring", rvalue);
++                return fatal ? -ENOEXEC : 0;
+         }
+ 
+         return config_parse_path(unit, filename, line, section, section_line, 
lvalue, ltype, k, data, userdata);
+diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
+index 265ac83dc..ffb905fb6 100644
+--- a/src/shared/conf-parser.c
++++ b/src/shared/conf-parser.c
+@@ -614,6 +614,7 @@ int config_parse_bool(const char* unit,
+ 
+         int k;
+         bool *b = data;
++        bool fatal = ltype;
+ 
+         assert(filename);
+         assert(lvalue);
+@@ -622,8 +623,10 @@ int config_parse_bool(const char* unit,
+ 
+         k = parse_boolean(rvalue);
+         if (k < 0) {
+-                log_syntax(unit, LOG_ERR, filename, line, k, "Failed to parse 
boolean value, ignoring: %s", rvalue);
+-                return 0;
++                log_syntax(unit, LOG_ERR, filename, line, k,
++                           "Failed to parse boolean value%s: %s",
++                           fatal ? "" : ", ignoring", rvalue);
++                return fatal ? -ENOEXEC : 0;
+         }
+ 
+         *b = !!k;
+@@ -714,6 +717,7 @@ int config_parse_path(
+                 void *userdata) {
+ 
+         char **s = data, *n;
++        bool fatal = ltype;
+ 
+         assert(filename);
+         assert(lvalue);
+@@ -722,12 +726,14 @@ int config_parse_path(
+ 
+         if (!utf8_is_valid(rvalue)) {
+                 log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, 
rvalue);
+-                return 0;
++                return fatal ? -ENOEXEC : 0;
+         }
+ 
+         if (!path_is_absolute(rvalue)) {
+-                log_syntax(unit, LOG_ERR, filename, line, 0, "Not an absolute 
path, ignoring: %s", rvalue);
+-                return 0;
++                log_syntax(unit, LOG_ERR, filename, line, 0,
++                           "Not an absolute path%s: %s",
++                           fatal ? "" : ", ignoring", rvalue);
++                return fatal ? -ENOEXEC : 0;
+         }
+ 
+         n = strdup(rvalue);
+-- 
+2.13.2
+

diff --git 
a/sys-apps/systemd/files/233-0003-core-load-fragment-refuse-units-with-errors-in-certa.patch
 
b/sys-apps/systemd/files/233-0003-core-load-fragment-refuse-units-with-errors-in-certa.patch
new file mode 100644
index 00000000000..28961b4b1e3
--- /dev/null
+++ 
b/sys-apps/systemd/files/233-0003-core-load-fragment-refuse-units-with-errors-in-certa.patch
@@ -0,0 +1,339 @@
+From f135524cd4cd6b71e7f6073b02389da30c6e94d9 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbys...@in.waw.pl>
+Date: Thu, 6 Jul 2017 13:28:19 -0400
+Subject: [PATCH 3/3] core/load-fragment: refuse units with errors in certain
+ directives
+
+If an error is encountered in any of the Exec* lines, WorkingDirectory,
+SELinuxContext, ApparmorProfile, SmackProcessLabel, Service (in .socket
+units), User, or Group, refuse to load the unit. If the config stanza
+has support, ignore the failure if '-' is present.
+
+For those configuration directives, even if we started the unit, it's
+pretty likely that it'll do something unexpected (like write files
+in a wrong place, or with a wrong context, or run with wrong permissions,
+etc). It seems better to refuse to start the unit and have the admin
+clean up the configuration without giving the service a chance to mess
+up stuff.
+
+Note that all "security" options that restrict what the unit can do
+(Capabilities, AmbientCapabilities, Restrict*, SystemCallFilter, Limit*,
+PrivateDevices, Protect*, etc) are _not_ treated like this. Such options are
+only supplementary, and are not always available depending on the architecture
+and compilation options, so unit authors have to make sure that the service
+runs correctly without them anyway.
+
+Fixes #6237, #6277.
+---
+ src/core/load-fragment.c  | 116 ++++++++++++++++++++++++++++------------------
+ src/test/test-unit-file.c |  14 +++---
+ 2 files changed, 78 insertions(+), 52 deletions(-)
+
+diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
+index ae4ec5cf0..f38240af3 100644
+--- a/src/core/load-fragment.c
++++ b/src/core/load-fragment.c
+@@ -637,26 +637,36 @@ int config_parse_exec(
+ 
+                 r = unit_full_printf(u, f, &path);
+                 if (r < 0) {
+-                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed 
to resolve unit specifiers on %s, ignoring: %m", f);
+-                        return 0;
++                        log_syntax(unit, LOG_ERR, filename, line, r,
++                                   "Failed to resolve unit specifiers on 
%s%s: %m",
++                                   f, ignore ? ", ignoring" : "");
++                        return ignore ? 0 : -ENOEXEC;
+                 }
+ 
+                 if (isempty(path)) {
+                         /* First word is either "-" or "@" with no command. */
+-                        log_syntax(unit, LOG_ERR, filename, line, 0, "Empty 
path in command line, ignoring: \"%s\"", rvalue);
+-                        return 0;
++                        log_syntax(unit, LOG_ERR, filename, line, 0,
++                                   "Empty path in command line%s: \"%s\"",
++                                   ignore ? ", ignoring" : "", rvalue);
++                        return ignore ? 0 : -ENOEXEC;
+                 }
+                 if (!string_is_safe(path)) {
+-                        log_syntax(unit, LOG_ERR, filename, line, 0, 
"Executable path contains special characters, ignoring: %s", rvalue);
+-                        return 0;
++                        log_syntax(unit, LOG_ERR, filename, line, 0,
++                                   "Executable path contains special 
characters%s: %s",
++                                   ignore ? ", ignoring" : "", rvalue);
++                        return ignore ? 0 : -ENOEXEC;
+                 }
+                 if (!path_is_absolute(path)) {
+-                        log_syntax(unit, LOG_ERR, filename, line, 0, 
"Executable path is not absolute, ignoring: %s", rvalue);
+-                        return 0;
++                        log_syntax(unit, LOG_ERR, filename, line, 0,
++                                   "Executable path is not absolute%s: %s",
++                                   ignore ? ", ignoring" : "", rvalue);
++                        return ignore ? 0 : -ENOEXEC;
+                 }
+                 if (endswith(path, "/")) {
+-                        log_syntax(unit, LOG_ERR, filename, line, 0, 
"Executable path specifies a directory, ignoring: %s", rvalue);
+-                        return 0;
++                        log_syntax(unit, LOG_ERR, filename, line, 0,
++                                   "Executable path specifies a directory%s: 
%s",
++                                   ignore ? ", ignoring" : "", rvalue);
++                        return ignore ? 0 : -ENOEXEC;
+                 }
+ 
+                 if (!separate_argv0) {
+@@ -709,12 +719,14 @@ int config_parse_exec(
+                         if (r == 0)
+                                 break;
+                         if (r < 0)
+-                                return 0;
++                                return ignore ? 0 : -ENOEXEC;
+ 
+                         r = unit_full_printf(u, word, &resolved);
+                         if (r < 0) {
+-                                log_syntax(unit, LOG_ERR, filename, line, 0, 
"Failed to resolve unit specifiers on %s, ignoring: %m", word);
+-                                return 0;
++                                log_syntax(unit, LOG_ERR, filename, line, r,
++                                           "Failed to resolve unit specifiers 
on %s%s: %m",
++                                           word, ignore ? ", ignoring" : "");
++                                return ignore ? 0 : -ENOEXEC;
+                         }
+ 
+                         if (!GREEDY_REALLOC(n, nbufsize, nlen + 2))
+@@ -725,8 +737,10 @@ int config_parse_exec(
+                 }
+ 
+                 if (!n || !n[0]) {
+-                        log_syntax(unit, LOG_ERR, filename, line, 0, "Empty 
executable name or zeroeth argument, ignoring: %s", rvalue);
+-                        return 0;
++                        log_syntax(unit, LOG_ERR, filename, line, 0,
++                                   "Empty executable name or zeroeth 
argument%s: %s",
++                                   ignore ? ", ignoring" : "", rvalue);
++                        return ignore ? 0 : -ENOEXEC;
+                 }
+ 
+                 nce = new0(ExecCommand, 1);
+@@ -1333,8 +1347,10 @@ int config_parse_exec_selinux_context(
+ 
+         r = unit_full_printf(u, rvalue, &k);
+         if (r < 0) {
+-                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to 
resolve specifiers, ignoring: %m");
+-                return 0;
++                log_syntax(unit, LOG_ERR, filename, line, r,
++                           "Failed to resolve specifiers%s: %m",
++                           ignore ? ", ignoring" : "");
++                return ignore ? 0 : -ENOEXEC;
+         }
+ 
+         free(c->selinux_context);
+@@ -1381,8 +1397,10 @@ int config_parse_exec_apparmor_profile(
+ 
+         r = unit_full_printf(u, rvalue, &k);
+         if (r < 0) {
+-                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to 
resolve specifiers, ignoring: %m");
+-                return 0;
++                log_syntax(unit, LOG_ERR, filename, line, r,
++                           "Failed to resolve specifiers%s: %m",
++                           ignore ? ", ignoring" : "");
++                return ignore ? 0 : -ENOEXEC;
+         }
+ 
+         free(c->apparmor_profile);
+@@ -1429,8 +1447,10 @@ int config_parse_exec_smack_process_label(
+ 
+         r = unit_full_printf(u, rvalue, &k);
+         if (r < 0) {
+-                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to 
resolve specifiers, ignoring: %m");
+-                return 0;
++                log_syntax(unit, LOG_ERR, filename, line, r,
++                           "Failed to resolve specifiers%s: %m",
++                           ignore ? ", ignoring" : "");
++                return ignore ? 0 : -ENOEXEC;
+         }
+ 
+         free(c->smack_process_label);
+@@ -1648,19 +1668,19 @@ int config_parse_socket_service(
+ 
+         r = unit_name_printf(UNIT(s), rvalue, &p);
+         if (r < 0) {
+-                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to 
resolve specifiers, ignoring: %s", rvalue);
+-                return 0;
++                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to 
resolve specifiers: %s", rvalue);
++                return -ENOEXEC;
+         }
+ 
+         if (!endswith(p, ".service")) {
+-                log_syntax(unit, LOG_ERR, filename, line, 0, "Unit must be of 
type service, ignoring: %s", rvalue);
+-                return 0;
++                log_syntax(unit, LOG_ERR, filename, line, 0, "Unit must be of 
type service: %s", rvalue);
++                return -ENOEXEC;
+         }
+ 
+         r = manager_load_unit(UNIT(s)->manager, p, NULL, &error, &x);
+         if (r < 0) {
+-                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to load 
unit %s, ignoring: %s", rvalue, bus_error_message(&error, r));
+-                return 0;
++                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to load 
unit %s: %s", rvalue, bus_error_message(&error, r));
++                return -ENOEXEC;
+         }
+ 
+         unit_ref_set(&s->service, x);
+@@ -1911,13 +1931,13 @@ int config_parse_user_group(
+ 
+                 r = unit_full_printf(u, rvalue, &k);
+                 if (r < 0) {
+-                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed 
to resolve unit specifiers in %s, ignoring: %m", rvalue);
+-                        return 0;
++                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed 
to resolve unit specifiers in %s: %m", rvalue);
++                        return -ENOEXEC;
+                 }
+ 
+                 if (!valid_user_group_name_or_id(k)) {
+-                        log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid 
user/group name or numeric ID, ignoring: %s", k);
+-                        return 0;
++                        log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid 
user/group name or numeric ID: %s", k);
++                        return -ENOEXEC;
+                 }
+ 
+                 n = k;
+@@ -1975,19 +1995,19 @@ int config_parse_user_group_strv(
+                 if (r == -ENOMEM)
+                         return log_oom();
+                 if (r < 0) {
+-                        log_syntax(unit, LOG_ERR, filename, line, r, "Invalid 
syntax, ignoring: %s", rvalue);
+-                        break;
++                        log_syntax(unit, LOG_ERR, filename, line, r, "Invalid 
syntax: %s", rvalue);
++                        return -ENOEXEC;
+                 }
+ 
+                 r = unit_full_printf(u, word, &k);
+                 if (r < 0) {
+-                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed 
to resolve unit specifiers in %s, ignoring: %m", word);
+-                        continue;
++                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed 
to resolve unit specifiers in %s: %m", word);
++                        return -ENOEXEC;
+                 }
+ 
+                 if (!valid_user_group_name_or_id(k)) {
+-                        log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid 
user/group name or numeric ID, ignoring: %s", k);
+-                        continue;
++                        log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid 
user/group name or numeric ID: %s", k);
++                        return -ENOEXEC;
+                 }
+ 
+                 r = strv_push(users, k);
+@@ -2146,25 +2166,28 @@ int config_parse_working_directory(
+ 
+                 r = unit_full_printf(u, rvalue, &k);
+                 if (r < 0) {
+-                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed 
to resolve unit specifiers in working directory path '%s', ignoring: %m", 
rvalue);
+-                        return 0;
++                        log_syntax(unit, LOG_ERR, filename, line, r,
++                                   "Failed to resolve unit specifiers in 
working directory path '%s'%s: %m",
++                                   rvalue, missing_ok ? ", ignoring" : "");
++                        return missing_ok ? 0 : -ENOEXEC;
+                 }
+ 
+                 path_kill_slashes(k);
+ 
+                 if (!utf8_is_valid(k)) {
+                         log_syntax_invalid_utf8(unit, LOG_ERR, filename, 
line, rvalue);
+-                        return 0;
++                        return missing_ok ? 0 : -ENOEXEC;
+                 }
+ 
+                 if (!path_is_absolute(k)) {
+-                        log_syntax(unit, LOG_ERR, filename, line, 0, "Working 
directory path '%s' is not absolute, ignoring.", rvalue);
+-                        return 0;
++                        log_syntax(unit, LOG_ERR, filename, line, 0,
++                                   "Working directory path '%s' is not 
absolute%s.",
++                                   rvalue, missing_ok ? ", ignoring" : "");
++                        return missing_ok ? 0 : -ENOEXEC;
+                 }
+ 
+-                free_and_replace(c->working_directory, k);
+-
+                 c->working_directory_home = false;
++                free_and_replace(c->working_directory, k);
+         }
+ 
+         c->working_directory_missing_ok = missing_ok;
+@@ -4444,8 +4467,11 @@ int unit_load_fragment(Unit *u) {
+                         return r;
+ 
+                 r = load_from_path(u, k);
+-                if (r < 0)
++                if (r < 0) {
++                        if (r == -ENOEXEC)
++                                log_unit_notice(u, "Unit configuration has 
fatal error, unit will not be started.");
+                         return r;
++                }
+ 
+                 if (u->load_state == UNIT_STUB) {
+                         SET_FOREACH(t, u->names, i) {
+diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
+index 12f48bf43..fd797b587 100644
+--- a/src/test/test-unit-file.c
++++ b/src/test/test-unit-file.c
+@@ -146,7 +146,7 @@ static void test_config_parse_exec(void) {
+         r = config_parse_exec(NULL, "fake", 4, "section", 1,
+                               "LValue", 0, "/RValue/ argv0 r1",
+                               &c, u);
+-        assert_se(r == 0);
++        assert_se(r == -ENOEXEC);
+         assert_se(c1->command_next == NULL);
+ 
+         log_info("/* honour_argv0 */");
+@@ -161,7 +161,7 @@ static void test_config_parse_exec(void) {
+         r = config_parse_exec(NULL, "fake", 3, "section", 1,
+                               "LValue", 0, "@/RValue",
+                               &c, u);
+-        assert_se(r == 0);
++        assert_se(r == -ENOEXEC);
+         assert_se(c1->command_next == NULL);
+ 
+         log_info("/* no command, whitespace only, reset */");
+@@ -220,7 +220,7 @@ static void test_config_parse_exec(void) {
+                               "-@/RValue argv0 r1 ; ; "
+                               "/goo/goo boo",
+                               &c, u);
+-        assert_se(r >= 0);
++        assert_se(r == -ENOEXEC);
+         c1 = c1->command_next;
+         check_execcommand(c1, "/RValue", "argv0", "r1", NULL, true);
+ 
+@@ -374,7 +374,7 @@ static void test_config_parse_exec(void) {
+                 r = config_parse_exec(NULL, "fake", 4, "section", 1,
+                                       "LValue", 0, path,
+                                       &c, u);
+-                assert_se(r == 0);
++                assert_se(r == -ENOEXEC);
+                 assert_se(c1->command_next == NULL);
+         }
+ 
+@@ -401,21 +401,21 @@ static void test_config_parse_exec(void) {
+         r = config_parse_exec(NULL, "fake", 4, "section", 1,
+                               "LValue", 0, "/path\\",
+                               &c, u);
+-        assert_se(r == 0);
++        assert_se(r == -ENOEXEC);
+         assert_se(c1->command_next == NULL);
+ 
+         log_info("/* missing ending ' */");
+         r = config_parse_exec(NULL, "fake", 4, "section", 1,
+                               "LValue", 0, "/path 'foo",
+                               &c, u);
+-        assert_se(r == 0);
++        assert_se(r == -ENOEXEC);
+         assert_se(c1->command_next == NULL);
+ 
+         log_info("/* missing ending ' with trailing backslash */");
+         r = config_parse_exec(NULL, "fake", 4, "section", 1,
+                               "LValue", 0, "/path 'foo\\",
+                               &c, u);
+-        assert_se(r == 0);
++        assert_se(r == -ENOEXEC);
+         assert_se(c1->command_next == NULL);
+ 
+         log_info("/* invalid space between modifiers */");
+-- 
+2.13.2
+

diff --git a/sys-apps/systemd/systemd-233-r4.ebuild 
b/sys-apps/systemd/systemd-233-r4.ebuild
new file mode 100644
index 00000000000..40dd3e060ee
--- /dev/null
+++ b/sys-apps/systemd/systemd-233-r4.ebuild
@@ -0,0 +1,463 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+if [[ ${PV} == 9999 ]]; then
+       EGIT_REPO_URI="https://github.com/systemd/systemd.git";
+       inherit git-r3
+else
+       SRC_URI="https://github.com/systemd/systemd/archive/v${PV}.tar.gz -> 
${P}.tar.gz
+               !doc? ( https://dev.gentoo.org/~floppym/dist/${P}-man.tar.gz )"
+       KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~ia64 ~ppc ~ppc64 ~sparc ~x86"
+fi
+
+PYTHON_COMPAT=( python{3_4,3_5,3_6} )
+
+inherit autotools bash-completion-r1 linux-info multilib-minimal pam 
python-any-r1 systemd toolchain-funcs udev user
+
+DESCRIPTION="System and service manager for Linux"
+HOMEPAGE="https://www.freedesktop.org/wiki/Software/systemd";
+
+LICENSE="GPL-2 LGPL-2.1 MIT public-domain"
+SLOT="0/2"
+IUSE="acl apparmor audit build cryptsetup curl doc elfutils +gcrypt gnuefi http
+       idn importd +kmod +lz4 lzma nat pam policykit
+       qrcode +seccomp selinux ssl sysv-utils test vanilla xkb"
+
+REQUIRED_USE="importd? ( curl gcrypt lzma )"
+
+MINKV="3.11"
+
+COMMON_DEPEND=">=sys-apps/util-linux-2.27.1:0=[${MULTILIB_USEDEP}]
+       sys-libs/libcap:0=[${MULTILIB_USEDEP}]
+       !<sys-libs/glibc-2.16
+       acl? ( sys-apps/acl:0= )
+       apparmor? ( sys-libs/libapparmor:0= )
+       audit? ( >=sys-process/audit-2:0= )
+       cryptsetup? ( >=sys-fs/cryptsetup-1.6:0= )
+       curl? ( net-misc/curl:0= )
+       elfutils? ( >=dev-libs/elfutils-0.158:0= )
+       gcrypt? ( >=dev-libs/libgcrypt-1.4.5:0=[${MULTILIB_USEDEP}] )
+       http? (
+               >=net-libs/libmicrohttpd-0.9.33:0=
+               ssl? ( >=net-libs/gnutls-3.1.4:0= )
+       )
+       idn? ( net-dns/libidn:0= )
+       importd? (
+               app-arch/bzip2:0=
+               sys-libs/zlib:0=
+       )
+       kmod? ( >=sys-apps/kmod-15:0= )
+       lz4? ( >=app-arch/lz4-0_p131:0=[${MULTILIB_USEDEP}] )
+       lzma? ( >=app-arch/xz-utils-5.0.5-r1:0=[${MULTILIB_USEDEP}] )
+       nat? ( net-firewall/iptables:0= )
+       pam? ( virtual/pam:=[${MULTILIB_USEDEP}] )
+       qrcode? ( media-gfx/qrencode:0= )
+       seccomp? ( >=sys-libs/libseccomp-2.3.1:0= )
+       selinux? ( sys-libs/libselinux:0= )
+       sysv-utils? (
+               !sys-apps/systemd-sysv-utils
+               !sys-apps/sysvinit )
+       xkb? ( >=x11-libs/libxkbcommon-0.4.1:0= )
+       abi_x86_32? ( !<=app-emulation/emul-linux-x86-baselibs-20130224-r9
+               !app-emulation/emul-linux-x86-baselibs[-abi_x86_32(-)] )"
+
+# baselayout-2.2 has /run
+RDEPEND="${COMMON_DEPEND}
+       >=sys-apps/baselayout-2.2
+       selinux? ( sec-policy/selinux-base-policy[systemd] )
+       !build? ( || (
+               sys-apps/util-linux[kill(-)]
+               sys-process/procps[kill(+)]
+               sys-apps/coreutils[kill(-)]
+       ) )
+       !sys-auth/nss-myhostname
+       !<sys-kernel/dracut-044
+       !sys-fs/eudev
+       !sys-fs/udev"
+
+# sys-apps/dbus: the daemon only (+ build-time lib dep for tests)
+PDEPEND=">=sys-apps/dbus-1.9.8[systemd]
+       >=sys-apps/hwids-20150417[udev]
+       >=sys-fs/udev-init-scripts-25
+       policykit? ( sys-auth/polkit )
+       !vanilla? ( sys-apps/gentoo-systemd-integration )"
+
+# Newer linux-headers needed by ia64, bug #480218
+DEPEND="${COMMON_DEPEND}
+       app-arch/xz-utils:0
+       dev-util/gperf
+       >=dev-util/intltool-0.50
+       >=sys-apps/coreutils-8.16
+       >=sys-kernel/linux-headers-${MINKV}
+       virtual/pkgconfig
+       gnuefi? ( >=sys-boot/gnu-efi-3.0.2 )
+       test? ( sys-apps/dbus )
+       app-text/docbook-xml-dtd:4.2
+       app-text/docbook-xml-dtd:4.5
+       app-text/docbook-xsl-stylesheets
+       dev-libs/libxslt:0
+       doc? ( $(python_gen_any_dep 'dev-python/lxml[${PYTHON_USEDEP}]') )
+"
+
+python_check_deps() {
+       has_version --host-root "dev-python/lxml[${PYTHON_USEDEP}]"
+}
+
+pkg_pretend() {
+       if [[ ${MERGE_TYPE} != buildonly ]]; then
+               local CONFIG_CHECK="~AUTOFS4_FS ~BLK_DEV_BSG ~CGROUPS
+                       ~CHECKPOINT_RESTORE ~DEVTMPFS ~EPOLL ~FANOTIFY ~FHANDLE
+                       ~INOTIFY_USER ~IPV6 ~NET ~NET_NS ~PROC_FS ~SIGNALFD 
~SYSFS
+                       ~TIMERFD ~TMPFS_XATTR ~UNIX
+                       ~CRYPTO_HMAC ~CRYPTO_SHA256 ~CRYPTO_USER_API_HASH
+                       ~!FW_LOADER_USER_HELPER ~!GRKERNSEC_PROC ~!IDE 
~!SYSFS_DEPRECATED
+                       ~!SYSFS_DEPRECATED_V2"
+
+               use acl && CONFIG_CHECK+=" ~TMPFS_POSIX_ACL"
+               use seccomp && CONFIG_CHECK+=" ~SECCOMP ~SECCOMP_FILTER"
+               kernel_is -lt 3 7 && CONFIG_CHECK+=" ~HOTPLUG"
+               kernel_is -lt 4 7 && CONFIG_CHECK+=" ~DEVPTS_MULTIPLE_INSTANCES"
+
+               if linux_config_exists; then
+                       local uevent_helper_path=$(linux_chkconfig_string 
UEVENT_HELPER_PATH)
+                       if [[ -n ${uevent_helper_path} ]] && [[ 
${uevent_helper_path} != '""' ]]; then
+                               ewarn "It's recommended to set an empty value 
to the following kernel config option:"
+                               ewarn 
"CONFIG_UEVENT_HELPER_PATH=${uevent_helper_path}"
+                       fi
+                       if linux_chkconfig_present X86; then
+                               CONFIG_CHECK+=" ~DMIID"
+                       fi
+               fi
+
+               if kernel_is -lt ${MINKV//./ }; then
+                       ewarn "Kernel version at least ${MINKV} required"
+               fi
+
+               check_extra_config
+       fi
+}
+
+pkg_setup() {
+       :
+}
+
+src_unpack() {
+       default
+       [[ ${PV} != 9999 ]] || git-r3_src_unpack
+}
+
+src_prepare() {
+       # Bug 463376
+       sed -i -e 's/GROUP="dialout"/GROUP="uucp"/' rules/*.rules || die
+
+       local PATCHES=(
+               
"${FILESDIR}/233-0001-Avoid-strict-DM-interface-version-dependencies-5519.patch"
+               "${FILESDIR}/233-CVE-2017-9445.patch"
+               "${FILESDIR}/233-format-warnings.patch"
+               
"${FILESDIR}/233-0002-core-load-fragment-refuse-units-with-errors-in-RootD.patch"
+               
"${FILESDIR}/233-0003-core-load-fragment-refuse-units-with-errors-in-certa.patch"
+       )
+
+       if ! use vanilla; then
+               PATCHES+=(
+                       "${FILESDIR}/218-Dont-enable-audit-by-default.patch"
+                       "${FILESDIR}/228-noclean-tmp.patch"
+                       "${FILESDIR}/233-systemd-user-pam.patch"
+               )
+       fi
+
+       [[ -d "${WORKDIR}"/patches ]] && PATCHES+=( "${WORKDIR}"/patches )
+
+       default
+
+       eautoreconf
+}
+
+src_configure() {
+       # Keep using the one where the rules were installed.
+       MY_UDEVDIR=$(get_udevdir)
+       # Fix systems broken by bug #509454.
+       [[ ${MY_UDEVDIR} ]] || MY_UDEVDIR=/lib/udev
+
+       # Prevent conflicts with i686 cross toolchain, bug 559726
+       tc-export AR CC NM OBJCOPY RANLIB
+
+       use doc && python_setup
+
+       multilib-minimal_src_configure
+}
+
+multilib_src_configure() {
+       local myeconfargs=(
+               # disable -flto since it is an optimization flag
+               # and makes distcc less effective
+               cc_cv_CFLAGS__flto=no
+               # disable -fuse-ld=gold since Gentoo supports explicit linker
+               # choice and forcing gold is undesired, #539998
+               # ld.gold may collide with user's LDFLAGS, #545168
+               # ld.gold breaks sparc, #573874
+               cc_cv_LDFLAGS__Wl__fuse_ld_gold=no
+
+               # Workaround for gcc-4.7, bug 554454.
+               cc_cv_CFLAGS__Werror_shadow=no
+
+               # Workaround for bug 516346
+               --enable-dependency-tracking
+
+               --disable-maintainer-mode
+               --localstatedir=/var
+               --with-pamlibdir=$(getpam_mod_dir)
+               # avoid bash-completion dep
+               --with-bashcompletiondir="$(get_bashcompdir)"
+               # make sure we get /bin:/sbin in $PATH
+               --enable-split-usr
+               # For testing.
+               --with-rootprefix="${ROOTPREFIX-/usr}"
+               --with-rootlibdir="${ROOTPREFIX-/usr}/$(get_libdir)"
+               # disable sysv compatibility
+               --with-sysvinit-path=
+               --with-sysvrcnd-path=
+               # no deps
+               --enable-efi
+               --enable-ima
+
+               # Optional components/dependencies
+               $(multilib_native_use_enable acl)
+               $(multilib_native_use_enable apparmor)
+               $(multilib_native_use_enable audit)
+               $(multilib_native_use_enable cryptsetup libcryptsetup)
+               $(multilib_native_use_enable curl libcurl)
+               $(multilib_native_use_enable elfutils)
+               $(use_enable gcrypt)
+               $(multilib_native_use_enable gnuefi)
+               --with-efi-libdir="/usr/$(get_libdir)"
+               $(multilib_native_use_enable http microhttpd)
+               $(usex http $(multilib_native_use_enable ssl gnutls) 
--disable-gnutls)
+               $(multilib_native_use_enable idn libidn)
+               $(multilib_native_use_enable importd)
+               $(multilib_native_use_enable importd bzip2)
+               $(multilib_native_use_enable importd zlib)
+               $(multilib_native_use_enable kmod)
+               $(use_enable lz4)
+               $(use_enable lzma xz)
+               $(multilib_native_use_enable nat libiptc)
+               $(use_enable pam)
+               $(multilib_native_use_enable policykit polkit)
+               $(multilib_native_use_enable qrcode qrencode)
+               $(multilib_native_use_enable seccomp)
+               $(multilib_native_use_enable selinux)
+               $(multilib_native_use_enable test tests)
+               $(multilib_native_use_enable test dbus)
+               $(multilib_native_use_enable xkb xkbcommon)
+               $(multilib_native_use_with doc python)
+
+               # hardcode a few paths to spare some deps
+               KILL=/bin/kill
+               QUOTAON=/usr/sbin/quotaon
+               QUOTACHECK=/usr/sbin/quotacheck
+
+               # TODO: we may need to restrict this to gcc
+               EFI_CC="$(tc-getCC)"
+
+               # dbus paths
+               --with-dbuspolicydir="${EPREFIX}/etc/dbus-1/system.d"
+               
--with-dbussessionservicedir="${EPREFIX}/usr/share/dbus-1/services"
+               
--with-dbussystemservicedir="${EPREFIX}/usr/share/dbus-1/system-services"
+
+               --with-ntp-servers="0.gentoo.pool.ntp.org 1.gentoo.pool.ntp.org 
2.gentoo.pool.ntp.org 3.gentoo.pool.ntp.org"
+
+               # Breaks screen, tmux, etc.
+               --without-kill-user-processes
+       )
+
+       # Work around bug 463846.
+       tc-export CC
+
+       ECONF_SOURCE="${S}" econf "${myeconfargs[@]}"
+}
+
+multilib_src_compile() {
+       local mymakeopts=(
+               udevlibexecdir="${MY_UDEVDIR}"
+       )
+
+       if multilib_is_native_abi; then
+               emake "${mymakeopts[@]}"
+       else
+               emake built-sources
+               local targets=(
+                       '$(rootlib_LTLIBRARIES)'
+                       '$(lib_LTLIBRARIES)'
+                       '$(pamlib_LTLIBRARIES)'
+                       '$(pkgconfiglib_DATA)'
+               )
+               echo "gentoo: ${targets[*]}" | emake "${mymakeopts[@]}" -f 
Makefile -f - gentoo
+       fi
+}
+
+multilib_src_test() {
+       multilib_is_native_abi || return 0
+       default
+}
+
+multilib_src_install() {
+       local mymakeopts=(
+               # automake fails with parallel libtool relinking
+               # https://bugs.gentoo.org/show_bug.cgi?id=491398
+               -j1
+
+               udevlibexecdir="${MY_UDEVDIR}"
+               dist_udevhwdb_DATA=
+               DESTDIR="${D}"
+       )
+
+       if multilib_is_native_abi; then
+               emake "${mymakeopts[@]}" install
+       else
+               mymakeopts+=(
+                       install-rootlibLTLIBRARIES
+                       install-libLTLIBRARIES
+                       install-pamlibLTLIBRARIES
+                       install-pkgconfiglibDATA
+                       install-includeHEADERS
+                       install-pkgincludeHEADERS
+               )
+
+               emake "${mymakeopts[@]}"
+       fi
+}
+
+multilib_src_install_all() {
+       prune_libtool_files --modules
+       einstalldocs
+       dodoc "${FILESDIR}"/nsswitch.conf
+
+       if [[ ${PV} != 9999 ]]; then
+               use doc || doman "${WORKDIR}"/man/systemd.{directives,index}.7
+       fi
+
+       if use sysv-utils; then
+               for app in halt poweroff reboot runlevel shutdown telinit; do
+                       dosym "..${ROOTPREFIX-/usr}/bin/systemctl" /sbin/${app}
+               done
+               dosym "..${ROOTPREFIX-/usr}/lib/systemd/systemd" /sbin/init
+       else
+               # we just keep sysvinit tools, so no need for the mans
+               rm 
"${D}"/usr/share/man/man8/{halt,poweroff,reboot,runlevel,shutdown,telinit}.8 \
+                       || die
+               rm "${D}"/usr/share/man/man1/init.1 || die
+       fi
+
+       # Preserve empty dirs in /etc & /var, bug #437008
+       keepdir /etc/binfmt.d /etc/modules-load.d /etc/tmpfiles.d \
+               /etc/systemd/ntp-units.d /etc/systemd/user /var/lib/systemd \
+               /var/log/journal/remote
+
+       # Symlink /etc/sysctl.conf for easy migration.
+       dosym ../sysctl.conf /etc/sysctl.d/99-sysctl.conf
+
+       # If we install these symlinks, there is no way for the sysadmin to 
remove them
+       # permanently.
+       rm 
"${D}"/etc/systemd/system/multi-user.target.wants/systemd-networkd.service || 
die
+       rm -f 
"${D}"/etc/systemd/system/multi-user.target.wants/systemd-resolved.service || 
die
+       rm -r "${D}"/etc/systemd/system/network-online.target.wants || die
+       rm -r "${D}"/etc/systemd/system/sockets.target.wants || die
+       rm -r "${D}"/etc/systemd/system/sysinit.target.wants || die
+}
+
+migrate_locale() {
+       local envd_locale_def="${EROOT%/}/etc/env.d/02locale"
+       local envd_locale=( "${EROOT%/}"/etc/env.d/??locale )
+       local locale_conf="${EROOT%/}/etc/locale.conf"
+
+       if [[ ! -L ${locale_conf} && ! -e ${locale_conf} ]]; then
+               # If locale.conf does not exist...
+               if [[ -e ${envd_locale} ]]; then
+                       # ...either copy env.d/??locale if there's one
+                       ebegin "Moving ${envd_locale} to ${locale_conf}"
+                       mv "${envd_locale}" "${locale_conf}"
+                       eend ${?} || FAIL=1
+               else
+                       # ...or create a dummy default
+                       ebegin "Creating ${locale_conf}"
+                       cat > "${locale_conf}" <<-EOF
+                               # This file has been created by the 
sys-apps/systemd ebuild.
+                               # See locale.conf(5) and localectl(1).
+
+                               # LANG=${LANG}
+                       EOF
+                       eend ${?} || FAIL=1
+               fi
+       fi
+
+       if [[ ! -L ${envd_locale} ]]; then
+               # now, if env.d/??locale is not a symlink (to locale.conf)...
+               if [[ -e ${envd_locale} ]]; then
+                       # ...warn the user that he has duplicate locale settings
+                       ewarn
+                       ewarn "To ensure consistent behavior, you should 
replace ${envd_locale}"
+                       ewarn "with a symlink to ${locale_conf}. Please migrate 
your settings"
+                       ewarn "and create the symlink with the following 
command:"
+                       ewarn "ln -s -n -f ../locale.conf ${envd_locale}"
+                       ewarn
+               else
+                       # ...or just create the symlink if there's nothing here
+                       ebegin "Creating ${envd_locale_def} -> ../locale.conf 
symlink"
+                       ln -n -s ../locale.conf "${envd_locale_def}"
+                       eend ${?} || FAIL=1
+               fi
+       fi
+}
+
+pkg_postinst() {
+       newusergroup() {
+               enewgroup "$1"
+               enewuser "$1" -1 -1 -1 "$1"
+       }
+
+       enewgroup input
+       enewgroup systemd-journal
+       newusergroup systemd-bus-proxy
+       newusergroup systemd-coredump
+       newusergroup systemd-journal-gateway
+       newusergroup systemd-journal-remote
+       newusergroup systemd-journal-upload
+       newusergroup systemd-network
+       newusergroup systemd-resolve
+       newusergroup systemd-timesync
+
+       systemd_update_catalog
+
+       # Keep this here in case the database format changes so it gets updated
+       # when required. Despite that this file is owned by sys-apps/hwids.
+       if has_version "sys-apps/hwids[udev]"; then
+               udevadm hwdb --update --root="${ROOT%/}"
+       fi
+
+       udev_reload || FAIL=1
+
+       # Bug 465468, make sure locales are respect, and ensure consistency
+       # between OpenRC & systemd
+       migrate_locale
+
+       if [[ ${FAIL} ]]; then
+               eerror "One of the postinst commands failed. Please check the 
postinst output"
+               eerror "for errors. You may need to clean up your system and/or 
try installing"
+               eerror "systemd again."
+               eerror
+       fi
+
+       if [[ $(readlink "${ROOT}"etc/resolv.conf) == */run/systemd/* ]]; then
+               ewarn "You should replace the resolv.conf symlink:"
+               ewarn "ln -snf ${ROOTPREFIX-/usr}/lib/systemd/resolv.conf 
${ROOT}etc/resolv.conf"
+       fi
+}
+
+pkg_prerm() {
+       # If removing systemd completely, remove the catalog database.
+       if [[ ! ${REPLACED_BY_VERSION} ]]; then
+               rm -f -v "${EROOT}"/var/lib/systemd/catalog/database
+       fi
+}

Reply via email to