Skip to main content

Parse and edit your FreeBSD jail.conf file with python.

Installation

To install jailconf, simply:

pip3 install jailconf

jailconf requires Python 3.

Examples

import jailconf

Load the configuration from a path

conf = jailconf.load('/etc/jail.conf')

Load the configuration from a string

conf = jailconf.loads(open('/etc/jail.conf').read())

Create an empty configuration

conf = jailconf.JailConf()

The configuration is represented as a dictionnary (actually a subclass of OrderedDict).

Let’s modify some settings.

The quoted strings in the configuration should be passed with the quotes. For example, to obtain the setting:

path = "/var/jail/$name";

you write:

conf['path'] = '"/var/jail/$name"'

The string should be exactly what you want to appear on the right side of the parameter name in the configuration file. If you want the value of a parameter to be a quoted string, you pass a string containing a quoted string. This allows you to specify what kind of quotes you want to see in the output configuration file (single quotes, double quotes, or no quote at all).

conf['exec.start'] = '"/bin/sh /etc/rc"'
conf['exec.stop'] = '"/bin/sh /etc/rc.shutdown"'

Boolean parameters. To obtain:

exec.clean;
mount.devfs;

you write:

conf['exec.clean'] = True
conf['mount.devfs'] = True

Add a jail:

conf['myjail'] = jailconf.JailBlock([
    ('host.hostname', '"example.com"'),
    ('ip4.addr', ['10.1.1.1', '10.1.1.2', '10.1.1.3'])
])

Modify a jail

conf['myjail']['ip4.addr'] = '192.168.1.2' # this will be rendered as the line: ip4.addr = 192.168.1.2

# To set multiple ips, use a list:

conf['myjail']['ip4.addr'] = ['192.168.1.2', '192.168.1.3']

Delete a jail

del conf['uselessjail']

Iterate over jails

for name, jail_block in conf.jails():
    jail_block['host.hostname'] = '"%s"' % name

Output the configuration as a string

>>> print(conf.dumps())
path = "/var/jail/$name";
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.clean;
mount.devfs;
myjail {
        host.hostname = "myjail";
        ip4.addr = 192.168.1.2, 192.168.1.3;
}

Write the configuration to a file

conf.write('/etc/jail.conf')

GitHub repo: https://github.com/leforestier/jailconf

Metadata

Release files for jailconf 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jailconf 0.2.2
File Size Uploaded Provenance
jailconf-0.2.2.tar.gz 7.0 kB Without provenance Details

Release files / jailconf-0.2.2.tar.gz

Download URL jailconf-0.2.2.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
17cb2f14a1247356ea8981e9776113cf9141e4c71cf9f769411822b9cc296d88
BLAKE2b-256 checksum
How to use checksums
5b180227c051b497550e9c7d00cddfa2f7e27c1b00b236b4931c3dbd04b219a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.8

Security for jailconf 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page