1*eac7052fSMatt Macy /*
2*eac7052fSMatt Macy * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3*eac7052fSMatt Macy * All rights reserved.
4*eac7052fSMatt Macy *
5*eac7052fSMatt Macy * Redistribution and use in source and binary forms, with or without
6*eac7052fSMatt Macy * modification, are permitted provided that the following conditions
7*eac7052fSMatt Macy * are met:
8*eac7052fSMatt Macy * 1. Redistributions of source code must retain the above copyright
9*eac7052fSMatt Macy * notice, this list of conditions and the following disclaimer.
10*eac7052fSMatt Macy * 2. Redistributions in binary form must reproduce the above copyright
11*eac7052fSMatt Macy * notice, this list of conditions and the following disclaimer in the
12*eac7052fSMatt Macy * documentation and/or other materials provided with the distribution.
13*eac7052fSMatt Macy *
14*eac7052fSMatt Macy * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15*eac7052fSMatt Macy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*eac7052fSMatt Macy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*eac7052fSMatt Macy * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18*eac7052fSMatt Macy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*eac7052fSMatt Macy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*eac7052fSMatt Macy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*eac7052fSMatt Macy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*eac7052fSMatt Macy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*eac7052fSMatt Macy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*eac7052fSMatt Macy * SUCH DAMAGE.
25*eac7052fSMatt Macy *
26*eac7052fSMatt Macy * $FreeBSD$
27*eac7052fSMatt Macy */
28*eac7052fSMatt Macy
29*eac7052fSMatt Macy #include <stdlib.h>
30*eac7052fSMatt Macy #include <assert.h>
31*eac7052fSMatt Macy #include <sys/types.h>
32*eac7052fSMatt Macy #include <sys/sysctl.h>
33*eac7052fSMatt Macy #include <zone.h>
34*eac7052fSMatt Macy
35*eac7052fSMatt Macy zoneid_t
getzoneid(void)36*eac7052fSMatt Macy getzoneid(void)
37*eac7052fSMatt Macy {
38*eac7052fSMatt Macy size_t size;
39*eac7052fSMatt Macy int jailid;
40*eac7052fSMatt Macy
41*eac7052fSMatt Macy /* Information that we are in jail or not is enough for our needs. */
42*eac7052fSMatt Macy size = sizeof (jailid);
43*eac7052fSMatt Macy if (sysctlbyname("security.jail.jailed", &jailid, &size, NULL, 0) == -1)
44*eac7052fSMatt Macy assert(!"No security.jail.jailed sysctl!");
45*eac7052fSMatt Macy return ((zoneid_t)jailid);
46*eac7052fSMatt Macy }
47