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