Bug 191181 - [jail] Jailnames cannot contain a dash
Summary: [jail] Jailnames cannot contain a dash
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: Jamie Gritton
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-19 12:44 UTC by Robert Schulze
Modified: 2016-01-15 18:27 UTC (History)
5 users (show)

See Also:


Attachments
jail.conf (657 bytes, text/plain)
2015-02-16 19:26 UTC, thomas.finstad.larsen
no flags Details
Safely map between jail names and rc.conf shell variables (9.65 KB, patch)
2015-03-07 04:08 UTC, Jamie Gritton
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Schulze 2014-06-19 12:44:54 UTC
When trying to start a jail with a dash in it, /etc/rc.d/jail loops printing the following message:

/etc/rc.d/jail: WARNING: jail_extract_address: type not identified
expr: illegal option -- b
expr: usage: expr [-e] expression
Comment 1 Robert Schulze 2014-06-20 14:34:41 UTC
Note: the name does not even have to be declared in jail.conf for this to trigger. Also the warning is dependend on the name given.

E.g.

# /etc/rc.d/jail start foo-bar
/etc/rc.d/jail: WARNING: jail_extract_address: type not identified
expr: illegal option -- b
expr: usage: expr [-e] expression

# /etc/rc.d/jail start bar-foo
/etc/rc.d/jail: WARNING: jail_extract_address: type not identified
expr: illegal option -- f
expr: usage: expr [-e] expression
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2014-06-26 01:58:07 UTC
over to maintainers.
Comment 3 Allan Jude freebsd_committer freebsd_triage 2014-06-26 02:06:23 UTC
Can you provide more detail, like your jail.conf etc
Comment 4 Robert Schulze 2014-06-26 08:02:03 UTC
The message occurs even without an existing /etc/jail.conf.
The system is 10.0-RELEASE-p2 #1 r265140.

What further information is required?
Comment 5 thomas.finstad.larsen 2015-02-16 19:26:38 UTC
Created attachment 153050 [details]
jail.conf

Current jail.conf
Comment 6 thomas.finstad.larsen 2015-02-16 19:27:58 UTC
I experience the same problem, I attached jail.conf in case that will help.

I can start jails using jail -c dom-ldap01, but I cannot use service jail start or have them start at boot.
Comment 7 Maciej Pasternacki 2015-02-17 11:33:11 UTC
Comment on attachment 153050 [details]
jail.conf

Just use double quotes around the jail name ("dom-ldap01" { … }).
Comment 8 Jamie Gritton freebsd_committer freebsd_triage 2015-03-07 04:08:15 UTC
Created attachment 153948 [details]
Safely map between jail names and rc.conf shell variables

Currently, rc.d/jail will strip some special characters ('.' and '/') from a jail name, and replace them with underscores.  That's sufficient for some purposes, but the requirements for shell variables are much stricter: only alphanumeric plus underscore.

I don't want to restrict jail names that far, so I've split the jail name into two purposes.  There's the jail's name which is as specified (e.g. on the command line) except with the '.' and '/' stripped out, and then the tag associated with jail variables which has all other non-alphanumeric characters also replaced with an underscore.  These are in the variables $_j and $_jv throughout the script.

If you have a jail named foo-bar, that's the name of the jail that would be created.  It would have a conf file in /var/run/jail.foo-bar.conf, and store its id in /var/run/jail_foo-bar.id.  If for some reason you wanted to continue to use old rc-shell-based configuration, the parameters would be along the lines of jail_foo_bar_ip and jail_foo_bar_hostname. Even if you use a proper jail.conf, the shell script won't get confused by illegal variable names.
Comment 9 commit-hook freebsd_committer freebsd_triage 2015-12-26 23:02:29 UTC
A commit references this bug:

Author: jamie
Date: Sat Dec 26 23:01:35 UTC 2015
New revision: 292759
URL: https://svnweb.freebsd.org/changeset/base/292759

Log:
  Let old-style (shell-based) jail configuration handle jail names that
  contain characters not allowed in a shell variable (such as "-").
  These will be replaced by an underscore in jail config variables,
  e.g. for jail "foo-bar" you would set "jail_foo_bar_hostname".

  This is separate from the current code that changes the jail names
  if they contain "." or "/".  It also doesn't apply to jails defined
  in a jail.conf file.

  PR:		191181
  MFC after:	5 days

Changes:
  head/etc/rc.d/jail
Comment 10 commit-hook freebsd_committer freebsd_triage 2015-12-31 01:24:39 UTC
A commit references this bug:

Author: jamie
Date: Thu Dec 31 01:24:16 UTC 2015
New revision: 292967
URL: https://svnweb.freebsd.org/changeset/base/292967

Log:
  MFC r292759:

    Let old-style (shell-based) jail configuration handle jail names that
    contain characters not allowed in a shell variable (such as "-").
    These will be replaced by an underscore in jail config variables,
    e.g. for jail "foo-bar" you would set "jail_foo_bar_hostname".

    This is separate from the current code that changes the jail names
    if they contain "." or "/".  It also doesn't apply to jails defined
    in a jail.conf file.

  PR:		191181

Changes:
_U  stable/10/
  stable/10/etc/rc.d/jail
Comment 11 Robert Schulze 2016-01-15 12:31:05 UTC
This has NOT been fixed, at least on 10.2-RELEASE-p10.

# /etc/rc.d/jail start foo-bar
/etc/rc.d/jail: WARNING: jail_extract_address: type not identified
expr: illegal option -- b
expr: usage: expr [-e] expression
[endless loop]

Please note that this even occurs with an empty jail.conf.

with kind regards,
Robert Schulze
Comment 12 Jamie Gritton freebsd_committer freebsd_triage 2016-01-15 18:27:35 UTC
No, it is not fixed in 10.2-RELEASE-p10.  This is not the level of bug fix that will be going into errata and patching an existing release.  It is fixed in CURRENT and in 10.0-STABLE, and will end up in 10.3.