Repository navigation
Conversation
SC2117 used the argument count to decide whether su runs a command. That allowed 'su -c foo' but flagged the equivalent long form 'su --command=foo'. Instead, look for the command option itself: -c, -cfoo, short option clusters like -lc, --command or --command=foo.
e-kwsm
left a comment
There was a problem hiding this comment.
In BSD implementation -c can be class:
-c class
Use the settings of the specified login class. The login class must be defined in login.conf(5). Only allowed for the super-user.
su -m -c staff operator -c 'shutdown -p now'
Same as above, but the target command is run with the resource limits of the login class "staff". Note: in this example, the first-coption applies to su while the second is an argument to the shell being invoked.
https://man.freebsd.org/cgi/man.cgi?query=su&sektion=1&format=html
|
This would mean, that we miss a warning for |
|
I have no BSD machines, but IIUC |
If the checks were to depend on OS, this raises questions:
|
|
Unfortunately su implementation varies between Linux and BSD as it is not specified in POSIX, and sudo and doas are not always avaiable. In BSD, $ uname -sr
OpenBSD 8.0
$ su -c whoami
su: only the superuser may specify a login class
$ su root -c whoami
root
$ su -
# su -c whoami
su: no such login class: whoami
# su -c build # start an interactive session as root (implied) with class of build
# exit
# su -c build root # the same as above
# exit
# su root -c whoami
root
# su -c build root -c whoami
rootshellcheck targets BSD and macOS as you can see in README. There are issues expressing concerns about portability between GNU Linux and BSD e.g. #2902. In that sense the current message does not care portability either: $ shellcheck -s sh -f gcc - <<< 'su alice'
-:1:1: note: To run commands as another user, use su -c or sudo. [SC2117]
§ silently ignores |
su -c foo # SC2117 on BSD
su root -c foo # better
su --command foo # this does not work on BSD, but should SC2117 cover it?
# atm shellcheck does not validate options to su
#su -z foo # invalid option |
SC2117 used the argument count to decide whether su runs a command. That allowed 'su -c foo' but flagged the equivalent long form 'su --command=foo'. Instead, look for the command option itself: -c, -cfoo, short option clusters like -lc, --command or --command=foo.