Commit Graph

55 Commits

Author SHA1 Message Date
Lennart Poettering 4a39c77419 strv: fix STRV_FOREACH_BACKWARDS() to be a single statement only
Let's make sure people invoking STRV_FOREACH_BACKWARDS() as a single statement
of an if statement don't fall into a trap, and find the tail for the list via
strv_length().
2016-10-07 20:14:38 +02:00
Zbigniew Jędrzejewski-Szmek c7bf9d5183 basic/strv: add STRPTR_IN_SET
Also some trivial tests for STR_IN_SET and STRPTR_IN_SET.
2016-09-24 20:13:28 -04:00
Zbigniew Jędrzejewski-Szmek b60df13b39 basic/strv: add an extra NUL after strings in strv_make_nulstr
strv_make_nulstr was creating a nulstr which was not a valid nulstr,
because it was missing the terminating NUL. This didn't cause any issues,
because strv_parse_nulstr correctly parsed the result, using the
separately specified length.

But it's confusing to have something called nulstr which really isn't.
It is likely that somebody will try to use strv_make_nulstr() in
some other place, incorrectly.

This patch changes strv_parse_nulstr() to produce a valid nulstr, and
changes the output length parameter to be the minimum number of bytes
which can be later on parsed by strv_parse_nulstr(). This allows the
only user in ask-password-api to be slightly simplified.

Based-on-patch-by: Jean-Sébastien Bour <jean-sebastien@bour.name>

