summaryrefslogtreecommitdiffstats
path: root/usr.sbin/jail/jail.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r278323:jamie2015-02-101-0/+2
| | | | | | | | | Add mount.procfs jail parameter, so procfs can be mounted when a prison's root is in its fstab. Also fix a typo while I'm at it. PR: 197237 197066
* MFC 256385:hrs2013-10-121-0/+2
| | | | | | | | | | | - Add mount.fdescfs parameter to jail(8). This is similar to mount.devfs but mounts fdescfs. The mount happens just after mount.devfs. - rc.d/jail now displays whole error message from jail(8) when a jail fails to start. Approved by: re (gjb)
* - Update rc.d/jail to use a jail(8) configuration file instead ofhrs2013-10-101-4/+6
| | | | | | | | | | | | command line options. The "jail_<jname>_*" rc.conf(5) variables for per-jail configuration are automatically converted to /var/run/jail.<jname>.conf before the jail(8) utility is invoked. This is transparently backward compatible. - Fix a minor bug in jail(8) which prevented it from returning false when jail -r failed. Approved by: re (glebius)
* Pre-separate IP addresses passed on the command line, so they can bejamie2012-08-231-2/+26
| | | | | | | | properly parsed for interface prefixes and netmask suffixes. This was already done for the old-style (fixed) command line, but missed for the new-style. MFC after: 1 week
* o Restore -u <username> getopt(3) flag somehow killed in r234712.maxim2012-06-281-1/+1
| | | | | | PR: bin/169490 Submitted by: amdmi3 MFC after: 2 weeks
* When writing the jid via the -i flag, do it right when the jail is created,jamie2012-05-281-4/+3
| | | | before any commands run. /etc/rc.d/jail depends on this.
* Add a meta-parameter IP__NULL to enum intparam, instead of mixingjamie2012-05-031-4/+4
| | | | | | enum values and zeroes. This keeps clang happy (and is just good form). Submitted by: dim
* A new jail(8) with a configuration file, ultimately to replace the workjamie2012-04-261-412/+826
|\ | | | | | | | | | | currently done by /etc/rc.d/jail. MFC after: 3 months
| * Improvements in error messages:jamie2012-02-081-7/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Some errors printed the jail name for unnamed (command line) jails. Attempting to create an already-existing jail from the command line returned with no error (even for non-root) due to bad logic in start_state. Ignore kvm_proc errors, which are typically caused by permission problems. Instead, stop ignoring permission errors when removing a jail (but continue to silently ignore other errors, i.e. the jail no longer existing). This makes non-root attempts at removing a jail give a clearer error message.
| * Allow relative pathnames for jails generated on the command linejamie2012-02-071-1/+1
| | | | | | | | (but continue to flag when from a config file).
| * Advance to the next command before running anything, so errors found injamie2011-06-221-2/+4
| | | | | | | | | | | | | | | | finish_command can be processed properly. Call failed() once in next_command() instead of multiple times in run_command(). Continue processing commands when a no-wait operation (IP__OP or background command) succeeds.
| * Following r222465:jamie2011-06-201-14/+32
| | | | | | | | | | | | Check for IPv4 or IPv6 to be available by the kernel to not provoke errors trying to query options not available. Make it possible to compile out INET or INET6 only parts.
| * Move the actual create/remove (IP__OP) handling into run_command,jamie2011-06-181-37/+6
| | | | | | | | and the cost of an ugly single-use global variable.
| * Update copyright dates and other whitespacey stuff.jamie2011-06-171-8/+8
| |
| * Split run_command up into an outer function (next_command) that choosesjamie2011-06-171-151/+88
| | | | | | | | | | | | | | | | | | a single command string to run, and an inner function (run_command) that runs that single string. Move the list of start/stop commands to run from a switch statement into an array, with a new placeholder parameter IP__OP for actually creating or removing the jail. When jail creation fails, revert all non-exec commands in reverse order.
| * Change cfstrings from an STAILQ into a TAILQ to allow commands to bejamie2011-06-171-4/+4
| | | | | | | | traversed in reverse order.
| * run_command (mostly) cleanup:jamie2010-12-101-38/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make the parallelism limit a global instead of always passing it to run_command and finish_command. In the case of an empty command string, try to run any other strings the command may have. Replace JF_BACKGROUND with its sort-of opposite JF_SLEEPQ. Change j->comstring earlier to render JF_RUNQ unncessary. Change the if-else series to a more readable switch statement. Treat IP_STOP_TIMEOUT like a command, calling run_command which then calls term_procs. When the IP_STOP_TIMEOUT "command" finishes, it shouldn't mess with the parallelism limit. Make sufficient checks in finish_command and run_command so that the nonintuitive j->comstring null check isn't necessary to run them. Rename the "waiting" queue to "depend", because the "sleeping" and "runnable" queues are also used to wait for something.
| * Check paths for security:jamie2010-11-041-0/+6
| | | | | | | | | | | | | | path must be absolute. mount paths must exist and have no symlinks beyond the jail's path itself. consolelog must exist (apart from the final component) and have no symlinks beyond the jail's path itself.
| * Reads the mount.fstab file, and put its lines separately into thejamie2010-11-041-5/+7
| | | | | | | | IP__MOUNT_FROM_FSTAB internal parameter.
| * Combine check_intparams() and ip_params(), JF_CHECKINT and JF_IPPARAMS.jamie2010-11-011-10/+4
| |
| * Don't assume either jid or name is set - they may not be from thejamie2010-10-271-4/+5
| | | | | | | | command line.
| * Keep all internal/known parameter names in one place, and usejamie2010-10-271-38/+38
| | | | | | | | enum constants everywhere else.
| * Initial work on the new jail(8). There are more features to add, and somejamie2010-10-201-385/+870
| | | | | | | | | | cleaning up to do on existing features, but this is pretty much what the final product will look like.
* | Try resolving jail path with realpath(3).mm2012-01-241-2/+8
| | | | | | | | | | | | | | | | | | jail(8) does a chdir(2) to the given path argument. Kernel evaluates the jail path from the new cwd and not from the original cwd, which leads to undesired behavior if given a relative path. Reviewed by: jamie MFC after: 2 weeks
* | Check for IPv4 or IPv6 to be available by the kernel to notbz2011-05-291-34/+42
|/ | | | | | | | | | provoke errors trying to query options not available. Make it possible to compile out INET or INET6 only parts. Reviewed by: jamie Sponsored by: The FreeBSD Foundation Sponsored by: iXsystems MFC after: 10 days
* Change the current working directory to be inside the jail created bycperciva2010-05-271-0/+4
| | | | | | | | | | | | | | the jail(8) command. [10:04] Fix a one-NUL-byte buffer overflow in libopie. [10:05] Correctly sanity-check a buffer length in nfs mount. [10:06] Approved by: so (cperciva) Approved by: re (kensmith) Security: FreeBSD-SA-10:04.jail Security: FreeBSD-SA-10:05.opie Security: FreeBSD-SA-10:06.nfsclient
* Handle kernels that don't have IPv6 by not sending an "ip6.addr"jamie2009-07-311-8/+32
| | | | | | | | parameter unless a (numeric) IPv6 address is given. Even the default binaries built with -DINET6 will work with IPv6-less kernels. With an eye to the future, similarly handle the possibility of an IPv4-less kernel. Approved by: re (kib), bz (mentor)
* Add libjail, a (somewhat) simpler interface to the jail_set and jail_getjamie2009-06-241-182/+23
| | | | | | system calls and the security.jail.param sysctls. Approved by: bz (mentor)
* Remove obsolete comment describing how the command line isjamie2009-06-231-5/+0
| | | | | | no longer parsed. Approved by: bz (mentor)
* In preparation for raising NGROUPS and NGROUPS_MAX, change basebrooks2009-06-191-2/+7
| | | | | | | | | | | | | | | | | | | | | | system callers of getgroups(), getgrouplist(), and setgroups() to allocate buffers dynamically. Specifically, allocate a buffer of size sysconf(_SC_NGROUPS_MAX)+1 (+2 in a few cases to allow for overflow). This (or similar gymnastics) is required for the code to actually follow the POSIX.1-2008 specification where {NGROUPS_MAX} may differ at runtime and where getgroups may return {NGROUPS_MAX}+1 results on systems like FreeBSD which include the primary group. In id(1), don't pointlessly add the primary group to the list of all groups, it is always the first result from getgroups(). In principle the old code was more portable, but this was only done in one of the two places where getgroups() was called to the overall effect was pointless. Document the actual POSIX requirements in the getgroups(2) and setgroups(2) manpages. We do not yet support a dynamic NGROUPS, but we may in the future. MFC after: 2 weeks
* In the old-style jail command line, explicitly set parameters from thejamie2009-06-101-2/+39
| | | | | | security.jail.* sysctls since jail_set(2) doesn't do it implicitly. Approved by: bz (mentor)
* Add support for the arbitrary named jail parameters used by jail_set(2)jamie2009-05-271-230/+456
| | | | | | | | | | | | | | and jail_get(2). Jail(8) can now create jails using a "name=value" format instead of just specifying a limited set of fixed parameters; it can also modify parameters of existing jails. Jls(8) can display all parameters of jails, or a specified set of parameters. The available parameters are gathered from the kernel, and not hard-coded into these programs. Small patches on killall(1) and jexec(8) to support jail names with jail_get(2). Approved by: bz (mentor)
* With the permission of phk@ change the license on remaining jail codejamie2009-04-291-7/+24
| | | | | | | to a 2 clause BSD license. Approved by: phk Approved by: bz (mentor)
* MFp4:bz2008-11-291-15/+237
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bring in updated jail support from bz_jail branch. This enhances the current jail implementation to permit multiple addresses per jail. In addtion to IPv4, IPv6 is supported as well. Due to updated checks it is even possible to have jails without an IP address at all, which basically gives one a chroot with restricted process view, no networking,.. SCTP support was updated and supports IPv6 in jails as well. Cpuset support permits jails to be bound to specific processor sets after creation. Jails can have an unrestricted (no duplicate protection, etc.) name in addition to the hostname. The jail name cannot be changed from within a jail and is considered to be used for management purposes or as audit-token in the future. DDB 'show jails' command was added to aid debugging. Proper compat support permits 32bit jail binaries to be used on 64bit systems to manage jails. Also backward compatibility was preserved where possible: for jail v1 syscalls, as well as with user space management utilities. Both jail as well as prison version were updated for the new features. A gap was intentionally left as the intermediate versions had been used by various patches floating around the last years. Bump __FreeBSD_version for the afore mentioned and in kernel changes. Special thanks to: - Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches and Olivier Houchard (cognet) for initial single-IPv6 patches. - Jeff Roberson (jeff) and Randall Stewart (rrs) for their help, ideas and review on cpuset and SCTP support. - Robert Watson (rwatson) for lots and lots of help, discussions, suggestions and review of most of the patch at various stages. - John Baldwin (jhb) for his help. - Simon L. Nielsen (simon) as early adopter testing changes on cluster machines as well as all the testers and people who provided feedback the last months on freebsd-jail and other channels. - My employer, CK Software GmbH, for the support so I could work on this. Reviewed by: (see above) MFC after: 3 months (this is just so that I get the mail) X-MFC Before: 7.2-RELEASE if possible
* correct strtol(3) usage and style(9)matteo2006-05-121-4/+8
| | | | | Reviewed by: maxim MFC after: 2 weeks
* o Style(9) the previous commit a bit.maxim2006-05-111-13/+7
|
* Add the -s option to set jail's securelevel. This is useful for jails run ↵matteo2006-05-111-3/+20
| | | | | | | with non-root privileges. PR: bin/80242 MFC after: 2 weeks
* o Do not mangle current session user login name with jail -u|-U.maxim2006-04-161-1/+1
| | | | | | PR: bin/94730 Submitted by: Frank Behrens MFC after: 1 month
* Add [-J jid_file] option to write out a JidFile, similar to a PidFile,philip2005-12-031-6/+26
| | | | | | | | | | containing the jailid, path, hostname, ip and the command used to start the jail. PR: misc/89883 Submitted by: L. Jason Godsey <lannygodsey -at- yahoo.com> Reviewed by: phk MFC after: 1 week
* Initialize lcap and pwd to NULL. This allows a WARNS=6 clean build,delphij2004-11-171-2/+2
| | | | | | | | | hence bump it to 6. Note that the last commit message was not quite accurate. While the assumption exists in the code, it's not possible to have an uninitialized p there because if lflag is set when username is NULL then execution would be terminated earlier.
* The code path in main() dealing with lflag assumes that p wasdelphij2004-11-171-1/+1
| | | | | initialized with NULL, while it is not. So let's initialize it.
* Pass an array of gid_t rather than an array of int to getgroups().stefanf2004-10-021-1/+2
| | | | PR: 56646
* o Add -l option to jail(8) similar to su(1): before running jail'edmaxim2004-08-151-5/+31
| | | | | | | | | program under specific user's credentials, clean the environment and set only a few variables. PR: bin/70024 Submitted by: demon MFC after: 1 month
* Prepare jail(8) utility for new functionality which will limitpjd2004-06-271-4/+6
| | | | | | seeing status of mounted file system for jailed processes. Pass full path of jail's root directory to the kernel. mount(8) utility is doing the same thing already.
* o Implement -U flag: run command as user which exists only in jail.maxim2004-05-291-17/+34
| | | | | | | | | o getpwnam(3) returns NULL and does not set errno when the user does not exist. Bail out with "no such user" instead of "Unknown error: 0". PR: bin/67262 Submitted by: demon (-U flag) MFC after: 3 weeks
* add FBSDIDcharnier2003-07-061-3/+3
|
* Force output of jail ID (if necessary) before excuting the command,mike2003-04-211-1/+3
| | | | | otherwise redirection of stdout to a file using block buffering will not complete in time.
* o Add jls(8) for listing active jails.mike2003-04-091-7/+14
| | | | | | | o Add jexec(8) to execute a command in an existing jail. o Add -j option for killall(1) to kill all processes in a specified jail. o Add -i option to jail(8) to output jail ID of newly created jail.
* Free login_cap(3) resources after usage.maxim2003-04-071-0/+1
| | | | Submitted by: demon
* o Fix error messages formatting, style.maxim2003-04-021-29/+22
| | | | | Prodded by: bde Reviewed by: bde
OpenPOWER on IntegriCloud