summaryrefslogtreecommitdiffstats
path: root/src/basic/hostname-util.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* resolved: introduce the _localdnsstub and _localdnsproxy special hostnames ↵Lennart Poettering2022-11-251-0/+8
| | | | | | | | | for 127.0.0.54 + 127.0.0.53 Let's give these special IP addresses names. After all name resolution is our job here. Fixes: #23623
* hostname-util: normalize get_pretty_hostname() call semanticsLennart Poettering2022-03-111-4/+1
| | | | | | | | | | | | | | get_pretty_hostname() so far had semantics not in line with our usual ones: the return parameter was actually freed before the return string written into it, because that's what parse_env_file() does. Moreover, when the value was not set it would return NULL but succeed. Let's normalize this, and only fill in the return value if there's something set, and never read from it, like we usually do with return parameter, and in particular those named "ret_xyz". The existing callers don't really care about the differences, but it's nicer to normalize behaviour to minimize surprises.
* hostname-util: drop GET_HOSTNAME_ALLOW_NONE flag and always refuse "(none)"Yu Watanabe2021-12-301-4/+3
| | | | | | The flag is now only used in test-sysctl-util.c, and it should be replaced with uname(), because of the same reason as the previous commit.
* hostname-util: introduce get_pretty_hostname()Yu Watanabe2021-09-271-0/+5
|
* hostname: introduce gethostname_full() and use it in various gethostname() ↵Yu Watanabe2021-08-121-3/+30
| | | | variants
* nss-myhostname: expose the "outbound" IP addresses under the synthetic ↵Lennart Poettering2021-04-231-0/+5
| | | | | | | | | | | "_outbound" hostname I found myself often looking for a quick way to determine "the local IP address", and then being lost in the "ip addr" output to find for the right one to use. This is supposed to help a bit with that. Let's introduce a new special hostname "_outbound" with semantics similar to "_gateway" that resolves to addresses that are the closest I could come up with that maps to "the" local IP address.
* Allow the fallback hostname to be overriden using an environment variableZbigniew Jędrzejewski-Szmek2021-02-221-0/+1
| | | | | | | | | | | | | | See https://bugzilla.redhat.com/show_bug.cgi?id=1893417 for the back story: the fallback hostname matters a lot in certain environments. Right now the only way to configure the fallback hostname is by recompiling systemd, which is obviously problematic in case when the fallback hostname shall differ between different editions of the same distro that share a single compiled rpm. By making this overridable through an envvar, we're providing an escape hatch without making this a top-level api. Later on a way to set this through os-release is added, but I think the approach with the variable is still useful. It it very convenient for testing, or to override settings only in a particular service, etc.
* Move hostname setup logic to new shared/hostname-setup.[ch]Zbigniew Jędrzejewski-Szmek2020-12-161-9/+0
| | | | | | | | | | No functional change, just moving a bunch of things around. Before we needed a rather complicated setup to test hostname_setup(), because the code was in src/core/. When things are moved to src/shared/ we can just test it as any function. The test is still "unsafe" because hostname_setup() may modify the hostname.
* hostname-util: flagsify hostname_is_valid(), drop machine_name_is_valid()Lennart Poettering2020-12-151-3/+7
| | | | | | | | | | | | Let's clean up hostname_is_valid() a bit: let's turn the second boolean argument into a more explanatory flags field, and add a flag that accepts the special name ".host" as valid. This is useful for the container logic, where the special hostname ".host" refers to the "root container", i.e. the host system itself, and can be specified at various places. let's also get rid of machine_name_is_valid(). It was just an alias, which is confusing and even more so now that we have the flags param.
* Drop compat "gateway" nameZbigniew Jędrzejewski-Szmek2020-12-101-1/+6
| | | | | | | Back in 5248e7e1f11aba6859de0b28f0dd3778b22842f2 (July 2017) we moved over to "_gateway", with the old name declared to be temporary measure. Since we're doing a bunch of changes to resolved now, it seems to be a good moment to make this simplification and not add support for the compat name in new code.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* Add %l as specifier for the hostname without any domain componentZbigniew Jędrzejewski-Szmek2020-05-071-0/+1
| | | | | | | | | As described in #15603, it is a fairly common setup to use a fqdn as the configured hostname. But it is often convenient to use just the actual hostname, i.e. until the first dot. This adds support in tmpfiles, sysusers, and unit files for %l which expands to that. Fixes #15603.
* Partially unify hostname_is_valid() and dns_name_is_valid()Zbigniew Jędrzejewski-Szmek2018-12-101-0/+1
| | | | | This makes hostname_is_valid() apply the ldh checks too, rejecting more hostnames.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-4/+0
| | | | | | | | | | | 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-06-141-2/+0
| | | | | | | | | | | | | | | | 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.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | 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.
* log: minimize includes in log.hLennart Poettering2018-01-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* networkd/dhcp: shorten overlong hostname (#7616)Luca Bruno2017-12-131-0/+2
| | | | | | This commit updates networkd behavior to check if the hostname option received via DHCP is too long for Linux limit, and in case shorten it. An overlong hostname will be truncated to the first dot or to `HOST_MAX_LEN`, whatever comes earlier.
* hostname-util: rework read_hostname_config() a bitLennart Poettering2017-11-201-1/+2
| | | | | | | | | | | | | | | | | First of all, let's rename it to read_etc_hostname(), to make clearer what kind of configuration it actually reads: the file format defined in /etc/hostname and nothing else. Secondly: let's port this to use read_line(), i.e. the new way to read lines from a file in a safe, bounded way. Thirdly: let's strip leading/trailing whitespace from what we are reading. Given that we are already pretty lenient what we read (comments and empty lines), let's be permissive regarding whitespace too. Fourthly: let's actually validate the hostname when reading it. So far we tried to make it valid, but that's not always possible (for example, we can't make an empty hostname valid, ever).
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* networkd: add basic LLDP transmission supportLennart Poettering2016-02-211-0/+1
| | | | | | Let's add some minimalistic LLDP sender support. The idea is that this is either on or off, and all fields determined automatically rather than configured explicitly.
* tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
| | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* util: make machine_name_is_valid() a macro and move it to hostname-util.hLennart Poettering2015-08-241-0/+2
| | | | | | | | | | | | | 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.
* util: make hostname_is_valid() easier to readLennart Poettering2015-08-241-1/+1
| | | | | Add more comments, and rename some parameters and variables to be more expressive.
* hostname-util: introduce new is_gateway_hostname() callLennart Poettering2015-08-211-0/+1
| | | | | | | | | This moves is_gateway() from nss-myhostname into the basic APIs, and makes it more like is_localhost(). Also, we rename it to is_gateway_hostname() to make it more expressive. Sharing this function in src/basic/ allows us to reuse the function for routing name requests in resolved (in a later commit).
* hostname-util: get rid of unused parameter of hostname_cleanup()Zbigniew Jędrzejewski-Szmek2015-08-061-1/+1
| | | | All users are now setting lowercase=false.
* hostname-util: add relax parameter to hostname_is_validZbigniew Jędrzejewski-Szmek2015-08-061-1/+1
| | | | | | | | | | Tests are modified to check behaviour with relax and without relax. New tests are added for hostname_cleanup(). Tests are moved a new file (test-hostname-util) because there's now a bunch of them. New parameter is not used anywhere, except in tests, so there should be no observable change.
* build-sys: split internal basic/ library from shared/Kay Sievers2015-06-111-0/+39
basic/ can be used by everything cannot use anything outside of basic/ libsystemd/ can use basic/ cannot use shared/ shared/ can use libsystemd/