substs.set('systemgidmax', system_gid_max)
message('maximum system GID is @0@'.format(system_gid_max))
-dynamic_uid_min = get_option('dynamic-uid-min').to_int()
-dynamic_uid_max = get_option('dynamic-uid-max').to_int()
-conf.set('DYNAMIC_UID_MIN', dynamic_uid_min)
-conf.set('DYNAMIC_UID_MAX', dynamic_uid_max)
-substs.set('dynamicuidmin', dynamic_uid_min)
-substs.set('dynamicuidmax', dynamic_uid_max)
-
-container_uid_base_min = get_option('container-uid-base-min').to_int()
-container_uid_base_max = get_option('container-uid-base-max').to_int()
-conf.set('CONTAINER_UID_BASE_MIN', container_uid_base_min)
-conf.set('CONTAINER_UID_BASE_MAX', container_uid_base_max)
-substs.set('containeruidbasemin', container_uid_base_min)
-substs.set('containeruidbasemax', container_uid_base_max)
-
-nobody_user = get_option('nobody-user')
-nobody_group = get_option('nobody-group')
-
-getent_result = run_command('getent', 'passwd', '65534')
-if getent_result.returncode() == 0
- name = getent_result.stdout().split(':')[0]
- if name != nobody_user
- message('WARNING:\n' +
- ' The local user with the UID 65534 does not match the configured user name "@0@" of the nobody user (its name is @1@).\n'.format(nobody_user, name) +
- ' Your build will result in an user table setup that is incompatible with the local system.')
- endif
-endif
-id_result = run_command('id', '-u', nobody_user)
-if id_result.returncode() == 0
- id = id_result.stdout().to_int()
- if id != 65534
- message('WARNING:\n' +
- ' The local user with the configured user name "@0@" of the nobody user does not have UID 65534 (it has @1@).\n'.format(nobody_user, id) +
- ' Your build will result in an user table setup that is incompatible with the local system.')
- endif
-endif
-
-getent_result = run_command('getent', 'group', '65534')
-if getent_result.returncode() == 0
- name = getent_result.stdout().split(':')[0]
- if name != nobody_group
- message('WARNING:\n' +
- ' The local group with the GID 65534 does not match the configured group name "@0@" of the nobody group (its name is @1@).\n'.format(nobody_group, name) +
- ' Your build will result in an group table setup that is incompatible with the local system.')
- endif
-endif
-id_result = run_command('id', '-g', nobody_group)
-if id_result.returncode() == 0
- id = id_result.stdout().to_int()
- if id != 65534
- message('WARNING:\n' +
- ' The local group with the configured group name "@0@" of the nobody group does not have UID 65534 (it has @1@).\n'.format(nobody_group, id) +
- ' Your build will result in an group table setup that is incompatible with the local system.')
- endif
-endif
-if nobody_user != nobody_group and not (nobody_user == 'nobody' and nobody_group == 'nogroup')
- message('WARNING:\n' +
- ' The configured user name "@0@" and group name "@0@" of the nobody user/group are not equivalent.\n'.format(nobody_user, nobody_group) +
- ' Please re-check that both "nobody-user" and "nobody-group" options are correctly set.')
-endif
-
-conf.set_quoted('NOBODY_USER_NAME', nobody_user)
-conf.set_quoted('NOBODY_GROUP_NAME', nobody_group)
-substs.set('NOBODY_USER_NAME', nobody_user)
-substs.set('NOBODY_GROUP_NAME', nobody_group)
+#if 0 /// UNNEEDED by elogind
+# dynamic_uid_min = get_option('dynamic-uid-min').to_int()
+# dynamic_uid_max = get_option('dynamic-uid-max').to_int()
+# conf.set('DYNAMIC_UID_MIN', dynamic_uid_min)
+# conf.set('DYNAMIC_UID_MAX', dynamic_uid_max)
+# substs.set('dynamicuidmin', dynamic_uid_min)
+# substs.set('dynamicuidmax', dynamic_uid_max)
+#
+# container_uid_base_min = get_option('container-uid-base-min').to_int()
+# container_uid_base_max = get_option('container-uid-base-max').to_int()
+# conf.set('CONTAINER_UID_BASE_MIN', container_uid_base_min)
+# conf.set('CONTAINER_UID_BASE_MAX', container_uid_base_max)
+# substs.set('containeruidbasemin', container_uid_base_min)
+# substs.set('containeruidbasemax', container_uid_base_max)
+#
+# nobody_user = get_option('nobody-user')
+# nobody_group = get_option('nobody-group')
+#
+# getent_result = run_command('getent', 'passwd', '65534')
+# if getent_result.returncode() == 0
+# name = getent_result.stdout().split(':')[0]
+# if name != nobody_user
+# message('WARNING:\n' +
+# ' The local user with the UID 65534 does not match the configured user name "@0@" of the nobody user (its name is @1@).\n'.format(nobody_user, name) +
+# ' Your build will result in an user table setup that is incompatible with the local system.')
+# endif
+# endif
+# id_result = run_command('id', '-u', nobody_user)
+# if id_result.returncode() == 0
+# id = id_result.stdout().to_int()
+# if id != 65534
+# message('WARNING:\n' +
+# ' The local user with the configured user name "@0@" of the nobody user does not have UID 65534 (it has @1@).\n'.format(nobody_user, id) +
+# ' Your build will result in an user table setup that is incompatible with the local system.')
+# endif
+# endif
+#
+# getent_result = run_command('getent', 'group', '65534')
+# if getent_result.returncode() == 0
+# name = getent_result.stdout().split(':')[0]
+# if name != nobody_group
+# message('WARNING:\n' +
+# ' The local group with the GID 65534 does not match the configured group name "@0@" of the nobody group (its name is @1@).\n'.format(nobody_group, name) +
+# ' Your build will result in an group table setup that is incompatible with the local system.')
+# endif
+# endif
+# id_result = run_command('id', '-g', nobody_group)
+# if id_result.returncode() == 0
+# id = id_result.stdout().to_int()
+# if id != 65534
+# message('WARNING:\n' +
+# ' The local group with the configured group name "@0@" of the nobody group does not have UID 65534 (it has @1@).\n'.format(nobody_group, id) +
+# ' Your build will result in an group table setup that is incompatible with the local system.')
+# endif
+# endif
+# if nobody_user != nobody_group and not (nobody_user == 'nobody' and nobody_group == 'nogroup')
+# message('WARNING:\n' +
+# ' The configured user name "@0@" and group name "@0@" of the nobody user/group are not equivalent.\n'.format(nobody_user, nobody_group) +
+# ' Please re-check that both "nobody-user" and "nobody-group" options are correctly set.')
+# endif
+#
+# conf.set_quoted('NOBODY_USER_NAME', nobody_user)
+# conf.set_quoted('NOBODY_GROUP_NAME', nobody_group)
+# substs.set('NOBODY_USER_NAME', nobody_user)
+# substs.set('NOBODY_GROUP_NAME', nobody_group)
+#endif // 0
tty_gid = get_option('tty-gid')
conf.set('TTY_GID', tty_gid)
# endif
#
# substs.set('DEV_KVM_MODE', get_option('dev-kvm-mode'))
+# substs.set('GROUP_RENDER_MODE', get_option('group-render-mode'))
#endif // 0
-substs.set('GROUP_RENDER_MODE', get_option('group-render-mode'))
kill_user_processes = get_option('default-kill-user-processes')
conf.set10('KILL_USER_PROCESSES', kill_user_processes)
libshared_static],
dependencies: [libacl,
libudev],
+ install_rpath : rootlibexecdir,
+ install : true,
+ install_dir : rootlibexecdir)
#endif // 0
############################################################
# get_option('debug-tty')),
#endif // 0
'TTY GID: @0@'.format(tty_gid),
- 'users GID: @0@'.format(users_gid),
+#if 0 /// UNSUPPORTED by elogind
+# 'users GID: @0@'.format(users_gid),
+#endif // 0
'maximum system UID: @0@'.format(system_uid_max),
'maximum system GID: @0@'.format(system_gid_max),
#if 0 /// UNSUPPORTED by elogind
+/* SPDX-License-Identifier: LGPL-2.1+ */
/***
This file is part of systemd.
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
+#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
return -errno;
}
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
if (max_length == 1) {
/* If there's only room for one byte, return the empty string */
return -errno;
}
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
count = fread(&c, 1, 1, f);
eof = feof(f);
fclose(f);
return -errno;
}
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
FOREACH_LINE(line, f, return -errno) {
char *l;
return -errno;
}
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
while ((c = fgetc(f)) != EOF) {
if (!GREEDY_REALLOC(outcome, allocated, sz + 5))
return -ENOMEM;
}
#if 0 /// UNNEEDED by elogind
+/*
+ * Return values:
+ * < 0 : wait_for_terminate_with_timeout() failed to get the state of the
+ * process, the process timed out, the process was terminated by a
+ * signal, or failed for an unknown reason.
+ * >=0 : The process terminated normally with no failures.
+ *
+ * Success is indicated by a return value of zero, a timeout is indicated
+ * by ETIMEDOUT, and all other child failure states are indicated by error
+ * is indicated by a non-zero value.
+ */
+int wait_for_terminate_with_timeout(pid_t pid, usec_t timeout) {
+ sigset_t mask;
+ int r;
+ usec_t until;
+
+ assert_se(sigemptyset(&mask) == 0);
+ assert_se(sigaddset(&mask, SIGCHLD) == 0);
+
+ /* Drop into a sigtimewait-based timeout. Waiting for the
+ * pid to exit. */
+ until = now(CLOCK_MONOTONIC) + timeout;
+ for (;;) {
+ usec_t n;
+ siginfo_t status = {};
+ struct timespec ts;
+
+ n = now(CLOCK_MONOTONIC);
+ if (n >= until)
+ break;
+
+ r = sigtimedwait(&mask, NULL, timespec_store(&ts, until - n)) < 0 ? -errno : 0;
+ /* Assuming we woke due to the child exiting. */
+ if (waitid(P_PID, pid, &status, WEXITED|WNOHANG) == 0) {
+ if (status.si_pid == pid) {
+ /* This is the correct child.*/
+ if (status.si_code == CLD_EXITED)
+ return (status.si_status == 0) ? 0 : -EPROTO;
+ else
+ return -EPROTO;
+ }
+ }
+ /* Not the child, check for errors and proceed appropriately */
+ if (r < 0) {
+ switch (r) {
+ case -EAGAIN:
+ /* Timed out, child is likely hung. */
+ return -ETIMEDOUT;
+ case -EINTR:
+ /* Received a different signal and should retry */
+ continue;
+ default:
+ /* Return any unexpected errors */
+ return r;
+ }
+ }
+ }
+
+ return -EPROTO;
+}
+
void sigkill_wait(pid_t pid) {
assert(pid > 1);
return -errno;
}
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
l = strlen(field);
r = 0;
* wrapper that uses errno if it is set, and uses the return value otherwise. And then it sets both errno and
* the return value indicating the same issue, so that we are definitely on the safe side.
*
- * See https://github.com/elogind/elogind/issues/6737 */
+ * See https://github.com/systemd/systemd/issues/6737 */
errno = 0;
ret = personality(p);
}
}
+int must_be_root(void) {
+
+ if (geteuid() == 0)
+ return 0;
+
+ log_error("Need to be root.");
+ return -EPERM;
+}
+
#if 0 /// UNNEEDED by elogind
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
+++ /dev/null
-/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
- This file is part of elogind.
-
- Copyright 2017 Lennart Poettering
-
- elogind is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- elogind is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with elogind; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-#include "alloc-util.h"
-#include "log.h"
-#include "specifier.h"
-#include "string-util.h"
-#include "strv.h"
-
-static void test_specifier_escape_one(const char *a, const char *b) {
- _cleanup_free_ char *x = NULL;
-
- x = specifier_escape(a);
- assert_se(streq_ptr(x, b));
-}
-
-static void test_specifier_escape(void) {
- test_specifier_escape_one(NULL, NULL);
- test_specifier_escape_one("", "");
- test_specifier_escape_one("%", "%%");
- test_specifier_escape_one("foo bar", "foo bar");
- test_specifier_escape_one("foo%bar", "foo%%bar");
- test_specifier_escape_one("%%%%%", "%%%%%%%%%%");
-}
-
-static void test_specifier_escape_strv_one(char **a, char **b) {
- _cleanup_strv_free_ char **x = NULL;
-
- assert_se(specifier_escape_strv(a, &x) >= 0);
- assert_se(strv_equal(x, b));
-}
-
-static void test_specifier_escape_strv(void) {
- test_specifier_escape_strv_one(NULL, NULL);
- test_specifier_escape_strv_one(STRV_MAKE(NULL), STRV_MAKE(NULL));
- test_specifier_escape_strv_one(STRV_MAKE(""), STRV_MAKE(""));
- test_specifier_escape_strv_one(STRV_MAKE("foo"), STRV_MAKE("foo"));
- test_specifier_escape_strv_one(STRV_MAKE("%"), STRV_MAKE("%%"));
- test_specifier_escape_strv_one(STRV_MAKE("foo", "%", "foo%", "%foo", "foo%foo", "quux", "%%%"), STRV_MAKE("foo", "%%", "foo%%", "%%foo", "foo%%foo", "quux", "%%%%%%"));
-}
-
-int main(int argc, char *argv[]) {
- log_set_max_level(LOG_DEBUG);
-
- test_specifier_escape();
- test_specifier_escape_strv();
-
- return 0;
-}