173577bf0SRyan Moeller.\" 2*4d846d26SWarner Losh.\" SPDX-License-Identifier: BSD-2-Clause 373577bf0SRyan Moeller.\" 473577bf0SRyan Moeller.\" Copyright (c) 2020, Ryan Moeller <freqlabs@FreeBSD.org> 573577bf0SRyan Moeller.\" 673577bf0SRyan Moeller.\" Redistribution and use in source and binary forms, with or without 773577bf0SRyan Moeller.\" modification, are permitted provided that the following conditions 873577bf0SRyan Moeller.\" are met: 973577bf0SRyan Moeller.\" 1. Redistributions of source code must retain the above copyright 1073577bf0SRyan Moeller.\" notice, this list of conditions and the following disclaimer. 1173577bf0SRyan Moeller.\" 2. Redistributions in binary form must reproduce the above copyright 1273577bf0SRyan Moeller.\" notice, this list of conditions and the following disclaimer in the 1373577bf0SRyan Moeller.\" documentation and/or other materials provided with the distribution. 1473577bf0SRyan Moeller.\" 1573577bf0SRyan Moeller.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1673577bf0SRyan Moeller.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1773577bf0SRyan Moeller.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1873577bf0SRyan Moeller.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1973577bf0SRyan Moeller.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2073577bf0SRyan Moeller.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2173577bf0SRyan Moeller.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2273577bf0SRyan Moeller.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2373577bf0SRyan Moeller.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2473577bf0SRyan Moeller.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2573577bf0SRyan Moeller.\" SUCH DAMAGE. 2673577bf0SRyan Moeller.\" 2773577bf0SRyan Moeller.Dd October 24, 2020 2873577bf0SRyan Moeller.Dt JAIL 3lua 2973577bf0SRyan Moeller.Os 3073577bf0SRyan Moeller.Sh NAME 31a6499c56SKyle Evans.Nm attach , 3273577bf0SRyan Moeller.Nm getid , 3373577bf0SRyan Moeller.Nm getname , 346a7647ecSKyle Evans.Nm list , 3573577bf0SRyan Moeller.Nm allparams , 3673577bf0SRyan Moeller.Nm getparams , 37a6499c56SKyle Evans.Nm remove , 3873577bf0SRyan Moeller.Nm setparams , 3973577bf0SRyan Moeller.Nm CREATE , 4073577bf0SRyan Moeller.Nm UPDATE , 4173577bf0SRyan Moeller.Nm ATTACH , 4273577bf0SRyan Moeller.Nm DYING 4373577bf0SRyan Moeller.Nd Lua binding to 4473577bf0SRyan Moeller.Xr jail 3 4573577bf0SRyan Moeller.Sh SYNOPSIS 4673577bf0SRyan Moeller.Bd -literal 4773577bf0SRyan Moellerlocal jail = require('jail') 4873577bf0SRyan Moeller.Ed 4973577bf0SRyan Moeller.Pp 5073577bf0SRyan Moeller.Bl -tag -width XXXX -compact 51a6499c56SKyle Evans.It Dv ok, err = jail.attach(jid|name) 5273577bf0SRyan Moeller.It Dv jid, err = jail.getid(name) 5373577bf0SRyan Moeller.It Dv name, err = jail.getname(jid) 5473577bf0SRyan Moeller.It Dv params, err = jail.allparams() 556a7647ecSKyle Evans.It Dv iter, jail_obj = jail.list([params]) 5673577bf0SRyan Moeller.It Dv jid, res = jail.getparams(jid|name, params [, flags ] ) 57a6499c56SKyle Evans.It Dv ok, err = jail.remove(jid|name) 5873577bf0SRyan Moeller.It Dv jid, err = jail.setparams(jid|name, params, flags ) 5973577bf0SRyan Moeller.It Dv jail.CREATE 6073577bf0SRyan Moeller.It Dv jail.UPDATE 6173577bf0SRyan Moeller.It Dv jail.ATTACH 6273577bf0SRyan Moeller.It Dv jail.DYING 6373577bf0SRyan Moeller.El 6473577bf0SRyan Moeller.Sh DESCRIPTION 6573577bf0SRyan MoellerThe 6673577bf0SRyan Moeller.Nm jail 6773577bf0SRyan Moellermodule is a binding to the 6873577bf0SRyan Moeller.Xr jail 3 6973577bf0SRyan Moellerlibrary. 7073577bf0SRyan MoellerIt provides a string-oriented interface for the 7173577bf0SRyan Moeller.Xr jail_get 2 7273577bf0SRyan Moellerand 7373577bf0SRyan Moeller.Xr jail_set 2 7473577bf0SRyan Moellersystem calls. 7573577bf0SRyan Moeller.Bl -tag -width XXXX 76a6499c56SKyle Evans.It Dv ok, err = jail.attach(jid|name) 77a6499c56SKyle EvansAttach to the given jail, identified by an integer 78a6499c56SKyle Evans.Fa jid 79a6499c56SKyle Evansor the 80a6499c56SKyle Evans.Fa name . 8173577bf0SRyan Moeller.It Dv jid, err = jail.getid(name) 8273577bf0SRyan MoellerGet the jail identifier 8373577bf0SRyan Moeller.Pq jid 8473577bf0SRyan Moelleras an integer. 8573577bf0SRyan Moeller.Fa name 8673577bf0SRyan Moelleris the name of a jail or a jid in the form of a string. 8773577bf0SRyan Moeller.It Dv name, err = jail.getname(jid) 8873577bf0SRyan MoellerGet the name of a jail as a string for the given 8973577bf0SRyan Moeller.Fa jid 9073577bf0SRyan Moeller.Pq an integer . 916a7647ecSKyle Evans.It Dv iter, jail_obj = jail.list([params]) 926a7647ecSKyle EvansReturns an iterator over running jails on the system. 936a7647ecSKyle Evans.Dv params 946a7647ecSKyle Evansis a list of parameters to fetch for each jail as we iterate. 956a7647ecSKyle Evans.Dv jid 966a7647ecSKyle Evansand 976a7647ecSKyle Evans.Dv name 986a7647ecSKyle Evanswill always be returned, and may be omitted from 996a7647ecSKyle Evans.Dv params . 1006a7647ecSKyle EvansAdditionally, 1016a7647ecSKyle Evans.Dv params 1026a7647ecSKyle Evansmay be omitted or an empty table, but not nil. 1036a7647ecSKyle Evans.Pp 1046a7647ecSKyle EvansSee 1056a7647ecSKyle Evans.Sx EXAMPLES . 10673577bf0SRyan Moeller.It Dv params, err = jail.allparams() 10773577bf0SRyan MoellerGet a list of all supported parameter names 10873577bf0SRyan Moeller.Pq as strings . 10973577bf0SRyan MoellerSee 11073577bf0SRyan Moeller.Xr jail 8 11173577bf0SRyan Moellerfor descriptions of the core jail parameters. 11273577bf0SRyan Moeller.It Dv jid, res = jail.getparams(jid|name, params [, flags ] ) 11373577bf0SRyan MoellerGet a table of the requested parameters for the given jail. 11473577bf0SRyan Moeller.Nm jid|name 11573577bf0SRyan Moellercan either be the jid as an integer or the jid or name as a string. 11673577bf0SRyan Moeller.Nm params 11773577bf0SRyan Moelleris a list of parameter names. 11873577bf0SRyan Moeller.Nm flags 11973577bf0SRyan Moelleris an optional integer representing the flag bits to apply for the operation. 12073577bf0SRyan MoellerSee the list of flags below. 12173577bf0SRyan MoellerOnly the 12273577bf0SRyan Moeller.Dv DYING 12373577bf0SRyan Moellerflag is valid to set. 124a6499c56SKyle Evans.It Dv ok, err = jail.remove(jid|name) 125a6499c56SKyle EvansRemove the given jail, identified by an integer 126a6499c56SKyle Evans.Fa jid 127a6499c56SKyle Evansor the 128a6499c56SKyle Evans.Fa name . 12973577bf0SRyan Moeller.It Dv jid, err = jail.setparams(jid|name, params [, flags ] ) 13073577bf0SRyan MoellerSet parameters for a given jail. 13173577bf0SRyan MoellerThis is used to create, update, attach to, or destroy a jail. 13273577bf0SRyan Moeller.Nm jid|name 13373577bf0SRyan Moellercan either be the jid as an integer or the jid or name as a string. 13473577bf0SRyan Moeller.Nm params 13573577bf0SRyan Moelleris a table of parameters to apply to the jail, where each key in the table 13673577bf0SRyan Moelleris a parameter name as a string and each value is a string that will be 13773577bf0SRyan Moellerconverted to the internal value type by 13873577bf0SRyan Moeller.Xr jailparam_import 3 . 13973577bf0SRyan Moeller.Nm flags 14073577bf0SRyan Moelleris an optional integer representing the flag bits to apply for the operation. 14173577bf0SRyan MoellerSee the list of flags below. 14273577bf0SRyan Moeller.El 14373577bf0SRyan Moeller.Pp 14473577bf0SRyan MoellerThe 14573577bf0SRyan Moeller.Nm flags 14673577bf0SRyan Moellerarguments are an integer bitwise-or combination of one or more of the following 14773577bf0SRyan Moellerflags: 14873577bf0SRyan Moeller.Bl -tag -width XXXX 14973577bf0SRyan Moeller.It Dv jail.CREATE 15073577bf0SRyan MoellerUsed with 15173577bf0SRyan Moeller.Fn setparams 15273577bf0SRyan Moellerto create a new jail. 15373577bf0SRyan MoellerThe jail must not already exist, unless combined with 15473577bf0SRyan Moeller.Dv UPDATE . 15573577bf0SRyan Moeller.It Dv jail.UPDATE 15673577bf0SRyan MoellerUsed with 15773577bf0SRyan Moeller.Fn setparams 15873577bf0SRyan Moellerto modify an existing jail. 15973577bf0SRyan MoellerThe jail must already exist, unless combined with 16073577bf0SRyan Moeller.Dv CREATE . 16173577bf0SRyan Moeller.It Dv jail.ATTACH 16273577bf0SRyan MoellerUsed with 16373577bf0SRyan Moeller.Fn setparams 16473577bf0SRyan Moellerin combination with 16573577bf0SRyan Moeller.Dv CREATE 16673577bf0SRyan Moelleror 16773577bf0SRyan Moeller.Dv UPDATE 16873577bf0SRyan Moellerto attach the current process to a jail. 16973577bf0SRyan Moeller.It Dv jail.DYING 17073577bf0SRyan MoellerAllow operating on a jail that is in the process of being removed. 17173577bf0SRyan Moeller.El 17273577bf0SRyan Moeller.Sh RETURN VALUES 17373577bf0SRyan MoellerThe 17473577bf0SRyan Moeller.Fn getid 17573577bf0SRyan Moellerand 17673577bf0SRyan Moeller.Fn setparams 17773577bf0SRyan Moellerfunctions return a jail identifier integer on success, or 17873577bf0SRyan Moeller.Dv nil 17973577bf0SRyan Moellerand an error message string if an error occurred. 18073577bf0SRyan Moeller.Pp 18173577bf0SRyan MoellerThe 18273577bf0SRyan Moeller.Fn getname 18373577bf0SRyan Moellerfunction returns a jail name string on success, or 18473577bf0SRyan Moeller.Dv nil 18573577bf0SRyan Moellerand an error message string if an error occurred. 18673577bf0SRyan Moeller.Pp 18773577bf0SRyan MoellerThe 18873577bf0SRyan Moeller.Fn allparams 18973577bf0SRyan Moellerfunction returns a list of parameter name strings on success, or 19073577bf0SRyan Moeller.Dv nil 19173577bf0SRyan Moellerand an error message string if an error occurred. 19273577bf0SRyan Moeller.Pp 19373577bf0SRyan MoellerThe 19473577bf0SRyan Moeller.Fn getparams 19573577bf0SRyan Moellerfunction returns a jail identifier integer and a table of jail parameters 19673577bf0SRyan Moellerwith parameter name strings as keys and strings for values on success, or 19773577bf0SRyan Moeller.Dv nil 19873577bf0SRyan Moellerand an error message string if an error occurred. 1996a7647ecSKyle Evans.Pp 2006a7647ecSKyle EvansThe 2016a7647ecSKyle Evans.Fn list 2026a7647ecSKyle Evansfunction returns an iterator over the list of running jails. 203a6499c56SKyle Evans.Pp 204a6499c56SKyle EvansThe 205a6499c56SKyle Evans.Fn attach 206a6499c56SKyle Evansand 207a6499c56SKyle Evans.Fn remove 208a6499c56SKyle Evansfunctions return true on success, or 209a6499c56SKyle Evans.Dv nil 210a6499c56SKyle Evansand an error message string if an error occurred. 21173577bf0SRyan Moeller.Sh EXAMPLES 21273577bf0SRyan MoellerSet the hostname of jail 21373577bf0SRyan Moeller.Dq foo 21473577bf0SRyan Moellerto 21573577bf0SRyan Moeller.Dq foo.bar : 21673577bf0SRyan Moeller.Bd -literal -offset indent 21773577bf0SRyan Moellerlocal jail = require('jail') 21873577bf0SRyan Moeller 21973577bf0SRyan Moellerjid, err = jail.setparams("foo", {["host.hostname"]="foo.bar"}, 22073577bf0SRyan Moeller jail.UPDATE) 22173577bf0SRyan Moellerif not jid then 22273577bf0SRyan Moeller error(err) 22373577bf0SRyan Moellerend 22473577bf0SRyan Moeller.Ed 22573577bf0SRyan Moeller.Pp 22673577bf0SRyan MoellerRetrieve the hostname of jail 22773577bf0SRyan Moeller.Dq foo : 22873577bf0SRyan Moeller.Bd -literal -offset indent 22973577bf0SRyan Moellerlocal jail = require('jail') 23073577bf0SRyan Moeller 23173577bf0SRyan Moellerjid, res = jail.getparams("foo", {"host.hostname"}) 23273577bf0SRyan Moellerif not jid then 23373577bf0SRyan Moeller error(res) 23473577bf0SRyan Moellerend 23573577bf0SRyan Moellerprint(res["host.hostname"]) 23673577bf0SRyan Moeller.Ed 2376a7647ecSKyle Evans.Pp 2386a7647ecSKyle EvansIterate over jails on the system: 2396a7647ecSKyle Evans.Bd -literal -offset indent 2406a7647ecSKyle Evanslocal jail = require('jail') 2416a7647ecSKyle Evans 2426a7647ecSKyle Evans-- Recommended: just loop over it 2436a7647ecSKyle Evansfor jparams in jail.list() do 2446a7647ecSKyle Evans print(jparams["jid"] .. " = " .. jparams["name"]) 2456a7647ecSKyle Evansend 2466a7647ecSKyle Evans 2476a7647ecSKyle Evans-- Request path and hostname, too 2486a7647ecSKyle Evansfor jparams in jail.list({"path", "host.hostname"}) do 2496a7647ecSKyle Evans print(jparams["host.hostname"] .. " mounted at " .. jparams["path"]) 2506a7647ecSKyle Evansend 2516a7647ecSKyle Evans 2526a7647ecSKyle Evans-- Raw iteration protocol 2536a7647ecSKyle Evanslocal iter, jail_obj = jail.list() 2546a7647ecSKyle Evans 2556a7647ecSKyle Evans-- Request the first params 2566a7647ecSKyle Evanslocal jparams = jail_obj:next() 2576a7647ecSKyle Evanswhile jparams do 2586a7647ecSKyle Evans print(jparams["jid"] .. " = " .. jparams["name"]) 2596a7647ecSKyle Evans -- Subsequent calls may return nil 2606a7647ecSKyle Evans jparams = jail_obj:next() 2616a7647ecSKyle Evansend 2626a7647ecSKyle Evans.Ed 26373577bf0SRyan Moeller.Sh SEE ALSO 26473577bf0SRyan Moeller.Xr jail 2 , 26573577bf0SRyan Moeller.Xr jail 3 , 26673577bf0SRyan Moeller.Xr jail 8 26773577bf0SRyan Moeller.Sh HISTORY 26873577bf0SRyan MoellerThe 26973577bf0SRyan Moeller.Nm jail 27073577bf0SRyan MoellerLua module for flua first appeared in 27173577bf0SRyan Moeller.Fx 13.0 . 27273577bf0SRyan Moeller.Sh AUTHORS 27373577bf0SRyan Moeller.An Ryan Moeller , 27473577bf0SRyan Moellerwith inspiration from 27573577bf0SRyan Moeller.Nx 27673577bf0SRyan Moellergpio(3lua), by 27773577bf0SRyan Moeller.An Mark Balmer . 278