]> git.ipfire.org Git - thirdparty/systemd.git/commit
userdbctl: convert to OPTION and VERB macros
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Fri, 8 May 2026 06:25:10 +0000 (08:25 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Fri, 8 May 2026 13:52:10 +0000 (15:52 +0200)
commitcb8359877ecb4b361a4ff74ac839a4a55986560c
tree6a2897120a4efce26e285cc40ba19e61b4643452
parent576ca62b9b1b76c5621d29b9a3895ab21e645740
userdbctl: convert to OPTION and VERB macros

The situation with --chain is complicated. The old code tried to use "+…"
in getopt_long() to stop option parsing. But it didn't actually work.
This logic was originally added in 8072a7e6a9eaf2de120797dd16c5e0baea606219.
ef9c12b157a50d63e8a8eb710c013d16c2cea319 added an comment about 'optind=0'
which explains why the code doesn't work, but the code wasn't changed.

To wit:
$ userdbctl.old --no-pager --chain ssh-authorized-keys zbyszek -- /bin/echo --asdf
--asdf
$ userdbctl.old --no-pager --chain ssh-authorized-keys zbyszek /bin/echo -- --asdf
--asdf
$ userdbctl.old --no-pager --chain ssh-authorized-keys zbyszek /bin/echo --asdf
userdbctl.old: unrecognized option '--asdf'
(Basically, if "--" is used, it can be anywhere, since getopt_long() doesn't do
anything special after --chain and looks for the next option. There were some
tests of --chain, but they all used the username as the positional argument, so
it wasn't misinterpreted as an option.)

This behaviour is preserved in the conversion.

--help is generally the same except for expected formatting changes.
--json= is moved above between --output= and -j. For some reason it was
further down.

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
src/userdb/userdbctl.c