On Tue, Sep 06, 2016 at 12:29:58PM -0400, Anthony Coulter wrote:
> Sometimes when I restart a service after changing its configuration file
> I accidentally type:
>
> # rcctl restart smtpd.conf
> /usr/sbin/rcctl: ${cached_svc_is_special_smtpd.conf}: bad substitution
> /usr/sbin/rcctl[556]: set: cached_svc_is_special_smtpd.conf: is not an
> identifier
> rcctl: service smtpd.conf does not exist
>
> The message about a bad substitution is not helpful to the user, who
> only needs to know that smtpd.conf is not a service.
>
> The problem is the period in "smtpd.conf". Line 189 of rcctl fails:
> _cached=$(eval print \${cached_svc_is_special_${_svc}})
>
> Special service names are thus limited to underscores and alphanumerics
> because they're concatenated into shell variable names. So instead of
> checking for [ -n ${_svc} ] at the top of svc_is_special, we ought to
> check that ${_svc} contains only legal characters.
>
> I check only in svc_is_special and not in any of the other places that
> test [ -n ${_svc} ] my only goal is to fix the error message people get
> when they try to start or enable configuration files, and this is the
> only place that needs the error. Adding a similar check to svc_is_avail
> would block an error message when someone creates an executable file
> called /etc/rc.d/foo.bar and then calls "rcctl enable foo.bar", but in
> that case I think the message "${foo.bar_flags}: bad substitution" is
> more helpful---the user is trying to create a service with an illegal
> name and the system is telling him why it will never work.
Yes I agree this should be fixed.
What about this?
Index: rcctl.sh
===================================================================
RCS file: /cvs/src/usr.sbin/rcctl/rcctl.sh,v
retrieving revision 1.104
diff -u -p -r1.104 rcctl.sh
--- rcctl.sh 30 Jul 2016 06:25:21 -0000 1.104
+++ rcctl.sh 6 Sep 2016 18:51:18 -0000
@@ -139,7 +139,7 @@ rcconf_edit_end()
svc_is_avail()
{
local _svc=$1
- [ -n "${_svc}" ] || return
+ [[ "${_svc}" == +([_/+[:alnum:]]) ]] || return
[ -x "/etc/rc.d/${_svc}" ] && return
svc_is_special ${_svc}
--
Antoine