summaryrefslogtreecommitdiff
path: root/src/basic/hostname-util.c
Commit message (Collapse)AuthorAgeFilesLines
* string-util: add new strdupcspn()/strdupspn()Lennart Poettering2023-01-201-1/+1
| | | | | | | | These combine strndup() + strspn()/strcspn() into one. There are a bunch of strndupa() calls that could use similar treatment (or should be converted to strdup[c]spn(), but this commit doesn't bother with that.
* tree-wide: add global ascii_isdigit() + ascii_isalpha()Lennart Poettering2022-07-051-4/+2
| | | | | | | | We now have a local implementation in string-util-fundamental.c, but it's useful at a lot of other places, hence let's give it a more expressive name and share it across the tree. Follow-up for: 8d9156660d6958c8d63b1d44692968f1b5d33920
* hostname-util: normalize get_pretty_hostname() call semanticsLennart Poettering2022-03-101-0/+18
| | | | | | | | | | | | | | 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-311-2/+1
| | | | | | 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: introduce gethostname_full() and use it in various gethostname() ↵Yu Watanabe2021-08-121-47/+20
| | | | variants
* Use the DEFAULT_HOSTNAME field from os-releaseZbigniew Jędrzejewski-Szmek2021-02-221-0/+12
| | | | | | | | | | | | | | | This provides a fairly comprehensible fix for https://bugzilla.redhat.com/show_bug.cgi?id=1893417. This adds yet-another level of configuration: - /etc/hostname - transient hostname - $SYSTEMD_DEFAULT_HOSTNAME - DEFAULT_HOSTNAME is os-release - -Dfallback-hostname= - "linux" It's a lot of layers, but each has it's own justification.
* Allow the fallback hostname to be overriden using an environment variableZbigniew Jędrzejewski-Szmek2021-02-221-2/+19
| | | | | | | | | | | | | | 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-120/+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-22/+17
| | | | | | | | | | | | 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.
* hostname-util: explain what 'LDH' isLennart Poettering2020-12-151-0/+2
|
* Drop compat "gateway" nameZbigniew Jędrzejewski-Szmek2020-12-101-14/+0
| | | | | | | 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-3/+22
| | | | | | | | | 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.
* basic: add STRCASE_IN_SET() which is to STR_IN_SET() what strcaseeq() is to ↵Lennart Poettering2020-05-041-8/+11
| | | | streq()
* tree-wide: use "hostname" spelling everywhereZbigniew Jędrzejewski-Szmek2020-04-211-2/+2
| | | | | | | | It's not that I think that "hostname" is vastly superior to "host name". Quite the opposite — the difference is small, and in some context the two-word version does fit better. But in the tree, there are ~200 occurrences of the first, and >1600 of the other, and consistent spelling is more important than any particular spelling choice.
* tree-wide: drop string.h when string-util.h or friends are includedYu Watanabe2019-11-041-1/+0
|
* basic/hostname-util: do truncation last when cleaning upZbigniew Jędrzejewski-Szmek2018-12-101-3/+1
| | | | | This allows more of the original name to be used if there are invalid chars in the beginning.
* Partially unify hostname_is_valid() and dns_name_is_valid()Zbigniew Jędrzejewski-Szmek2018-12-101-16/+38
| | | | | This makes hostname_is_valid() apply the ldh checks too, rejecting more hostnames.
* Move LONG_LINE_MAX definition to fileio.hZbigniew Jędrzejewski-Szmek2018-11-141-1/+0
| | | | | | | | | | | All users of the macro (except for one, in serialize.c), use the macro in connection with read_line(), so they must include fileio.h. Let's not play libc games and require multiple header file to be included for the most common use of a function. The removal of def.h includes is not exact. I mostly went over the commits that switch over to use read_line() and add def.h at the same time and reverted the addition of def.h in those files.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-3/+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.
* networkd/dhcp: shorten overlong hostname (#7616)Luca Bruno2017-12-131-0/+32
| | | | | | 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-23/+45
| | | | | | | | | | | | | | | | | 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.
* tree-wide: use IN_SET macro (#6977)Yu Watanabe2017-10-041-4/+2
|
* resolved,nss-myhostname: use _gateway for the gatewayZbigniew Jędrzejewski-Szmek2017-07-311-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | This changes the symbolic name for the default gateway from "gateway" to "_gateway". A new configuration option -Dcompat-gateway-hostname=true|false is added. If it is set, the old name is also supported, but the new name is used as the canonical name in either case. This is intended as a temporary measure to make the transition easier, and the option should be removed after a few releases, at which point only the new name will be used. The old "gateway" name mostly works OK, but hasn't gained widespread acceptance because of the following (potential) conflicts: - it is completely legal to have a host called "gateway" - there is no guarantee that "gateway" will not be registered as a TLD, even though this currently seems unlikely. (Even then, there would be no conflict except for the case when the top-level domain itself was being resolved. The "gateway" or "_gateway" labels have only special meaning when the whole name consists of a single label, so resolution of any subdomain of the hypothetical gateway. TLD would still work OK. ) Moving to "_gateway" avoids those issues because underscores are not allowed in host names (RFC 1123, §2.1) and avoids potential conflicts with local or global names. v2: - simplify the logic to hardcode "_gateway" and allow -Dcompat-gateway-hostname=true as a temporary measure.
* hostname-util: default to the compile time default hostname in ↵Lennart Poettering2017-02-171-1/+1
| | | | | | | | | gethostname_malloc() Currently, if the hostname is not set gethostname_malloc() defaults to the "sysname", which is "linux" on Linux. Let's change that to also honour the compile-time fallback hostname as specified on the configure command line.
* hostnamectl: rework pretty hostname validation (#3985)Lennart Poettering2016-08-181-1/+0
| | | | | | | | | | Rework 17eb9a9ddba3f03fcba33445c1c1eedeb948da04 a bit. Let's make sure we don't clobber the input parameter args[1], following our coding style to not clobber parameters unless explicitly indicated. (in particular, as we don't want to have our changes appear in the command line shown in "ps"...) No functional change.
* Merge pull request #2959 from keszybz/stop-resolving-localdomainZbigniew Jędrzejewski-Szmek2016-04-041-5/+5
|\ | | | | *.localdomain != localhost
| * *.localdomain != localhostDavid R. Hedges2016-04-041-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ".localdomain" is not a reserved suffix (or prefix). I'm not aware of any product expecting *.localdomain to resolve to localhost, however I am aware of at least one product that defaults to ".localdomain" as its DNS suffix provided via DHCP (pfSense). This leads to unexpected results when attempting to access a host that's offline (or a host that's online, when nsswitch.conf is [mis-]configured to have myhostname ahead of DNS). Operate on: localhost (and localhost.) *.localhost (and *.localhost.) localhost.localdomain (and localhost.localdomain.) *.localhost.localdomain (and *.localhost.localdomain.) We should not cover: *.localdomain (nor *.localdomain.) localdomain (nor localdomain.)
* | shorten hostname before checking for trailing dotThomas Blume2016-02-291-2/+2
| | | | | | | | | | Shortening can lead to a hostname that has a trailing dot. Therefore it should be done before checking from trailing dots.
* | Merge pull request #2717 from keszybz/networkctl-prettificationLennart Poettering2016-02-231-2/+3
|\ \ | | | | | | Networkctl prettification
| * | Fix two typosZbigniew Jędrzejewski-Szmek2016-02-231-2/+3
| | |
* | | tree-wide: make ++/-- usage consistent WRT spacingVito Caputo2016-02-221-1/+1
|/ / | | | | | | | | | | 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.
* | networkd: add basic LLDP transmission supportLennart Poettering2016-02-211-0/+28
| | | | | | | | | | | | 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.
* | Remove/add (un)needed includesNathan McSween2016-02-181-1/+0
|/
* 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.
* basic: include only what we useThomas Hindoe Paaboel Andersen2015-11-301-2/+7
| | | | | This is a cleaned up result of running iwyu but without forward declarations on src/basic.
* hostname-util: fix code commentBeniamino Galvani2015-11-171-1/+1
|
* util-lib: move more file I/O related calls into fileio.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: split out fd-related operations into fd-util.[ch]Lennart Poettering2015-10-251-1/+2
| | | | | There are more than enough to deserve their own .c file, hence move them over.
* util-lib: split our string related calls from util.[ch] into its own file ↵Lennart Poettering2015-10-241-1/+2
| | | | | | | | | | | | | | 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.
* util: make hostname_is_valid() easier to readLennart Poettering2015-08-241-7/+12
| | | | | 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/+11
| | | | | | | | | 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: ignore case when checking if hostname is localhostZbigniew Jędrzejewski-Szmek2015-08-051-8/+8
|
* hostname-util: get rid of unused parameter of hostname_cleanup()Zbigniew Jędrzejewski-Szmek2015-08-051-3/+3
| | | | All users are now setting lowercase=false.
* hostname-util: add relax parameter to hostname_is_validZbigniew Jędrzejewski-Szmek2015-08-051-3/+12
| | | | | | | | | | 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/+193
basic/ can be used by everything cannot use anything outside of basic/ libsystemd/ can use basic/ cannot use shared/ shared/ can use libsystemd/