2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2009 James Gritton.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/types.h>
46 * Return the JID corresponding to a jail name.
49 jail_getid(const char *name)
55 jid = strtoul(name, &ep, 10);
58 jiov[0].iov_base = __DECONST(char *, "name");
59 jiov[0].iov_len = sizeof("name");
60 jiov[1].iov_len = strlen(name) + 1;
61 jiov[1].iov_base = alloca(jiov[1].iov_len);
62 strcpy(jiov[1].iov_base, name);
63 jiov[2].iov_base = __DECONST(char *, "errmsg");
64 jiov[2].iov_len = sizeof("errmsg");
65 jiov[3].iov_base = jail_errmsg;
66 jiov[3].iov_len = JAIL_ERRMSGLEN;
68 jid = jail_get(jiov, 4, 0);
69 if (jid < 0 && !jail_errmsg[0])
70 snprintf(jail_errmsg, JAIL_ERRMSGLEN, "jail_get: %s",
76 * Return the name corresponding to a JID.
83 char namebuf[MAXHOSTNAMELEN];
85 jiov[0].iov_base = __DECONST(char *, "jid");
86 jiov[0].iov_len = sizeof("jid");
87 jiov[1].iov_base = &jid;
88 jiov[1].iov_len = sizeof(jid);
89 jiov[2].iov_base = __DECONST(char *, "name");
90 jiov[2].iov_len = sizeof("name");
91 jiov[3].iov_base = namebuf;
92 jiov[3].iov_len = sizeof(namebuf);
93 jiov[4].iov_base = __DECONST(char *, "errmsg");
94 jiov[4].iov_len = sizeof("errmsg");
95 jiov[5].iov_base = jail_errmsg;
96 jiov[5].iov_len = JAIL_ERRMSGLEN;
98 jid = jail_get(jiov, 6, 0);
101 snprintf(jail_errmsg, JAIL_ERRMSGLEN, "jail_get: %s",
105 name = strdup(namebuf);
107 strerror_r(errno, jail_errmsg, JAIL_ERRMSGLEN);