summaryrefslogtreecommitdiff
path: root/src/basic/socket-util.c
Commit message (Collapse)AuthorAge
* Prep v239.2: Fix migration errors in basicSven Eden2018-11-08
|
* socket-util: add new sockaddr_un_unlink() helperLennart Poettering2018-10-29
| | | | | | | | | | | The helper is supposed to properly handle cases where .sun_path does not contain a NUL byte, and thus copies out the path suffix a NUL as necessary. This also reworks the more specific socket_address_unlink() to be a wrapper around the more generic sockaddr_un_unlink() (cherry picked from commit 9f20fc28f0a624ea49ac941bcde57b5435a01b6e)
* socket-util: attempt SO_RCVBUFFORCE/SO_SNDBUFFORCE only if ↵Franck Bui2018-10-29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | SO_RCVBUF/SO_SNDBUF fails Both SO_SNDBUFFORCE and SO_RCVBUFFORCE requires capability 'net_admin'. If this capability is not granted to the service the first attempt to increase the recv/snd buffers (via sd_notify()) with SO_RCVBUFFORCE/SO_SNDBUFFORCE will fail, even if the requested size is lower than the limit enforced by the kernel. If apparmor is used, the DENIED logs for net_admin will show up. These log entries are seen as red warning light, because they could indicate that a program has been hacked and tries to compromise the system. It would be nicer if they can be avoided without giving services (relying on sd_notify) net_admin capability or dropping DENIED logs for all such services via their apparmor profile. I'm not sure if sd_notify really needs to forcibly increase the buffer sizes, but at least if the requested size is below the kernel limit, the capability (hence the log entries) should be avoided. Hence let's first ask politely for increasing the buffers and only if it fails then ignore the kernel limit if we have sufficient privileges. (cherry picked from commit 10ce2e0681ac16e7bb3619b7bb1a72a6f98a2f2c)
* util: do not use stack frame for parsing arbitrary inputsYu Watanabe2018-10-29
| | | | | | | | | | This replaces strndupa() by strndup() in socket_address_parse(), as input string may be too long. Fixes issue 10007 by ClusterFuzz-External: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=10007 (cherry picked from commit 8d30fcb9b51b1d102a589171b6e28f5f370236f6)
* tree-wide: drop MSG_NOSIGNAL flag from recvmsg() invocationsLennart Poettering2018-08-24
| | | | | | | | MSG_NOSIGNAL is only defined for sendmsg(), not for recvmsg(), hence let's drop it's use, in particular as it appears to create problems on older kernels. See: https://lists.freedesktop.org/archives/systemd-devel/2018-June/040869.html
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-08-24
| | | | | | | | | | | 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.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | 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.
* socket-util: rename parse_socket_address_bind_ipv6_only_or_bool() to ↵Yu Watanabe2018-08-24
| | | | | | | socket_address_bind_ipv6_only_or_bool_from_string() Hence, we can define config_parse_socket_bind() by using DEFINE_CONFIG_PARSE_ENUM() macro.
* tree-wide: drop spurious newlines (#8764)Lennart Poettering2018-08-24
| | | | | | | | | Double newlines (i.e. one empty lines) are great to structure code. But let's avoid triple newlines (i.e. two empty lines), quadruple newlines, quintuple newlines, …, that's just spurious whitespace. It's an easy way to drop 121 lines of code, and keeps the coding style of our sources a bit tigther.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | 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.
* tree-wide: use TAKE_PTR() and TAKE_FD() macrosYu Watanabe2018-08-24
|
* macro: introduce TAKE_PTR() macroLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* Prep v238: Remove getnameinfo_pretty(), it is no longer used.Sven Eden2018-06-29
|
* Prep v238: Uncomment now needed headers and unmask now needed functions in ↵Sven Eden2018-06-05
| | | | src/basic (1/6)
* Prep v238: Applied some upstream updates to src/basic (3/5)Sven Eden2018-06-04
|
* socket-util: drop getnameinfo_pretty()Yu Watanabe2018-05-30
|
* basic/socket-util: drop use of NI_IDN_USE_STD3_ASCII_RULESZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | | The only use of socknameinfo_pretty() is in src/journal-remote/journal-remote.c, to determine the output filename. Replaces #8120.
* socket-util: fix getpeergroups() assert(fd) (#8080)Vito Caputo2018-05-30
| | | | | | | | Don't assert on zero-value fds. Fixes #8075. (cherry picked from commit 75f40779607ea79f20441c7fb46744d04ee2c7ae)
* log: minimize includes in log.hLennart Poettering2018-05-30
| | | | | | | | | | | | | | | | | | | | | | | | | | log.h really should only include the bare minimum of other headers, as it is really pulled into pretty much everything else and already in itself one of the most basic pieces of code we have. Let's hence drop inclusion of: 1. sd-id128.h because it's entirely unneeded in current log.h 2. errno.h, dito. 3. sys/signalfd.h which we can replace by a simple struct forward declaration 4. process-util.h which was needed for getpid_cached() which we now hide in a funciton log_emergency_level() instead, which nicely abstracts the details away. 5. sys/socket.h which was needed for struct iovec, but a simple struct forward declaration suffices for that too. Ultimately this actually makes our source tree larger (since users of the functionality above must now include it themselves, log.h won't do that for them), but I think it helps to untangle our web of includes a tiny bit. (Background: I'd like to isolate the generic bits of src/basic/ enough so that we can do a git submodule import into casync for it)
* socket-util: use parse_ip_port() for parsing IP portsLennart Poettering2018-05-30
| | | | | Let's unify some code here, and also use parse_ip_port() for all our IP port parsing needs in socket_address_parse().
* socket-util: slight rework of getpeersec()Lennart Poettering2018-05-30
| | | | | | | | | | Let's call getsockopt() in a loop, so that we can deal correctly with the label changing while we are trying to read it. (also, while we are at it, let's make sure that there's always one trailing NUL byte at the end of the buffer, after all SO_PEERSEC has zero documentation, and multiple implementing backends, hence let's better be safe than sorry)
* tree-wide: use {pid,uid,gid}_is_valid() where appropriateLennart Poettering2018-05-30
| | | | | | Also, drop UID/GID validity checks from getpeercred() as the kernel will never pass us invalid UID/GID on userns, but the overflow UID/GID instead. Add a comment about this.
* socket-util: add new getpeergroups() callLennart Poettering2018-05-30
| | | | | It's a wrapper around the new SO_PEERGROUPS sockopt, similar in style as getpeersec() and getpeercred().
* socket-util: introduce parse_socket_address_bind_ipv6_only_or_bool()Yu Watanabe2018-05-30
|
* socket-util: clarify why sockaddr_port returns unsigned rather than uint16_tLennart Poettering2018-05-30
|
* socket-util: add socket_address_type_{from,to}_string()Yu Watanabe2018-05-30
|
* Prep v236 : Add missing SPDX-License-Identifier (2/9) src/basicSven Eden2018-03-26
|
* Apply missing updates from upstreamSven Eden2017-12-08
|
* tree-wide: use IN_SET macro (#6977)Yu Watanabe2017-12-08
|
* Apply updates from upstreamSven Eden2017-12-07
|
* build-sys: use #if Y instead of #ifdef Y everywhereZbigniew Jędrzejewski-Szmek2017-11-23
| | | | | | | | | | | | | | | The advantage is that is the name is mispellt, cpp will warn us. $ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/" $ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;' $ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g' $ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g' + manual changes to meson.build squash! build-sys: use #if Y instead of #ifdef Y everywhere v2: - fix incorrect setting of HAVE_LIBIDN2
* tree-wide: use `!IN_SET(..)` for `a != b && a != c && …`Andreas Rammhold2017-09-29
| | | | | | The included cocci was used to generate the changes. Thanks to @flo-wer for pointing this case out.
* tree-wide: use IN_SET where possibleAndreas Rammhold2017-09-29
| | | | | In addition to the changes from #6933 this handles cases that could be matched with the included cocci file.
* Support 'rdma' as a ListenNetlink= argument (#6626)Jason Gunthorpe2017-08-29
| | | | NETLINK_RDMA has been in the kernel since v3.0.
* basic/path-util: allow flags for path_equal_or_files_sameZbigniew Jędrzejewski-Szmek2017-07-25
| | | | | No functional change, just a new parameters and the tests that AT_SYMLINK_NOFOLLOW works as expected.
* Make IDN support conditionalWaldemar Brodkorb2017-07-25
| | | | [zj: rename HAVE_IDN to ENABLE_IDN]
* Prep v233.2: Mask unneeded functions and definitions in src/basicSven Eden2017-07-18
|
* socket-util: introduce address_label_validSusant Sahani2017-07-17
|
* fs-util: unify code we use to check if dirent's d_name is "." or ".."Lennart Poettering2017-07-17
| | | | | We use different idioms at different places. Let's replace this is the one true new idiom, that is even a bit faster...
* socket-utils: revert f1811313f42dc7ddaed3c47edc834c2bfd1309b2Susant Sahani2017-07-17
| | | | ':' in not a a valid interface name.
* network: accept colons in network interface names, normally used for alias ↵peoronoob2017-07-17
| | | | interfaces (#5117)
* socket-util: add AF_VSOCK address familyStefan Hajnoczi2017-07-17
| | | | | | | | The AF_VSOCK address family facilitates guest<->host communication on VMware and KVM (virtio-vsock). Adding support to elogind allows guest agents to be launched through .socket unit files. Today guest agents are stand-alone daemons running inside guests that do not take advantage of elogind socket activation.
* socket-util: introduce port argument in sockaddr_port()Stefan Hajnoczi2017-07-17
| | | | | | | | sockaddr_port() either returns a >= 0 port number or a negative errno. This works for AF_INET and AF_INET6 because port ranges are only 16-bit. In AF_VSOCK ports are 32-bit so an int cannot represent all port number and negative errnos. Separate the port and the return code.
* Rename formats-util.h to format-util.hZbigniew Jędrzejewski-Szmek2017-07-17
| | | | | | 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.
* Prep v232.2: Mask more unneeded functionsSven Eden2017-07-07
|
* sd-device/networkd: unify code to get a socket for issuing netdev ioctls onLennart Poettering2017-07-05
| | | | | | | | | | | As suggested here: https://github.com/elogind/elogind/pull/4296#issuecomment-251911349 Let's try AF_INET first as socket, but let's fall back to AF_NETLINK, so that we can use a protocol-independent socket here if possible. This has the benefit that our code will still work even if AF_INET/AF_INET6 is made unavailable (for exmple via seccomp), at least on current kernels.
* basic: fix for IPv6 status (#4224)Susant Sahani2017-07-05
| | | | | | | | | | | | | | | | | | | | | | Even if ``` cat /proc/sys/net/ipv6/conf/all/disable_ipv6 1 ``` is disabled cat /proc/net/sockstat6 ``` TCP6: inuse 2 UDP6: inuse 1 UDPLITE6: inuse 0 RAW6: inuse 0 FRAG6: inuse 0 memory 0 ``` Looking for /proc/net/if_inet6 is the right choice.
* core: add a concept of "dynamic" user ids, that are allocated as long as a ↵Lennart Poettering2017-07-05
| | | | | | | | | | | | | | | | | | | service is running This adds a new boolean setting DynamicUser= to service files. If set, a new user will be allocated dynamically when the unit is started, and released when it is stopped. The user ID is allocated from the range 61184..65519. The user will not be added to /etc/passwd (but an NSS module to be added later should make it show up in getent passwd). For now, care should be taken that the service writes no files to disk, since this might result in files owned by UIDs that might get assigned dynamically to a different service later on. Later patches will tighten sandboxing in order to ensure that this cannot happen, except for a few selected directories. A simple way to test this is: elogind-run -p DynamicUser=1 /bin/sleep 99999
* socket-util: Run the fallback when the kernel complains about the null ↵Kai Ruhnau2017-06-16
| | | | | | | | | | | buffer (#3541) Calling recv with a NULL buffer returns EFAULT instead of EOPNOTSUPP on older kernels (3.14). Fixes #3407 Signed-off-by: Kai Ruhnau <kai.ruhnau@target-sg.com>
* tree-wide: htonl() is weird, let's use htobe32() instead (#3538)Lennart Poettering2017-06-16
| | | | Super-important change, yeah!