Commit Graph

51 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek e5d5edc3ff nss-mymachines: initialize logging
No logging is done directly by nss-mymachines.c code, but we call into sd-bus,
which will log.
2020-12-10 20:52:03 +01:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Lennart Poettering 38ccb55731 nss-mymachines: drop support for UID/GID resolving
Now that we make the user/group name resolving available via userdb and
thus nss-systemd, we do not need the UID/GID resolving support in
nss-mymachines anymore. Let's drop it hence.

We keep the module around, since besides UID/GID resolving it also does
hostname resolving, which we care about. (One of those days we should
replace that by some Varlink logic between
nss-resolve/systemd-resolved.service too)

The hooks are kept in the NSS module, but they do not resolve anything
anymore, in order to keep compat at a maximum.
2020-07-14 17:08:12 +02:00
Lennart Poettering 9b71e4ab90 shared: actually move all BusLocator related calls to bus-locator.c 2020-06-30 15:09:19 +02:00
Vito Caputo 7b38987880 nss-mymachines: switch to BusLocator-oriented helpers
Mechanical substitution reducing some verbosity
2020-05-07 08:46:44 -07:00
Michael Biebl 6db904625d meson: make nologin path build time configurable
Some distros install nologin as /usr/sbin/nologin, others as
/sbin/nologin.
Since we can't really on merged-usr everywhere (where the path wouldn't
matter), make the path build time configurable via -Dnologin-path=.

Closes #13028
2019-07-18 12:46:35 +02:00
Lennart Poettering 2b0c1bfd8d nss-mymachines: return NO_RECOVERY instead of NO_DATA when we fail to do D-Bus and similar
This makes more semantical sense and is what we do in nss-resolve in a
similar case, hence let's remove the differences here.
2019-04-11 11:13:10 +02:00
Zbigniew Jędrzejewski-Szmek ca78ad1de9 headers: remove unneeded includes from util.h
This means we need to include many more headers in various files that simply
included util.h before, but it seems cleaner to do it this way.
2019-03-27 11:53:12 +01:00
Lennart Poettering 2b2fec7db0 util: split out errno related stuff 2019-03-14 13:25:51 +01:00
Lennart Poettering 0a9707187b util: split out memcmp()/memset() related calls into memory-util.[ch]
Just some source rearranging.
2019-03-13 12:16:43 +01:00
Lennart Poettering cdccd29f39 nss: unportect errno before writing to NSS' *errnop
Fixes: #11321
2019-02-08 10:34:47 +01:00
Zbigniew Jędrzejewski-Szmek 0192cbdb2c Revert "nss: prevent PROTECT_ERRNO from squashing changes to *errnop"
This reverts commit b26c904113.

I don't see anythign wrong, but Ubuntu autopkgtest CI started failing fairly
consistently since this was merged. Let's see if reverting fixes things.
2019-01-10 21:23:14 +01:00
Sam Morris b26c904113 nss: prevent PROTECT_ERRNO from squashing changes to *errnop
glibc passes in &errno for errnop, which means PROTECT_ERRNO ends up
squashing our intentional changes to *errnop.

Fixes #11321.
2019-01-10 11:08:42 +01:00
Zbigniew Jędrzejewski-Szmek 54fe2ce1b9
Merge pull request #9504 from poettering/nss-deadlock
some nss deadlock love
2018-07-26 10:16:25 +02:00
Yu Watanabe 06202b9e65 nss: do not modify errno when NSS_STATUS_NOTFOUND or NSS_STATUS_SUCCESS
This also adds PROTECT_ERRNO for all nss module functions.

C.f. glibc NSS documents https://www.gnu.org/software/libc/manual/html_node/NSS-Modules-Interface.html
and discussion in https://sourceware.org/bugzilla/show_bug.cgi?id=23410.

Fixes #9585.
2018-07-25 10:23:22 +02:00
Lennart Poettering 2f28018cb8 nss: never become IPC clients for services that are about to be started
This is an attempt to automatically detect and avoid certain kinds of
NSS deadlocks as discussed in this thread:

