1/*-
2 * Copyright (c) 2011 James Gritton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 11 unchanged lines hidden (view full) ---
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
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: stable/10/usr.sbin/jail/command.c 256387 2013-10-12 17:46:13Z hrs $");
29
30#include <sys/types.h>
31#include <sys/event.h>
32#include <sys/mount.h>
33#include <sys/stat.h>
34#include <sys/sysctl.h>
35#include <sys/user.h>
36#include <sys/wait.h>
--- 226 unchanged lines hidden (view full) ---
263 char **argv;
264 char *cs, *comcs, *devpath;
265 const char *jidstr, *conslog, *path, *ruleset, *term, *username;
266 enum intparam comparam;
267 size_t comlen;
268 pid_t pid;
269 int argc, bg, clean, consfd, down, fib, i, injail, sjuser, timeout;
270#if defined(INET) || defined(INET6)
271 char *addr;
272#endif
273
274 static char *cleanenv;
275
276 /* Perform some operations that aren't actually commands */
277 comparam = *j->comparam;
278 down = j->flags & (JF_STOP | JF_FAILED);
279 switch (comparam) {
--- 32 unchanged lines hidden (view full) ---
312 * Collect exec arguments. Internal commands for network and
313 * mounting build their own argument lists.
314 */
315 comstring = j->comstring;
316 bg = 0;
317 switch (comparam) {
318#ifdef INET
319 case IP__IP4_IFADDR:
320 argv = alloca(8 * sizeof(char *));
321 *(const char **)&argv[0] = _PATH_IFCONFIG;
322 if ((cs = strchr(comstring->s, '|'))) {
323 argv[1] = alloca(cs - comstring->s + 1);
324 strlcpy(argv[1], comstring->s, cs - comstring->s + 1);
325 addr = cs + 1;
326 } else {
327 *(const char **)&argv[1] =
328 string_param(j->intparams[IP_INTERFACE]);
329 addr = comstring->s;
330 }
331 *(const char **)&argv[2] = "inet";
332 if (!(cs = strchr(addr, '/'))) {
333 argv[3] = addr;
334 *(const char **)&argv[4] = "netmask";
335 *(const char **)&argv[5] = "255.255.255.255";
336 argc = 6;
337 } else if (strchr(cs + 1, '.')) {
338 argv[3] = alloca(cs - addr + 1);
339 strlcpy(argv[3], addr, cs - addr + 1);
340 *(const char **)&argv[4] = "netmask";
341 *(const char **)&argv[5] = cs + 1;
342 argc = 6;
343 } else {
344 argv[3] = addr;
345 argc = 4;
346 }
347 *(const char **)&argv[argc] = down ? "-alias" : "alias";
348 argv[argc + 1] = NULL;
349 break;
350#endif
351
352#ifdef INET6
353 case IP__IP6_IFADDR:
354 argv = alloca(8 * sizeof(char *));
355 *(const char **)&argv[0] = _PATH_IFCONFIG;
356 if ((cs = strchr(comstring->s, '|'))) {
357 argv[1] = alloca(cs - comstring->s + 1);
358 strlcpy(argv[1], comstring->s, cs - comstring->s + 1);
359 addr = cs + 1;
360 } else {
361 *(const char **)&argv[1] =
362 string_param(j->intparams[IP_INTERFACE]);
363 addr = comstring->s;
364 }
365 *(const char **)&argv[2] = "inet6";
366 argv[3] = addr;
367 if (!(cs = strchr(addr, '/'))) {
368 *(const char **)&argv[4] = "prefixlen";
369 *(const char **)&argv[5] = "128";
370 argc = 6;
371 } else
372 argc = 4;
373 *(const char **)&argv[argc] = down ? "-alias" : "alias";
374 argv[argc + 1] = NULL;
375 break;
376#endif
377
378 case IP_VNET_INTERFACE:
379 argv = alloca(5 * sizeof(char *));
380 *(const char **)&argv[0] = _PATH_IFCONFIG;
--- 517 unchanged lines hidden ---
2 * Copyright (c) 2011 James Gritton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 11 unchanged lines hidden (view full) ---
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
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: stable/10/usr.sbin/jail/command.c 256387 2013-10-12 17:46:13Z hrs $");
29
30#include <sys/types.h>
31#include <sys/event.h>
32#include <sys/mount.h>
33#include <sys/stat.h>
34#include <sys/sysctl.h>
35#include <sys/user.h>
36#include <sys/wait.h>
--- 226 unchanged lines hidden (view full) ---
263 char **argv;
264 char *cs, *comcs, *devpath;
265 const char *jidstr, *conslog, *path, *ruleset, *term, *username;
266 enum intparam comparam;
267 size_t comlen;
268 pid_t pid;
269 int argc, bg, clean, consfd, down, fib, i, injail, sjuser, timeout;
270#if defined(INET) || defined(INET6)
271 char *addr;
272#endif
273
274 static char *cleanenv;
275
276 /* Perform some operations that aren't actually commands */
277 comparam = *j->comparam;
278 down = j->flags & (JF_STOP | JF_FAILED);
279 switch (comparam) {
--- 32 unchanged lines hidden (view full) ---
312 * Collect exec arguments. Internal commands for network and
313 * mounting build their own argument lists.
314 */
315 comstring = j->comstring;
316 bg = 0;
317 switch (comparam) {
318#ifdef INET
319 case IP__IP4_IFADDR:
320 argv = alloca(8 * sizeof(char *));
321 *(const char **)&argv[0] = _PATH_IFCONFIG;
322 if ((cs = strchr(comstring->s, '|'))) {
323 argv[1] = alloca(cs - comstring->s + 1);
324 strlcpy(argv[1], comstring->s, cs - comstring->s + 1);
325 addr = cs + 1;
326 } else {
327 *(const char **)&argv[1] =
328 string_param(j->intparams[IP_INTERFACE]);
329 addr = comstring->s;
330 }
331 *(const char **)&argv[2] = "inet";
332 if (!(cs = strchr(addr, '/'))) {
333 argv[3] = addr;
334 *(const char **)&argv[4] = "netmask";
335 *(const char **)&argv[5] = "255.255.255.255";
336 argc = 6;
337 } else if (strchr(cs + 1, '.')) {
338 argv[3] = alloca(cs - addr + 1);
339 strlcpy(argv[3], addr, cs - addr + 1);
340 *(const char **)&argv[4] = "netmask";
341 *(const char **)&argv[5] = cs + 1;
342 argc = 6;
343 } else {
344 argv[3] = addr;
345 argc = 4;
346 }
347 *(const char **)&argv[argc] = down ? "-alias" : "alias";
348 argv[argc + 1] = NULL;
349 break;
350#endif
351
352#ifdef INET6
353 case IP__IP6_IFADDR:
354 argv = alloca(8 * sizeof(char *));
355 *(const char **)&argv[0] = _PATH_IFCONFIG;
356 if ((cs = strchr(comstring->s, '|'))) {
357 argv[1] = alloca(cs - comstring->s + 1);
358 strlcpy(argv[1], comstring->s, cs - comstring->s + 1);
359 addr = cs + 1;
360 } else {
361 *(const char **)&argv[1] =
362 string_param(j->intparams[IP_INTERFACE]);
363 addr = comstring->s;
364 }
365 *(const char **)&argv[2] = "inet6";
366 argv[3] = addr;
367 if (!(cs = strchr(addr, '/'))) {
368 *(const char **)&argv[4] = "prefixlen";
369 *(const char **)&argv[5] = "128";
370 argc = 6;
371 } else
372 argc = 4;
373 *(const char **)&argv[argc] = down ? "-alias" : "alias";
374 argv[argc + 1] = NULL;
375 break;
376#endif
377
378 case IP_VNET_INTERFACE:
379 argv = alloca(5 * sizeof(char *));
380 *(const char **)&argv[0] = _PATH_IFCONFIG;
--- 517 unchanged lines hidden ---