Commit Graph

212 Commits

Author SHA1 Message Date
Reverend Homer 8fb3f00997 tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853) 2016-12-09 10:04:30 +01:00
Zbigniew Jędrzejewski-Szmek f97b34a629 Rename formats-util.h to format-util.h
We don't have plural in the name of any other -util files and this
inconsistency trips me up every time I try to type this file name
from memory. "formats-util" is even hard to pronounce.
2016-11-07 10:15:08 -05:00
Lennart Poettering c5a11ae268 logind: enforce a limit on inhibitors we hand out
For similar reasons as the recent addition of a limit on sessions.

Note that we don't enforce a limit on inhibitors per-user currently, but
there's an implicit one, since each inhibitor takes up one fd, and fds are
limited via RLIMIT_NOFILE, and the limit on the number of processes per user.
2016-05-05 22:50:09 +02:00
Lennart Poettering 6d97d3c648 logind: expose more configuration settings as bus properties 2016-05-05 22:50:09 +02:00
Lennart Poettering 183e073842 logind: enforce a limit on current user sessions
We really should put limits on all resources we manage, hence add one to the
number of concurrent sessions, too. This was previously unbounded, hence set a
relatively high limit of 8K by default.

Note that most PAM setups will actually invoke pam_systemd prefixed with "-",
so that the return code of pam_systemd is ignored, and the login attempt
succeeds anyway. On systems like this the session will be created but is not
tracked by systemd.
2016-05-05 22:50:09 +02:00
Zbigniew Jędrzejewski-Szmek 152199f2d7 logind: allow any user to request lingering
We enable lingering for anyone who wants this. It is still disabled by
default to avoid keeping long-running processes accidentally.
Admins might want to customize this policy on multi-user sites.
2016-04-21 00:21:33 -04:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Nicolas Iooss 4b51966cf6 logind: load SELinux labelling system
systemd-logind uses mkdir_label and label_fix functions without calling
first mac_selinux_init.  This makes /run/user/$UID/ directories not
labelled correctly on an Arch Linux system using SELinux.

Fix this by calling mac_selinux_init("/run") early in systemd-logind.
This makes files created in /etc/udev/rules.d and /var/lib/systemd to be
labelled through transitions in the SELinux policy instead of using
setfscreatecon (with mac_selinux_create_file_prepare).
2016-02-02 20:07:46 +01:00
Zbigniew Jędrzejewski-Szmek 2adae5ac5d logind: simplify job variable handling
manager_{start,stop}_{slice,scope,unit} functions had an optional job
output parameter. But all callers specified job, so make the parameter
mandatory, add asserts. Also extract common job variable handling to
a helper function to avoid duplication.

Avoids gcc warning about job being unitialized.
2016-01-18 15:21:28 -05:00
Zbigniew Jędrzejewski-Szmek 011062f3c0 logind: do not use an uninitialized variable
We requested various fields using SD_BUS_CREDS_AUGMENT but at least
sd_bus_creds_get_tty can fail with ENXIO, not setting the output variable.
2016-01-18 15:21:28 -05:00
Zbigniew Jędrzejewski-Szmek f5e5c28f42 tree-wide: check if errno is greater then zero
gcc is confused by the common idiom of
  return errno ? -errno : -ESOMETHING
and thinks a positive value may be returned. Replace this condition
with errno > 0 to help gcc and avoid many spurious warnings. I filed
a gcc rfe a long time ago, but it hard to say if it will ever be
implemented [1].

Both conventions were used in the codebase, this change makes things
more consistent. This is a follow up to bcb161b023.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61846
2016-01-13 15:09:55 -05:00
Joost Bremmer 0671d7f463 Fix typo on logind-dbus.c
method_schedule_shutdown referenced org.freedesktop.login1.poweroff*
which is never registered in polkit.

Now refers to org.freedesktop.login1.power-off*

Signed-off-by: Joost Bremmer <toost.b@gmail.com>
2015-12-19 12:46:09 +01:00
Michal Sekletar 716cff4b45 login: make sure /run/nologin has correct SELinux label 2015-12-04 22:29:38 +01:00
Lennart Poettering 4afd3348c7 tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.

With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.

The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).

This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.

Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:

       #define _cleanup_(function) __attribute__((cleanup(function)))

Or similar, to make the gcc feature easier to use.

Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.

See #2008.
2015-11-27 19:19:36 +01:00
David Herrmann 2f157acdae login: ignore JobRemoved of old jobs
If we requeue jobs, we are no longer interested in old jobs. Hence, we
better ignore any JobRemoved signals for old jobs and concentrate on our
replacements.
2015-11-16 16:15:42 +01:00
David Herrmann 79ee4ad108 login: make sure to replace existing units
When queuing unit jobs, we should rather replace existing units than
fail. This is especially important when we queued a user-shutdown and a
new login is encountered. In this case, we better raplce the shutdown
jobs. systemd takes care of everything else.
2015-11-16 15:43:18 +01:00
David Herrmann 44690833df Merge pull request #1886 from poettering/tasks-max
Enable TasksMax by default for all units
2015-11-16 15:09:55 +01:00
Lennart Poettering 06820eafdb machined,logind: be more careful when accepting PIDs and UIDs from clients
Always validate first before we start processing the data.
2015-11-15 22:00:47 +01:00
Lennart Poettering 90558f3158 logind: add a new UserTasksMax= setting to logind.conf
This new setting configures the TasksMax= field for the slice objects we
create for each user.