https://lists.freedesktop.org/archives/systemd-devel/2018-July/040975.html
2018-07-20 16:57:35 +02:00
Yu Watanabe 31d99bd172 tree-wide: do not assign values if not used 2018-06-19 08:44:55 +02:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Ivan Shapovalov ee73a176a2 mymachines: fix getgrnam()
getgrnam() was returning input gid instead of the mapped one. Fix that.
2018-06-08 17:52:18 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Yu Watanabe 3e75a1bb43 nss-mymachines: add work-around to silence gcc warning
This is similar to 3c3d384ae9 and
a workaround for the following warning.
```
In file included from ../src/basic/in-addr-util.h:28,
                 from ../src/nss-mymachines/nss-mymachines.c:31:
../src/nss-mymachines/nss-mymachines.c: In function '_nss_mymachines_getgrnam_r':
../src/nss-mymachines/nss-mymachines.c:653:32: warning: argument to 'sizeof' in 'memset' call is the same pointer type 'char *' as the destination; expected 'char' or an explicit length [-Wsizeof-pointer-memaccess]
         memzero(buffer, sizeof(char*));
                                ^~~~
../src/basic/util.h:118:39: note: in definition of macro 'memzero'
 #define memzero(x,l) (memset((x), 0, (l)))
                                       ^
../src/nss-mymachines/nss-mymachines.c: In function '_nss_mymachines_getgrgid_r':
../src/nss-mymachines/nss-mymachines.c:730:32: warning: argument to 'sizeof' in 'memset' call is the same pointer type 'char *' as the destination; expected 'char' or an explicit length [-Wsizeof-pointer-memaccess]
         memzero(buffer, sizeof(char*));
                                ^~~~
../src/basic/util.h:118:39: note: in definition of macro 'memzero'
 #define memzero(x,l) (memset((x), 0, (l)))
                                       ^
```
2018-02-06 17:08:42 +09:00
Lennart Poettering 3a664727fa user-util: add UID_NOBODY defines that resolve to (uid_t) 65534
We use it all over the place, let's add a #define for it. Makes things
easier greppable, and more explanatory I think.
2017-12-06 13:40:50 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Zbigniew Jędrzejewski-Szmek 71e0acccfd nss: use secure_getenv for behaviour-modifying booleans (#6817)
Follow up for fe102d6ab1.
2017-09-14 09:20:27 +02:00
Lennart Poettering cda458a54a nss: fix error to ERANGE for nss calls with too little buffer space (#5365)
This is a follow-up for #5359, fixing the error codes in a similar way
for the other NSS modules.

(user/group lookup calls don't have h_errnop, hence we don't update that
in those cases)
2017-02-16 21:29:09 +01:00
Lennart Poettering d6c575e303 nss: when we encounter an invalid user/group name or UID/GID, don't return EINVAL
It's not our business to validate invalid user/group names or UID/GID.
Ideally, libc would filter these out, but they don't, hence we have to
filter, but let's not propagate this as error, but simply as "not found"
to the caller.

User name rules are pretty vaguely defined, and the rules defined by
POSIX clash with reality quite heavily (for example, utmp doesn't offer
enough room for user name length, and /usr/bin/chown permits separating
user/group names by a single dot, even though POSIX allows dots being
used in user/group names themselves.) We enforce stricter rules than
POSIX for good reason, and hence in doing so we should not categorically
return EINVAL on stuff we don't consider valid, but other components
might.

Fixes: #4983
2016-12-27 18:09:58 +01:00
Lennart Poettering 6e32c03ed8 nss-mymachines: avoid connecting to dbus from inside dbus-daemon
Inspired from the new logic in nss-systemd let's make sure we don't end up
deadlocking in nss-mymachines either in case dbus-daemon tries to a look up a
name and we want to connect to the bus.

This case is much simpler though, as there's no point in resolving virtual
machine UIDs by dbus-daemon as those should never be able to connect to the
host's busses.
2016-08-19 00:52:00 +02:00
Vito Caputo 313cefa1d9 tree-wide: make ++/-- usage consistent WRT spacing
Throughout the tree there's spurious use of spaces separating ++ and --
operators from their respective operands.  Make ++ and -- operator
consistent with the majority of existing uses; discard the spaces.
2016-02-22 20:32:04 -08:00
Lennart Poettering cf3bdcfeba nss-mymachines: never resolve unmapped UIDs/GIDs
Don't ever permit successful user or group lookups if no UID/GID mapping is
actually applied. THis way, we can be sure that nss-mymachines cannot be used
to insert invalid cache entries into nscd's cache.

https://bugzilla.redhat.com/show_bug.cgi?id=1285339
2016-02-10 23:42:34 +01: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
Lennart Poettering 0c5eb0562a nss: block various signals while running NSS lookups
Let's make sure our poll() calls don't get interrupted where they shouldn't (SIGALRM, ...), but allow them to be
interrupted where they should (SIGINT, ...).

Fixes #1965
2016-01-27 02:22:58 +01:00
Zbigniew Jędrzejewski-Szmek d6ce77dbc2 nss-mymachines: link less
This reduces libraries reported by ldd by liblzma,
liblz4, libgcrypt, libgpg-error, libacl, libidn, libseccomp.
2015-11-27 21:00:44 -05: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
Zbigniew Jędrzejewski-Szmek cb31827d62 nss-mymachines: do not allow overlong machine names
https://github.com/systemd/systemd/issues/2002
2015-11-23 13:59:43 -05:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +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 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Lennart Poettering c077529ba6 util: drop UID_IS_INVALID() in favour of uid_is_valid()
No need to keep both functions, settle on uid_is_valid() for everything.
2015-09-22 16:31:32 +02:00
Lennart Poettering 25300b5a1f util: make machine_name_is_valid() a macro and move it to hostname-util.h
As it turns out machine_name_is_valid() does the exact same thing as
hostname_is_valid() these days, as it just invoked that and checked the
name length was < 64. However, hostname_is_valid() checks the length
against HOST_NAME_MAX anyway (which is 64 on Linux), hence any
additional check is redundant.

We hence replace machine_name_is_valid() by a macro that simply maps it
to hostname_is_valid() but sets the allow_trailing_dot parameter to
false. We also move this this call to hostname-util.h, to the same place
as the hostname_is_valid() declaration.
2015-08-24 22:46:45 +02:00
Lennart Poettering c01ff965b4 nss-mymachines: map userns users of containers to real user names
Given a container "foo", that maps user id $UID to container user, using
user namespaces, this NSS module extenstion will now map the $UID to a
name "vu-foo-$TUID" for the translated UID $UID.

Similar, userns groups are mapped to "vg-foo-$TGID" for translated GIDs
of $GID.

This simple change should make userns users more discoverable. Also,
given that many tools like "adduser" check NSS before allocating a UID,
should lower the chance of UID range conflicts between tools.
2015-07-09 14:46:20 -03:00
Lennart Poettering 03976f7b4a sd-bus: introduce new sd_bus_flush_close_unref() call
sd_bus_flush_close_unref() is a call that simply combines sd_bus_flush()
(which writes all unwritten messages out) + sd_bus_close() (which
terminates the connection, releasing all unread messages) +
sd_bus_unref() (which frees the connection).

The combination of this call is used pretty frequently in systemd tools
right before exiting, and should also be relevant for most external
clients, and is hence useful to cover in a call of its own.

Previously the combination of the three calls was already done in the
_cleanup_bus_close_unref_ macro, but this was only available internally.

Also see #327
2015-07-03 19:49:03 +02:00
Thomas Hindoe Paaboel Andersen 66a16e7e9f nss: remove dead code
c > 0 is already guaranteed from earlier checks.

We go from

ms = ALIGN(l+1) +
        sizeof(char*) +
        (c > 0 ? c : 1) * ALIGN(alen) +
        (c > 0 ? c+1 : 2) * sizeof(char*);

to

ms = ALIGN(l+1) +
        sizeof(char*) +
        c * ALIGN(alen) +
        (c+1) * sizeof(char*);

to

ms = ALIGN(l+1) + c * ALIGN(alen) + (c+2) * sizeof(char*);

Found by coverity. Fixes: CID#1237570 and CID#1237610
2014-09-19 00:15:39 +02:00
Lennart Poettering 3a6fb33c54 machined: fix address API signatures 2014-08-04 19:05:06 +02:00
Lennart Poettering 249968612f bus: always explicitly close bus from main programs
Since b5eca3a205 we don't attempt to GC
busses anymore when unsent messages remain that keep their reference,
when they otherwise are not referenced anymore. This means that if we
explicitly want connections to go away, we need to close them.

With this change we will no do so explicitly wherver we connect to the
bus from a main program (and thus know when the bus connection should go
away), or when we create a private bus connection, that really should go
away after our use.

This fixes connection leaks in the NSS and PAM modules.
2014-08-04 16:25:24 +02:00
Lennart Poettering e70df46b97 nss: always explicitly reset all error variables
glibc appears to be broken if we don't explicitly reset all error
variables, let's work around that.

https://bugzilla.redhat.com/show_bug.cgi?id=1125975
2014-08-01 16:06:39 +02:00
Lennart Poettering 0dd25fb9f0 change type for address family to "int"
Let's settle on a single type for all address family values, even if
UNIX is very inconsitent on the precise type otherwise. Given that
socket() is the primary entrypoint for the sockets API, and that uses
"int", and "int" is relatively simple and generic, we settle on "int"
for this.
2014-07-18 16:10:51 +02:00
Lennart Poettering 9d48598533 shared: rename PROTO_ADDRESS_SIZE() to FAMILY_ADDRESS_SIZE()
We mostly use "family" to refer to AF_INET, AF_INET6, etc, let's use
this terminology here, too
2014-07-18 12:38:32 +02:00
Lennart Poettering 634af5665f sd-login: always use "indices" as plural of "index"
So far both "indexes" and "indices" was used. Let's clean this up, and
stick to indices, since it appears to be used more frequently.
2014-07-17 01:48:40 +02:00
Lennart Poettering 555bd6e95b nss: various minor fixes to nss-myhostname + nss-mymachines 2014-07-16 03:30:40 +02:00