diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/execute.c | 1 | ||||
-rw-r--r-- | src/journal/journald.h | 1 | ||||
-rw-r--r-- | src/login/logind.h | 1 | ||||
-rw-r--r-- | src/login/pam-module.c | 1 | ||||
-rw-r--r-- | src/nspawn.c | 1 | ||||
-rw-r--r-- | src/shared/audit.c | 118 | ||||
-rw-r--r-- | src/shared/audit.h | 29 | ||||
-rw-r--r-- | src/shared/capability.c | 86 | ||||
-rw-r--r-- | src/shared/capability.h | 27 | ||||
-rw-r--r-- | src/shared/conf-parser.c (renamed from src/conf-parser.c) | 0 | ||||
-rw-r--r-- | src/shared/conf-parser.h (renamed from src/conf-parser.h) | 0 | ||||
-rw-r--r-- | src/shared/exit-status.c (renamed from src/exit-status.c) | 0 | ||||
-rw-r--r-- | src/shared/exit-status.h (renamed from src/exit-status.h) | 0 | ||||
-rw-r--r-- | src/shared/hashmap.c (renamed from src/hashmap.c) | 0 | ||||
-rw-r--r-- | src/shared/hashmap.h (renamed from src/hashmap.h) | 0 | ||||
-rw-r--r-- | src/shared/label.c (renamed from src/label.c) | 0 | ||||
-rw-r--r-- | src/shared/label.h (renamed from src/label.h) | 0 | ||||
-rw-r--r-- | src/shared/log.c (renamed from src/log.c) | 0 | ||||
-rw-r--r-- | src/shared/log.h (renamed from src/log.h) | 0 | ||||
-rw-r--r-- | src/shared/ratelimit.c (renamed from src/ratelimit.c) | 0 | ||||
-rw-r--r-- | src/shared/ratelimit.h (renamed from src/ratelimit.h) | 0 | ||||
-rw-r--r-- | src/shared/set.c (renamed from src/set.c) | 0 | ||||
-rw-r--r-- | src/shared/set.h (renamed from src/set.h) | 0 | ||||
-rw-r--r-- | src/shared/socket-util.c (renamed from src/socket-util.c) | 0 | ||||
-rw-r--r-- | src/shared/socket-util.h (renamed from src/socket-util.h) | 0 | ||||
-rw-r--r-- | src/shared/strv.c (renamed from src/strv.c) | 0 | ||||
-rw-r--r-- | src/shared/strv.h (renamed from src/strv.h) | 0 | ||||
-rw-r--r-- | src/shared/utf8.c (renamed from src/utf8.c) | 0 | ||||
-rw-r--r-- | src/shared/utf8.h (renamed from src/utf8.h) | 0 | ||||
-rw-r--r-- | src/shared/util.c (renamed from src/util.c) | 133 | ||||
-rw-r--r-- | src/shared/util.h (renamed from src/util.h) | 8 | ||||
-rw-r--r-- | src/shared/virt.c (renamed from src/virt.c) | 0 | ||||
-rw-r--r-- | src/shared/virt.h (renamed from src/virt.h) | 0 |
33 files changed, 265 insertions, 141 deletions
diff --git a/src/execute.c b/src/execute.c index dab485682b..179ca7e55c 100644 --- a/src/execute.c +++ b/src/execute.c @@ -45,6 +45,7 @@ #include "execute.h" #include "strv.h" #include "macro.h" +#include "capability.h" #include "util.h" #include "log.h" #include "ioprio.h" diff --git a/src/journal/journald.h b/src/journal/journald.h index 6160991ed8..7840fd5730 100644 --- a/src/journal/journald.h +++ b/src/journal/journald.h @@ -29,6 +29,7 @@ #include "journal-file.h" #include "hashmap.h" #include "util.h" +#include "audit.h" #include "journal-rate-limit.h" #include "list.h" diff --git a/src/login/logind.h b/src/login/logind.h index a4b4602675..9586793ad4 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -28,6 +28,7 @@ #include <libudev.h> #include "util.h" +#include "audit.h" #include "list.h" #include "hashmap.h" #include "cgroup-util.h" diff --git a/src/login/pam-module.c b/src/login/pam-module.c index 4106d2ba4b..1edb91c804 100644 --- a/src/login/pam-module.c +++ b/src/login/pam-module.c @@ -35,6 +35,7 @@ #include <systemd/sd-daemon.h> #include "util.h" +#include "audit.h" #include "macro.h" #include "strv.h" #include "dbus-common.h" diff --git a/src/nspawn.c b/src/nspawn.c index 6f5a9d9547..66910bc684 100644 --- a/src/nspawn.c +++ b/src/nspawn.c @@ -43,6 +43,7 @@ #include "log.h" #include "util.h" +#include "audit.h" #include "missing.h" #include "cgroup-util.h" #include "strv.h" diff --git a/src/shared/audit.c b/src/shared/audit.c new file mode 100644 index 0000000000..3850059132 --- /dev/null +++ b/src/shared/audit.c @@ -0,0 +1,118 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + systemd 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include <assert.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <stdlib.h> +#include <stdio.h> +#include <ctype.h> +#include <sys/prctl.h> +#include <sys/capability.h> + +#include "macro.h" +#include "audit.h" +#include "util.h" +#include "log.h" + +int audit_session_from_pid(pid_t pid, uint32_t *id) { + char *s; + uint32_t u; + int r; + + assert(id); + + if (have_effective_cap(CAP_AUDIT_CONTROL) <= 0) + return -ENOENT; + + if (pid == 0) + r = read_one_line_file("/proc/self/sessionid", &s); + else { + char *p; + + if (asprintf(&p, "/proc/%lu/sessionid", (unsigned long) pid) < 0) + return -ENOMEM; + + r = read_one_line_file(p, &s); + free(p); + } + + if (r < 0) + return r; + + r = safe_atou32(s, &u); + free(s); + + if (r < 0) + return r; + + if (u == (uint32_t) -1 || u <= 0) + return -ENOENT; + + *id = u; + return 0; +} + +int audit_loginuid_from_pid(pid_t pid, uid_t *uid) { + char *s; + uid_t u; + int r; + + assert(uid); + + /* Only use audit login uid if we are executed with sufficient + * capabilities so that pam_loginuid could do its job. If we + * are lacking the CAP_AUDIT_CONTROL capabality we most likely + * are being run in a container and /proc/self/loginuid is + * useless since it probably contains a uid of the host + * system. */ + + if (have_effective_cap(CAP_AUDIT_CONTROL) <= 0) + return -ENOENT; + + if (pid == 0) + r = read_one_line_file("/proc/self/loginuid", &s); + else { + char *p; + + if (asprintf(&p, "/proc/%lu/loginuid", (unsigned long) pid) < 0) + return -ENOMEM; + + r = read_one_line_file(p, &s); + free(p); + } + + if (r < 0) + return r; + + r = parse_uid(s, &u); + free(s); + + if (r < 0) + return r; + + if (u == (uid_t) -1) + return -ENOENT; + + *uid = (uid_t) u; + return 0; +} diff --git a/src/shared/audit.h b/src/shared/audit.h new file mode 100644 index 0000000000..3529046ff3 --- /dev/null +++ b/src/shared/audit.h @@ -0,0 +1,29 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#ifndef fooaudithfoo +#define fooaudithfoo + +/*** + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + systemd 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include "capability.h" + +int audit_session_from_pid(pid_t pid, uint32_t *id); +int audit_loginuid_from_pid(pid_t pid, uid_t *uid); +#endif diff --git a/src/shared/capability.c b/src/shared/capability.c new file mode 100644 index 0000000000..b8002159ec --- /dev/null +++ b/src/shared/capability.c @@ -0,0 +1,86 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + systemd 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include <assert.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <stdio.h> +#include <sys/types.h> +#include <stdarg.h> +#include <ctype.h> +#include <sys/capability.h> +#include <sys/prctl.h> + +#include "macro.h" +#include "capability.h" +#include "util.h" +#include "log.h" + +int have_effective_cap(int value) { + cap_t cap; + cap_flag_value_t fv; + int r; + + if (!(cap = cap_get_proc())) + return -errno; + + if (cap_get_flag(cap, value, CAP_EFFECTIVE, &fv) < 0) + r = -errno; + else + r = fv == CAP_SET; + + cap_free(cap); + return r; +} + +unsigned long cap_last_cap(void) { + static __thread unsigned long saved; + static __thread bool valid = false; + unsigned long p; + + if (valid) + return saved; + + p = (unsigned long) CAP_LAST_CAP; + + if (prctl(PR_CAPBSET_READ, p) < 0) { + + /* Hmm, look downwards, until we find one that + * works */ + for (p--; p > 0; p --) + if (prctl(PR_CAPBSET_READ, p) >= 0) + break; + + } else { + + /* Hmm, look upwards, until we find one that doesn't + * work */ + for (;; p++) + if (prctl(PR_CAPBSET_READ, p+1) < 0) + break; + } + + saved = p; + valid = true; + + return p; +} diff --git a/src/shared/capability.h b/src/shared/capability.h new file mode 100644 index 0000000000..ab7e40b601 --- /dev/null +++ b/src/shared/capability.h @@ -0,0 +1,27 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#ifndef foocapabilityhfoo +#define foocapabilityhfoo + +/*** + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + systemd 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +unsigned long cap_last_cap(void); +int have_effective_cap(int value); +#endif diff --git a/src/conf-parser.c b/src/shared/conf-parser.c index a9b01135e6..a9b01135e6 100644 --- a/src/conf-parser.c +++ b/src/shared/conf-parser.c diff --git a/src/conf-parser.h b/src/shared/conf-parser.h index be7d708171..be7d708171 100644 --- a/src/conf-parser.h +++ b/src/shared/conf-parser.h diff --git a/src/exit-status.c b/src/shared/exit-status.c index ab8907d32c..ab8907d32c 100644 --- a/src/exit-status.c +++ b/src/shared/exit-status.c diff --git a/src/exit-status.h b/src/shared/exit-status.h index 44ef879562..44ef879562 100644 --- a/src/exit-status.h +++ b/src/shared/exit-status.h diff --git a/src/hashmap.c b/src/shared/hashmap.c index 6928118615..6928118615 100644 --- a/src/hashmap.c +++ b/src/shared/hashmap.c diff --git a/src/hashmap.h b/src/shared/hashmap.h index ab4363a7a3..ab4363a7a3 100644 --- a/src/hashmap.h +++ b/src/shared/hashmap.h diff --git a/src/label.c b/src/shared/label.c index 2c887a0fe5..2c887a0fe5 100644 --- a/src/label.c +++ b/src/shared/label.c diff --git a/src/label.h b/src/shared/label.h index ead44837a4..ead44837a4 100644 --- a/src/label.h +++ b/src/shared/label.h diff --git a/src/log.c b/src/shared/log.c index 9fffc1dbc0..9fffc1dbc0 100644 --- a/src/log.c +++ b/src/shared/log.c diff --git a/src/log.h b/src/shared/log.h index 3283808ff8..3283808ff8 100644 --- a/src/log.h +++ b/src/shared/log.h diff --git a/src/ratelimit.c b/src/shared/ratelimit.c index 93157c7a2e..93157c7a2e 100644 --- a/src/ratelimit.c +++ b/src/shared/ratelimit.c diff --git a/src/ratelimit.h b/src/shared/ratelimit.h index a6443e7f87..a6443e7f87 100644 --- a/src/ratelimit.h +++ b/src/shared/ratelimit.h diff --git a/src/set.c b/src/shared/set.c index 097b9d3aae..097b9d3aae 100644 --- a/src/set.c +++ b/src/shared/set.c diff --git a/src/set.h b/src/shared/set.h index 885780c4c0..885780c4c0 100644 --- a/src/set.h +++ b/src/shared/set.h diff --git a/src/socket-util.c b/src/shared/socket-util.c index acc4d33372..acc4d33372 100644 --- a/src/socket-util.c +++ b/src/shared/socket-util.c diff --git a/src/socket-util.h b/src/shared/socket-util.h index 8ccbd371cf..8ccbd371cf 100644 --- a/src/socket-util.h +++ b/src/shared/socket-util.h diff --git a/src/strv.c b/src/shared/strv.c index bb309d9f92..bb309d9f92 100644 --- a/src/strv.c +++ b/src/shared/strv.c diff --git a/src/strv.h b/src/shared/strv.h index d038c9f3b1..d038c9f3b1 100644 --- a/src/strv.h +++ b/src/shared/strv.h diff --git a/src/utf8.c b/src/shared/utf8.c index 11619dce2f..11619dce2f 100644 --- a/src/utf8.c +++ b/src/shared/utf8.c diff --git a/src/utf8.h b/src/shared/utf8.h index 9a72bec084..9a72bec084 100644 --- a/src/utf8.h +++ b/src/shared/utf8.h diff --git a/src/util.c b/src/shared/util.c index dfc1dc6b85..563853fad6 100644 --- a/src/util.c +++ b/src/shared/util.c @@ -4716,23 +4716,6 @@ void skip_syslog_date(char **buf) { *buf = p; } -int have_effective_cap(int value) { - cap_t cap; - cap_flag_value_t fv; - int r; - - if (!(cap = cap_get_proc())) - return -errno; - - if (cap_get_flag(cap, value, CAP_EFFECTIVE, &fv) < 0) - r = -errno; - else - r = fv == CAP_SET; - - cap_free(cap); - return r; -} - char* strshorten(char *s, size_t l) { assert(s); @@ -5399,89 +5382,6 @@ int symlink_or_copy_atomic(const char *from, const char *to) { return r; } -int audit_session_from_pid(pid_t pid, uint32_t *id) { - char *s; - uint32_t u; - int r; - - assert(id); - - if (have_effective_cap(CAP_AUDIT_CONTROL) <= 0) - return -ENOENT; - - if (pid == 0) - r = read_one_line_file("/proc/self/sessionid", &s); - else { - char *p; - - if (asprintf(&p, "/proc/%lu/sessionid", (unsigned long) pid) < 0) - return -ENOMEM; - - r = read_one_line_file(p, &s); - free(p); - } - - if (r < 0) - return r; - - r = safe_atou32(s, &u); - free(s); - - if (r < 0) - return r; - - if (u == (uint32_t) -1 || u <= 0) - return -ENOENT; - - *id = u; - return 0; -} - -int audit_loginuid_from_pid(pid_t pid, uid_t *uid) { - char *s; - uid_t u; - int r; - - assert(uid); - - /* Only use audit login uid if we are executed with sufficient - * capabilities so that pam_loginuid could do its job. If we - * are lacking the CAP_AUDIT_CONTROL capabality we most likely - * are being run in a container and /proc/self/loginuid is - * useless since it probably contains a uid of the host - * system. */ - - if (have_effective_cap(CAP_AUDIT_CONTROL) <= 0) - return -ENOENT; - - if (pid == 0) - r = read_one_line_file("/proc/self/loginuid", &s); - else { - char *p; - - if (asprintf(&p, "/proc/%lu/loginuid", (unsigned long) pid) < 0) - return -ENOMEM; - - r = read_one_line_file(p, &s); - free(p); - } - - if (r < 0) - return r; - - r = parse_uid(s, &u); - free(s); - - if (r < 0) - return r; - - if (u == (uid_t) -1) - return -ENOENT; - - *uid = (uid_t) u; - return 0; -} - bool display_is_local(const char *display) { assert(display); @@ -6137,39 +6037,6 @@ int prot_from_flags(int flags) { } } -unsigned long cap_last_cap(void) { - static __thread unsigned long saved; - static __thread bool valid = false; - unsigned long p; - - if (valid) - return saved; - - p = (unsigned long) CAP_LAST_CAP; - - if (prctl(PR_CAPBSET_READ, p) < 0) { - - /* Hmm, look downwards, until we find one that - * works */ - for (p--; p > 0; p --) - if (prctl(PR_CAPBSET_READ, p) >= 0) - break; - - } else { - - /* Hmm, look upwards, until we find one that doesn't - * work */ - for (;; p++) - if (prctl(PR_CAPBSET_READ, p+1) < 0) - break; - } - - saved = p; - valid = true; - - return p; -} - char *format_bytes(char *buf, size_t l, off_t t) { unsigned i; diff --git a/src/util.h b/src/shared/util.h index b1af6dbe7c..e96d56dd2a 100644 --- a/src/util.h +++ b/src/shared/util.h @@ -431,8 +431,6 @@ void parse_syslog_priority(char **p, int *priority); void skip_syslog_pid(char **buf); void skip_syslog_date(char **buf); -int have_effective_cap(int value); - bool hostname_is_valid(const char *s); char* hostname_cleanup(char *s); @@ -457,9 +455,6 @@ int hwclock_reset_localtime_delta(void); int hwclock_get_time(struct tm *tm); int hwclock_set_time(const struct tm *tm); -int audit_session_from_pid(pid_t pid, uint32_t *id); -int audit_loginuid_from_pid(pid_t pid, uid_t *uid); - bool display_is_local(const char *display); int socket_from_display(const char *display, char **path); @@ -526,8 +521,6 @@ bool kexec_loaded(void); int prot_from_flags(int flags); -unsigned long cap_last_cap(void); - char *format_bytes(char *buf, size_t l, off_t t); int fd_wait_for_event(int fd, int event, usec_t timeout); @@ -540,5 +533,4 @@ int is_kernel_thread(pid_t pid); int fd_inc_sndbuf(int fd, size_t n); int fd_inc_rcvbuf(int fd, size_t n); - #endif diff --git a/src/virt.c b/src/shared/virt.c index 4c526ff454..4c526ff454 100644 --- a/src/virt.c +++ b/src/shared/virt.c diff --git a/src/virt.h b/src/shared/virt.h index f55c9a68fd..f55c9a68fd 100644 --- a/src/virt.h +++ b/src/shared/virt.h |