summaryrefslogtreecommitdiff
path: root/src/basic/parse-util.c
Commit message (Collapse)AuthorAgeFilesLines
* parse-util: make parse_fd() return -EBADFYu Watanabe2023-05-081-1/+1
| | | | | | | | The previous error code -ERANGE is slightly ambiguous, and use more specific one. This also drops unnecessary error handlings. Follow-up for 754d8b9c330150fdb3767491e24975f7dfe2a203 and e652663a043cb80936bb12ad5c87766fc5150c24.
* fd-util: introduce parse_fd()David Tardon2023-05-051-0/+15
| | | | | It's a simple wrapper for safe_atoi() that returns error if the parsed fd is < 0 .
* parse-util: allow parse_pid() to work with NULL return parameterLennart Poettering2023-04-251-2/+2
| | | | | That way the function becomes useful for validating pids formatted as strings.
* repart: Allow configuring sector sizeDaan De Meyer2023-01-171-0/+20
| | | | | | Let's allow users to configure the (logical) sector size of their image. This is required when building images for a 4k sector size disk on a 512b sector size host or vice-versa.
* parse-util: make safe_atou8() just a wrapper around safe_atou8_full()Lennart Poettering2022-09-051-20/+8
| | | | | As in the previous commit: it's just a wrapper around the same strtoul(), hence let's just share some more code.
* parse-util: make safe_atou16_full() just a wrapper around safe_atou_full()Lennart Poettering2022-09-051-33/+7
| | | | | | Both are fancy wrappers around strtoul() anyway, not more, hence let's just make them a wrapper around each other, too, to simplify things a lot.
* tree-wide: add global ascii_isdigit() + ascii_isalpha()Lennart Poettering2022-07-051-2/+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
* Revert NFTSet featureYu Watanabe2022-06-221-35/+0
| | | | | | | | | | | | | | | | | | | | | | | | This reverts PR #22587 and its follow-up commit. More specifically, 2299b1cae32c1fb8911da0ce26efced68032f4f8 (partially), e176f855278d5098d3fecc5aa24ba702147d42e0, ceb46a31a01b3d3d1d6095d857e29ea214a2776b, and 51bb9076ab8c050bebb64db5035852385accda35. The PR was merged without final approval, and has several issues: - OSS fuzz reported issues in the conf parser, - It calls synchrnous netlink call, it should not be especially in PID1, - The importance of NFTSet for CGroup and DynamicUser may be questionable, at least, there was no justification PID1 should support it. - For networkd, it should be implemented with Request object, - There is no test for the feature. Fixes #23711. Fixes #23717. Fixes #23719. Fixes #23720. Fixes #23721. Fixes #23759.
* network: firewall integration with NFT setsTopi Miettinen2022-06-081-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | New directives `NFTSet=`, `IPv4NFTSet=` and `IPv6NFTSet=` provide a method for integrating configuration of dynamic networks into firewall rules with NFT sets. /etc/systemd/network/eth.network ``` [DHCPv4] ... NFTSet=netdev:filter:eth_ipv4_address ``` ``` table netdev filter { set eth_ipv4_address { type ipv4_addr flags interval } chain eth_ingress { type filter hook ingress device "eth0" priority filter; policy drop; ip saddr != @eth_ipv4_address drop accept } } ``` ``` sudo nft list set netdev filter eth_ipv4_address table netdev filter { set eth_ipv4_address { type ipv4_addr flags interval elements = { 10.0.0.0/24 } } } ```
* basic: split out dev_t related calls into new devno-util.[ch]Lennart Poettering2022-04-131-28/+0
| | | | | | | | | | | | | | No actual code changes, just splitting out of some dev_t handling related calls from stat-util.[ch], they are quite a number already, and deserve their own module now I think. Also, try to settle on the name "devnum" as the name for the concept, instead of "devno" or "dev" or "devid". "devnum" is the name exported in udev APIs, hence probably best to stick to that. (this just renames a few symbols to "devum", local variables are left untouched, to make the patch not too invasive) No actual code changes.
* tree-wide: move `unsigned` to the start of type declarationFrantisek Sumsal2022-02-101-1/+1
| | | | | | | | | | | | | | | | | Even though ISO C11 doesn't mandate in which order the type specifiers should appear, having `unsigned` at the beginning of each type declaration feels more natural and, more importantly, it unbreaks Coccinelle, which has a hard time parsing `long unsigned` and others: ``` init_defs_builtins: /usr/lib64/coccinelle/standard.h init_defs: /home/mrc0mmand/repos/systemd/coccinelle/macros.h HANDLING: src/shared/mount-util.c : 1: strange type1, maybe because of weird order: long unsigned ``` Most of the codebase already "complies", so let's fix the remaining "offenders".
* parse-util: refuse leading white space in port numberYu Watanabe2021-12-021-1/+1
| | | | | | | | When parse_ip_port() is directly used in a conf parser, then that's fine, as the rvalue is already truncated. When parse_ip_port() is used when e.g. parsing IP address with port, then we should really refuse white space after colon.
* alloc-util: add strdupa_safe() + strndupa_safe() and use it everywhereLennart Poettering2021-10-141-2/+2
| | | | | | | | | | | | | Let's define two helpers strdupa_safe() + strndupa_safe() which do the same as their non-safe counterparts, except that they abort if called with allocations larger than ALLOCA_MAX. This should ensure that all our alloca() based allocations are subject to this limit. afaics glibc offers three alloca() based APIs: alloca() itself, strndupa() + strdupa(). With this we have now replacements for all of them, that take the limit into account.
* parse-util: prefix load average macros with LOAD_AVG_Luca Boccassi2021-09-271-4/+4
| | | | Follow-up for #20839
* basic: delete loadavg.h copyLuca Boccassi2021-09-251-4/+4
| | | | | | | | | | loadavg.h is an internal header of the Linux source repository, and as such it is licensed as GPLv2-only, without syscall exception. We use it only for 4 macros, which are simply doing some math calculations that cannot thus be subject to copyright. Reimplement the same calculations in another internal header and delete loadavg.h from our tree.
* parse-util: use oom_score_adjust_is_valid() at one more placeLennart Poettering2021-07-281-2/+1
|
* util: move percent/permille/permyriad parser into percent-util.[ch]Lennart Poettering2021-02-181-140/+0
| | | | | | | A good chunk of parse-util.[ch] has been about parsing parts per hundred/thousand/ten-thousand. Let's split that out into its own file. No code changes, just some shuffling around.
* parse-util: add permyriad parsingAnita Zhang2021-02-021-39/+98
|
* treewide: tighten variable scope in loops (#18372)Susant Sahani2021-01-271-2/+1
| | | | Also use _cleanup_free_ in one more place.
* util: move parse_syscall_and_errno() to seccomp-util.cYu Watanabe2021-01-191-43/+0
| | | | | This makes parse-util.c independent of seccomp-util.c, which is located in src/shared.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* parse-util: add parse_loadavg_fixed_pointAnita Zhang2020-10-071-0/+42
|
* exec: Add kill action to system call filtersTopi Miettinen2020-09-151-1/+6
| | | | | | | | | | | | | | | | | Define explicit action "kill" for SystemCallErrorNumber=. In addition to errno code, allow specifying "kill" as action for SystemCallFilter=. --- v7: seccomp_parse_errno_or_action() returns -EINVAL if !HAVE_SECCOMP v6: use streq_ptr(), let errno_to_name() handle bad values, kill processes, init syscall_errno v5: actually use seccomp_errno_or_action_to_string(), don't fail bus unit parsing without seccomp v4: fix build without seccomp v3: drop log action v2: action -> number
* parse-util: also parse integers prefixed with 0b and 0oLennart Poettering2020-06-051-5/+51
| | | | | Let's adopt Python 3 style 0b and 0x syntaxes, because it makes a ton of sense, in particular in bitmask settings.
* parse-util: rewrite parse_mode() on top of safe_atou_full()Lennart Poettering2020-06-051-15/+13
| | | | | Parsing is hard, hence let's use our own careful wrappers wherever possible.
* parse-util: make return parameter optional in safe_atou16_full()Lennart Poettering2020-06-051-1/+3
| | | | | All other safe_atoXYZ_full() functions have the parameter optional, let's make it optoinal here, too.
* parse-util: allow '-0' as alternative to '0' and '+0'Lennart Poettering2020-06-051-4/+4
| | | | | | | | | | Let's allow "-0" as alternative to "+0" and "0" when parsing integers, unless the new SAFE_ATO_REFUSE_PLUS_MINUS flag is specified. In cases where allowing the +/- syntax shall not be allowed SAFE_ATO_REFUSE_PLUS_MINUS is the right flag to use, but this also means that -0 as only negative integer that fits into an unsigned value should be acceptable if the flag is not specified.
* parse-util: allow tweaking how to parse integersLennart Poettering2020-06-051-13/+52
| | | | | | | This allows disabling a few alternative ways to decode integers formatted as strings, for safety reasons. See: #15991
* basic: add STRCASE_IN_SET() which is to STR_IN_SET() what strcaseeq() is to ↵Lennart Poettering2020-05-041-2/+16
| | | | streq()
* basic/parse-util: add safe_atoux64()Zbigniew Jędrzejewski-Szmek2020-04-091-2/+2
|
* network: add SuppressPrefixLength option to RoutingPolicyRule (#14736)Naïm Favier2020-02-031-0/+16
| | | Closes #14724.
* Resolve alternative ifnames wherever we would resolve an interface nameZbigniew Jędrzejewski-Szmek2020-01-121-17/+0
| | | | To keep the names manageable, "ifname_or_ifindex" is replaced by "interface".
* tree-wide: make parse_ifindex simply return the indexZbigniew Jędrzejewski-Szmek2020-01-111-10/+7
| | | | | | | | We don't need a seperate output parameter that is of type int. glibc() says that the type is "unsigned", but the kernel thinks it's "int". And the "alternative names" interface also uses ints. So let's standarize on ints, since it's clearly not realisitic to have interface numbers in the upper half of unsigned int range.
* parse-util: sometimes it is useful to check if a string is a valid integer, ↵Lennart Poettering2019-12-041-14/+20
| | | | but not actually parse it
* tree-wide: drop locale.h when locale-util.h is includedYu Watanabe2019-11-041-1/+0
|
* tree-wide: drop string.h when string-util.h or friends are includedYu Watanabe2019-11-041-1/+0
|
* tree-wide: drop missing.hYu Watanabe2019-10-311-1/+1
|
* util: introduce format_bytes_full()Yu Watanabe2019-06-191-41/+0
| | | | And move it into format-util.c.
* util: add assertionsYu Watanabe2019-05-291-0/+3
|
* util: introduce parse_ifindex_or_ifname()Yu Watanabe2019-05-291-0/+19
|
* missing: drop old OOM related definitionsYu Watanabe2018-12-061-0/+1
| | | | These are exposed earlier than linux-3.11. Let's just include linux/oom.h.
* parse-util: allow parse_boolean() to take a NULL argumentLennart Poettering2018-11-301-1/+2
| | | | | | | It's pretty useful to allow parse_boolean() to take a NULL argument and return an error in that case, rather than abort. i.e. making this a runtime rather than programming error allows us to shorten code elsewhere.
* parse-util: rework parse_dev() based on safe_atou() and ↵Lennart Poettering2018-11-291-6/+20
| | | | | | | | DEVICE_MAJOR_VALID()/DEVICE_MINOR_VALID() Let's be a bit more careful when parsing major/minor pairs, and filter out more corner cases. This also means using safe_atou() rather than sscanf() to avoid weird negative unsigned handling and such.
* networkd: add support to configure ip rule port range and protocol.Susant Sahani2018-11-281-0/+20
| | | | | | | | | Please see: iprule: support for ip_proto, sport and dport match options https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=f686f764682745daf6a93b0a6330ba42a961f858 Closes 10622
* trivial: fix spelling in code commentsThomas Haller2018-09-301-1/+1
| | | | Based-on-patch-by: Rafael Fontenelle <rafaelff@gnome.org>
* parse-util: in parse_permille() check negative earlierLennart Poettering2018-07-251-3/+4
| | | | | | | | If 'v' is negative, it's wrong to add the decimal to it, as we'd actually need to subtract it in this case. But given that we don't want to allow negative vaues anyway, simply check earlier whether what we have parsed so far was negative, and react to that before adding the decimal to it.
* 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.
* basic/parse-util: remove unnecessary parenthesesZbigniew Jędrzejewski-Szmek2018-06-131-1/+1
|
* parse-util: add permille parser + testsMarc Kleine-Budde2018-06-091-0/+52
|