Fixes #3689.
2016-07-17 15:34:57 -04:00
Jean-Sébastien Bour f41794d036 basic/strv: exhibit strv_make_nulstr missing final NUL char (systemd/systemd#3689) 2016-07-17 18:14:59 +02:00
Evgeny Vereshchagin 57681e84ce tests: fix memory leak in test_strv_fnmatch (#3653)
==1447== 4 bytes in 1 blocks are definitely lost in loss record 1 of 1
==1447==    at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
==1447==    by 0x5350F19: strdup (in /usr/lib64/libc-2.23.so)
==1447==    by 0x4E9D435: strv_new_ap (strv.c:166)
==1447==    by 0x4E9D5FA: strv_new (strv.c:199)
==1447==    by 0x10E665: test_strv_fnmatch (test-strv.c:693)
==1447==    by 0x10EAD5: main (test-strv.c:763)
==1447==
2016-07-04 10:11:07 +02:00
Evgeny Vereshchagin 2027927b10 basic: pass flags to the fnmatch (#3606)
Fixes:
```
$ systemctl list-unit-files 'hey\*'

0 unit files listed.

$ systemctl list-unit-files | grep hey
hey\x7eho.service                          static
```
2016-06-27 14:47:37 +02:00
Zbigniew Jędrzejewski-Szmek ea9b54f827 test-strv: add a test that extending empty strv works as expected
Just making sure :)
2016-04-13 21:09:32 -04:00
Ronny Chevalier ebde5cb261 tests: move strv related tests to test-strv.c 2016-03-03 18:46:58 +01:00
Zbigniew Jędrzejewski-Szmek afe773b01a basic/strv: fix strv_join for first empty argument
Empty strings were ignored in strv_join, but only if they were at the beginning
of the string. Empty strings after at least one non-empty item were treated
normally.

Previously:
{"x"} → "x"
{"x", ""} → "x"
{"x", "", ""} → "x::"
{""} → ""
{"", ""} → ""
{"", "", ""} → ""
{"", "x"} → "x"
{"", "x", ""} → "x:"
Now:
{"x"} → "x"
{"x", ""} → "x"
{"x", "", ""} → "x::"
{""} → ""
{"", ""} → ":"
{"", "", ""} → "::"
{"", "x"} → ":x"
{"", "x", ""} → ""
2016-02-13 11:54:39 -05: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 b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +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 e287086b8a ask-password: add support for caching passwords in the kernel keyring
This adds support for caching harddisk passwords in the kernel keyring
if it is available, thus supporting caching without Plymouth being
around.

This is also useful for hooking up "gdm-auto-login" with the collected
boot-time harddisk password, in order to support gnome keyring
passphrase unlocking via the HDD password, if it is the same.

Any passwords added to the kernel keyring this way have a timeout of
2.5min at which time they are purged from the kernel.
2015-10-07 12:26:14 +02:00
Lennart Poettering 8dd4c05b54 core: add support for naming file descriptors passed using socket activation
This adds support for naming file descriptors passed using socket
activation. The names are passed in a new $LISTEN_FDNAMES= environment
variable, that matches the existign $LISTEN_FDS= one and contains a
colon-separated list of names.

This also adds support for naming fds submitted to the per-service fd
store using FDNAME= in the sd_notify() message.

This also adds a new FileDescriptorName= setting for socket unit files
to set the name for fds created by socket units.

This also adds a new call sd_listen_fds_with_names(), that is similar to
sd_listen_fds(), but also returns the names of the fds.

systemd-activate gained the new --fdname= switch to specify a name for
testing socket activation.

This is based on #1247 by Maciej Wereski.

Fixes #1247.
2015-10-06 11:52:48 +02:00
Lennart Poettering e3ead6bb42 systemctl: move strv_skip_first() out of systemctl.c
Make it generic, call it strv_skip() and move it to strv.[ch]
2015-09-29 21:55:52 +02:00
Richard Maw 04c14b2541 strv: Add strv_shell_escape
This modifies the strv in-place, replacing strings with their escaped
version. It's mostly just a convenience function for when you need to
join a strv together because it's passed as a string to something, and
the separator needs escaping.
2015-08-07 15:50:43 +00:00
Richard Maw 8adaf7bd23 strv: convert strv_split_quotes into a generic strv_split_extract
strv_split_extract is to strv_split_quotes as extract_first_word was to
unquote_first_word.

Now there's extract_first_word for extracting a single argument,
extract_many_words for extracting a bounded number of arguments,
and strv_split_extract for extracting an arbitrary number of arguments.
2015-08-07 15:50:43 +00:00
Thomas Hindoe Paaboel Andersen 7d6884b65e tree-wide: fix indentation 2015-08-06 00:44:19 +02:00
Lennart Poettering 4034a06ddb util: rework word parsing and c unescaping code
When parsing words from input files, optionally automatically unescape
the passed strings, controllable via a new flags parameter.

Make use of this in tmpfiles, and port everything else over, too.

This improves parsing quite a bit, since we no longer have to process the
same string multiple times with different calls, where an earlier call
might corrupt the input for a later call.
2015-03-26 11:56:22 +01:00
Lennart Poettering e1dd6790e4 strv: ass new strv_is_uniq() and strv_reverse() calls 2014-12-19 02:07:42 +01:00
Zbigniew Jędrzejewski-Szmek ba774317ac Treat a trailing backslash as an error
Commit a2a5291b3f changed the parser to reject unfinished quoted
strings. Unfortunately it introduced an error where a trailing
backslash would case an infinite loop. Of course this must fixed, but
the question is what to to instead. Allowing trailing backslashes and
treating them as normal characters would be one option, but this seems
suboptimal. First, there would be inconsistency between handling of
quoting and of backslashes. Second, a trailing backslash is most
likely an error, at it seems better to point it out to the user than
to try to continue.

Updated rules:
ExecStart=/bin/echo \\ → OK, prints a backslash
ExecStart=/bin/echo \ → error
ExecStart=/bin/echo "x → error
ExecStart=/bin/echo "x"y → error
2014-12-18 19:26:21 -05:00
Zbigniew Jędrzejewski-Szmek 30bcc05295 test-strv: use STRV_MAKE 2014-12-18 19:26:21 -05:00
Ronny Chevalier e74aa253e9 test-strv: add test for strv_equal 2014-12-11 18:32:57 +01:00
Lennart Poettering 98940a3cd9 strv: add calls to add two entries to an strv at once 2014-12-03 18:31:51 +01:00
Lennart Poettering f88e6be5ee strv: rework strv_split_quoted() to use unquote_first_word()
This should make the unquoting scheme a bit less naive.
2014-11-10 23:45:12 +01:00
Ronny Chevalier 7bd57a87ad tests: add tests for strv.c
add tests for:
- strv_find_startswith
- strv_push_prepend
- strv_consume_prepend
2014-10-31 10:57:21 +01:00
Thomas Hindoe Paaboel Andersen bdf7026e95 test: only use assert_se
The asserts used in the tests should never be allowed to be
optimized away
2014-10-04 23:55:35 +02:00
Zbigniew Jędrzejewski-Szmek b2fadec604 Properly report invalid quoted strings
$ systemd-analyze verify trailing-g.service
[./trailing-g.service:2] Trailing garbage, ignoring.
trailing-g.service lacks ExecStart setting. Refusing.
Error: org.freedesktop.systemd1.LoadFailed: Unit trailing-g.service failed to load: Invalid argument.
Failed to create trailing-g.service/start: Invalid argument
2014-07-31 08:56:03 -04:00
Zbigniew Jędrzejewski-Szmek a2a5291b3f Reject invalid quoted strings
String which ended in an unfinished quote were accepted, potentially
with bad memory accesses.

Reject anything which ends in a unfished quote, or contains
non-whitespace characters right after the closing quote.

_FOREACH_WORD now returns the invalid character in *state. But this return
value is not checked anywhere yet.

Also, make 'word' and 'state' variables const pointers, and rename 'w'
to 'word' in various places. Things are easier to read if the same name
is used consistently.

mbiebl_> am I correct that something like this doesn't work
mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-passwd "Unlock EncFS"'
mbiebl_> systemd seems to strip of the quotes
mbiebl_> systemctl status shows
mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-password Unlock EncFS  $RootDir $MountPoint
mbiebl_> which is pretty weird
2014-07-31 04:00:31 -04:00
Zbigniew Jędrzejewski-Szmek 73381fcf54 test-strv: add test which shows access to random memory 2014-07-31 04:00:31 -04:00
Ronny Chevalier 4a336a69fd tests: add tests for strv_extendf 2014-06-19 19:59:57 -04:00
Simon Peeters e3e45d4f82 strv: multiple cleanups
- turn strv_merge into strv_extend_strv.
   appending strv b to the end of strv a instead of creating a new strv
- strv_append: remove in favor of strv_extend and strv_push.
- strv_remove: write slightly more elegant
- strv_remove_prefix: remove unused function
- strv_overlap: use strv_contains
- strv_printf: STRV_FOREACH handles NULL correctly
2014-01-05 09:16:15 -05:00
Thomas Hindoe Paaboel Andersen 5fba7bbfa4 scan-build: silence some warnings
test-fileio/test-strv:
Use the streq_ptr to make build-scan not worry about passing in a null
to a nonnull function.

test-dhcp-option:
Prevent a theoretical null pointer dereference
2013-12-12 23:08:47 +01:00
Lennart Poettering 70f75a523b util: fix handling of trailing whitespace in split_quoted()
Inspired by a patch by Lukas Nykryn.
2013-11-28 18:42:18 +01:00
Daniel Buch aed2ebfed0 test-strv: add strv_split, strv_split_newline, strv_remove_prefix 2013-11-07 01:23:55 -05:00
Lennart Poettering 897e7561a0 strv: introduce new STRV_MAKE and STRV_MAKE_EMPTY macros to create string arrays nicely on the fly 2013-10-29 20:09:16 +01:00
Lennart Poettering 250a918dc4 strv: introduce new strv_from_stdarg_alloca() macro to generate a string array from stdarg function parameters
This allows us to turn lists of strings passed in easily into string
arrays without having to allocate memory.
2013-10-29 19:53:43 +01:00
Daniel Buch 02f19706a9 test-strv.c: added STRV_FOREACH and STRV_FOREACH_BACKWARDS 2013-10-27 11:51:22 -04:00
Lennart Poettering 1731e34a4e tmpfiles: support simple specifier expansion for specified paths 2013-09-17 11:02:54 -05:00
Lennart Poettering 19f6d71077 specifier: rework specifier calls to return proper error message
Previously the specifier calls could only indicate OOM by returning
NULL. With this change they will return negative errno-style error codes
like everything else.
2013-09-17 10:06:50 -05:00
Zbigniew Jędrzejewski-Szmek a6fde35332 systemd-run: properly escape arguments
Spaces, quotes, and such, were not properly escaped. We should
write them like we read them.

https://bugs.freedesktop.org/show_bug.cgi?id=67971
2013-09-09 13:49:29 -04:00
Zbigniew Jędrzejewski-Szmek 1e64bbc156 test-strv: do not declare table to be sorted const
Segmentation fault under clang.
2013-04-05 00:31:59 -04:00
Daniel Buch 4c325b2efe test-strv.c: test STRV_FOREACH_PAIR macro 2013-03-18 21:09:02 +01:00
Daniel Buch 9f31636648 test-strv.c: ported test_specifier_printf() to _cleanup_free_ + assert_se + cleanup 2013-02-18 23:57:56 +01:00
Daniel Buch 04045d8426 test-strv.c: added OOM check for current tests
New OOM check patch:

I do assert_se() before variable is used to do correct check.
2013-02-18 23:57:48 +01:00
Daniel Buch 2f213f7493 test-strv.c: added strv_split_nulstr() test 2013-02-18 23:57:43 +01:00
Daniel Buch 7b68d618a2 test-strv.c: Changed assert() to assert_se()
test-strv.c: Indent fix
2013-02-13 20:22:12 +01:00
Daniel Buch 40857008d8 test-strv.c: added strv_append test 2013-02-13 20:22:09 +01:00
Daniel Buch 343a896935 test-strv.c: added strv_merge_concat test 2013-02-13 20:22:05 +01:00
Daniel Buch a1022300b9 test-strv.c: added strv_merge test 2013-02-13 20:21:44 +01:00