This alters logind to create the slice unit as transient unit explicitly
instead of relying on implicit generation of slice units by simply
starting them. This also enables us to set a friendly description for
slice units that way.
2015-11-13 19:50:52 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 430f0182b7 src/basic: rename audit.[ch] → audit-util.[ch] and capability.[ch] → capability-util.[ch]
The files are named too generically, so that they might conflict with
the upstream project headers. Hence, let's add a "-util" suffix, to
clarify that this are just our utility headers and not any official
upstream headers.
2015-10-27 13:25:57 +01:00
Lennart Poettering f4f15635ec util-lib: move a number of fs operations into fs-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering a09561746f util-lib: introduce dirent-util.[ch] for directory entry calls
Also, move a couple of more path-related functions to path-util.c.
2015-10-27 13:25:56 +01:00
Lennart Poettering d02608170e util: remove lookup_uid(), replace by uid_to_name()
So far we had two pretty much identical calls in user-util.[ch]:
lookup_uid() and uid_to_name(). Get rid of the former, in favour of the
latter, and while we are at it, rewrite it, to use getpwuid_r()
correctly, inside an allocation loop, as POSIX intended.
2015-10-26 01:24:38 +01:00
Lennart Poettering b1d4f8e154 util-lib: split out user/group/uid/gid calls into user-util.[ch] 2015-10-26 01:24:38 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 4f5dd3943b util: split out escaping code into escape.[ch]
This really deserves its own file, given how much code this is now.
2015-10-24 23:04:42 +02:00
Tom Gundersen af4efb515b login: suspend - be a bit more explicit when logging
When the Suspend method is called, the only log message we write
(unless debugging is enabled) is "Operation finished.". This is
not very helpful when trying to figure out what is going on, so
add what operation we are talking about to the message:
"Operation 'sleep' finished.".

Hat tip to Daniel Aleksandersen for pointing this out.
2015-10-14 22:25:58 +02:00
Zbigniew Jędrzejewski-Szmek f868cb58c1 logind: avoid a dot before parenthesis
systemd-logind[27]: System is rebooting. (Applied kernel updates.)

is changed to

systemd-logind[27]: System is rebooting (Applied kernel updates).

Users should not add a dot in the sentence in --message, i.e. the correct usage is now:
$ systemctl reboot --message "Applied kernel updates"
2015-09-30 12:20:01 -04:00
Daniel Mack 1389f4b958 logind: allow dry run variants for scheduled shutdowns
Allow passing a "dry-" prefix to the action parameter passed to
.ScheduleShutdown(). When strings with this prefix are passed,
the scheduled action will not take place. Instead, an info message
is logged.
2015-09-09 17:52:11 +02:00
Lennart Poettering a1e58e8ee1 tree-wide: use coccinelle to patch a lot of code to use mfree()
This replaces this:

        free(p);
        p = NULL;

by this:

        p = mfree(p);

Change generated using coccinelle. Semantic patch is added to the
sources.
2015-09-09 08:19:27 +02:00
Tom Gundersen 6167a91c74 Merge pull request #1165 from poettering/nspawn-files
various fixes to the core, logind, machined, nspawn
2015-09-07 02:59:08 +02:00
Lennart Poettering 91b3e7fb6c logind: make scope of wall message handling smaller 2015-09-05 20:27:52 +02:00
Michael Chapman 403ed0e5c9 bus-util: support details in CheckAuthorization calls
Extra details for an action can be supplied when calling polkit's
CheckAuthorization method. Details are a list of key/value string pairs.
Custom policy can use these details when making authorization decisions.
2015-09-06 00:07:16 +10:00
David Herrmann 3d1c455f9a login: fix NULL-deref on wall_message
We treat an empty wall-message equal to a NULL wall-message since:

        commit 5744f59a3e
        Author: Lennart Poettering <lennart@poettering.net>
        Date:   Fri Sep 4 10:34:47 2015 +0200

            logind: treat an empty wall message like a NULL one

Fix the shutdown scheduler to not deref a NULL pointer, but properly
check for an empty wall-message.

Fixes: #1120
2015-09-05 12:56:04 +02:00
Lennart Poettering 2cf088b56d logind: when parsing a boolean via sd-bus the type must be "int"
And not bool.
2015-09-04 10:36:08 +02:00
Lennart Poettering 5744f59a3e logind: treat an empty wall message like a NULL one 2015-09-04 10:34:47 +02:00
Jan Synacek 9ef15026c0 logind/systemctl: introduce SetWallMessage and --message
Enable unprivileged users to set wall message on a shutdown
operation. When the message is set via the --message option,
it is logged together with the default shutdown message.

