Usage of su -m / rc.subr _user support

  • Anybody know why "Bad -c option" is triggered below? Is this an environment/shell configuration difference triggered by the usage of -m?

    From the shell in 2.4.4-RELEASE:
    su -m nobody -c 'sh -c "echo foo"'
    Bad -c option

    From a stock 11.2 FreeBSD install:
    su -m nobody -c 'sh -c "echo foo"'

    /etc/rc.subr supports providing the _user option, to allow daemons to be run as a different user, and this same error is triggered when attempting to use this.

  • Rebel Alliance Developer Netgate

    I tried it on several boxes with several different shells, and it worked for me each time. On 2.4.4, 2.5.0 snapshots, and FreeBSD 12.

  • Jim, it looks like the difference may be specific to connecting to the console using "admin" instead of "root". Connecting and issuing the prior steps as root works fine, whereas admin does not (for me).

    Admin has SHELL=/etc/rc.initial, whereas root has SHELL=/bin/sh, I haven't looked further at whether this explains the difference.

    This (rc.subr) also worked while logged in as user admin:
    _doit="echo $_doit | su -m $_user -c 'sh -s'"

  • Rebel Alliance Developer Netgate

    That would probably explain it, since admin is setup different.

    You could also install the sudo package and use that, which is less likely to care about such things.

  • This change appears to make it consistent, if you wanted it to be:
    /bin/sh -c $1
    change to
    /bin/sh -c "$1"

Log in to reply