$ systemctl reboot --message "Applied kernel updates."

$ journalctl -b -1
...
systemd-logind[27]: System is rebooting. (Applied kernel updates.)
...
2015-08-25 13:52:44 +02:00
Lennart Poettering 491ac9f2c4 logind,machined: various smaller cleanups
Use mfree() where we can.

Drop unnecessary {}.

Drop unnecessary variable declarations.

Cast syscall invocations where explicitly don't care for the return
value to (void).

Reword a comment.
2015-08-06 16:54:00 +03:00
Lennart Poettering 65d73cf042 machined,logind: don't generate errors on signal match functions
If we get a weird signal, then we should log about it, but not return an
error, since sd-bus will not call us again then anymore, but for these
signals we match here we actually do want to be called on the next
invocation.
2015-08-06 16:54:00 +03:00
Daniel Mack 3cde9e8fa0 logind: switch to sd_bus_track helper
Let logind use the sd_bus_track helper object to track the controllers of
sessions. This does not only remove quite some code but also kills the
unconditional matches for all NameOwnerChanged signals.

The latter is something we should never ever do, as it wakes up the daemon
every time a client connects, which doesn't scale.
2015-08-05 17:06:45 +02:00
David Herrmann 97b11eedff tree-wide: introduce mfree()
Pretty trivial helper which wraps free() but returns NULL, so we can
simplify this:
        free(foobar);
        foobar = NULL;
to this:
        foobar = mfree(foobar);
2015-07-31 19:56:38 +02:00
Lennart Poettering dacd6cee76 tree-wide: port everything over to fflush_and_check()
Some places invoked fflush() directly with their own manual error
checking, let's unify all that by using fflush_and_check().

This also unifies the general error paths of fflush()+rename() file
writers.
2015-07-29 20:31:07 +02:00
Daniel Mack 6f566391a4 logind: fix write_string_file() fallout
WRITE_STRING_FILE_ATOMIC is only valid if WRITE_STRING_FILE_CREATE is also
given. IOW, an atomic file write operation is only possible when creating a
file is also being asked for.

This is a regression from the recent write_string_file() rework.
2015-07-21 15:58:59 +02:00
Lennart Poettering 559b5cc273 logind: bring bus policy up-to-date
A while back we opened up all of logind's bus calls to unprivileged
users, via PK. However, the dbus1 policy wasn't updated accordingly.

With this change, the dbus1 policy is opened up for all bus calls that
should be available to unprivileged clients.

(also rearranges some calls in the vtable, to make more sense, and be in
line with the order in the bus policy file)

Fixes #471.
2015-07-11 17:03:42 -03:00
David Herrmann cc85d56245 logind: allow greeters to take over VTs
Make sure a greeter can forcefully spawn a session on a VT that is
in-use. A recent patch prevented this (this used to be possible for all
session types) as it is highly fragile. However, as it turns out,
greeters seem to rely on that feature. Therefore, make sure we allow it
explicitly for greeters.
2015-07-10 15:25:43 +02:00
Lennart Poettering 1434eb3838 Merge pull request #500 from zonque/fileio
fileio: consolidate write_string_file*()
2015-07-08 17:13:53 -03:00
David Herrmann b80120c4cb logind: fail on CreateSession if already in session
Right now, if you're already in a session and call CreateSession, we
return information about the current session of yours. This is highy
confusing and a nasty hack. Avoid that, and instead return a commonly
known error, so the caller can detect that.

This has the side-effect, that we no longer override XDG_VTNR and XDG_SEAT
in pam_systemd, if you're already in a session. But this sounds like the
right thing to do, anyway.
2015-07-07 19:38:41 +02:00
David Herrmann 586cd08e1b logind: allow sessions to share a VT if it's a greeter
Old gdm and lightdm start the user-session during login before they
destroy the greeter-session. Therefore, the user-session will take over
the VT from the greeter. We recently prevented this by never allowing
multiple sessions on the same VT. Fix this now, by explicitly allowing
this if the owning session is a GREETER.

Note that gdm no longer behaves like this. Instead, due to wayland, they
always use a different VT for each session. All other login-managers are
highly encouraged to destroy the greeter-session _before_ starting the
user-session. We now work around this, but this will probably not last
forever (and will already have nasty side-effects on the greeter-session).
2015-07-07 19:13:52 +02:00
Daniel Mack 4c1fc3e404 fileio: consolidate write_string_file*()
Merge write_string_file(), write_string_file_no_create() and
write_string_file_atomic() into write_string_file() and provide a flags mask
that allows combinations of atomic writing, newline appending and automatic
file creation. Change all users accordingly.
2015-07-06 19:19:25 -04:00