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 269805 2014-08-11 08:58:35Z smh $");
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, *extrap, *p, *val;
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 argc = 0;
321 val = alloca(strlen(comstring->s) + 1);
322 strcpy(val, comstring->s);
323 cs = val;
324 extrap = NULL;
325 while ((p = strchr(cs, ' ')) != NULL && strlen(p) > 1) {
326 if (extrap == NULL) {
327 *p = '\0';
328 extrap = p + 1;
329 }
330 cs = p + 1;
331 argc++;
332 }
333
334 argv = alloca((8 + argc) * sizeof(char *));
335 *(const char **)&argv[0] = _PATH_IFCONFIG;
336 if ((cs = strchr(val, '|'))) {
337 argv[1] = alloca(cs - val + 1);
338 strlcpy(argv[1], val, cs - val + 1);
339 addr = cs + 1;
340 } else {
341 *(const char **)&argv[1] =
342 string_param(j->intparams[IP_INTERFACE]);
343 addr = val;
344 }
345 *(const char **)&argv[2] = "inet";
346 if (!(cs = strchr(addr, '/'))) {
347 argv[3] = addr;
348 *(const char **)&argv[4] = "netmask";
349 *(const char **)&argv[5] = "255.255.255.255";
350 argc = 6;
351 } else if (strchr(cs + 1, '.')) {
352 argv[3] = alloca(cs - addr + 1);
353 strlcpy(argv[3], addr, cs - addr + 1);
354 *(const char **)&argv[4] = "netmask";
355 *(const char **)&argv[5] = cs + 1;
356 argc = 6;
357 } else {
358 argv[3] = addr;
359 argc = 4;
360 }
361
362 if (!down) {
363 for (cs = strtok(extrap, " "); cs; cs = strtok(NULL, " ")) {
364 size_t len = strlen(cs) + 1;
365 argv[argc] = alloca(len);
366 strlcpy(argv[argc++], cs, len);
367 }
368 }
369
370 *(const char **)&argv[argc] = down ? "-alias" : "alias";
371 argv[argc + 1] = NULL;
372 break;
373#endif
374
375#ifdef INET6
376 case IP__IP6_IFADDR:
377 argc = 0;
378 val = alloca(strlen(comstring->s) + 1);
379 strcpy(val, comstring->s);
380 cs = val;
381 extrap = NULL;
382 while ((p = strchr(cs, ' ')) != NULL && strlen(p) > 1) {
383 if (extrap == NULL) {
384 *p = '\0';
385 extrap = p + 1;
386 }
387 cs = p + 1;
388 argc++;
389 }
390
391 argv = alloca((8 + argc) * sizeof(char *));
392 *(const char **)&argv[0] = _PATH_IFCONFIG;
393 if ((cs = strchr(val, '|'))) {
394 argv[1] = alloca(cs - val + 1);
395 strlcpy(argv[1], val, cs - val + 1);
396 addr = cs + 1;
397 } else {
398 *(const char **)&argv[1] =
399 string_param(j->intparams[IP_INTERFACE]);
400 addr = val;
401 }
402 *(const char **)&argv[2] = "inet6";
403 argv[3] = addr;
404 if (!(cs = strchr(addr, '/'))) {
405 *(const char **)&argv[4] = "prefixlen";
406 *(const char **)&argv[5] = "128";
407 argc = 6;
408 } else
409 argc = 4;
410
411 if (!down) {
412 for (cs = strtok(extrap, " "); cs; cs = strtok(NULL, " ")) {
413 size_t len = strlen(cs) + 1;
414 argv[argc] = alloca(len);
415 strlcpy(argv[argc++], cs, len);
416 }
417 }
418
419 *(const char **)&argv[argc] = down ? "-alias" : "alias";
420 argv[argc + 1] = NULL;
421 break;
422#endif
423
424 case IP_VNET_INTERFACE:
425 argv = alloca(5 * sizeof(char *));
426 *(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 269805 2014-08-11 08:58:35Z smh $");
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, *extrap, *p, *val;
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 argc = 0;
321 val = alloca(strlen(comstring->s) + 1);
322 strcpy(val, comstring->s);
323 cs = val;
324 extrap = NULL;
325 while ((p = strchr(cs, ' ')) != NULL && strlen(p) > 1) {
326 if (extrap == NULL) {
327 *p = '\0';
328 extrap = p + 1;
329 }
330 cs = p + 1;
331 argc++;
332 }
333
334 argv = alloca((8 + argc) * sizeof(char *));
335 *(const char **)&argv[0] = _PATH_IFCONFIG;
336 if ((cs = strchr(val, '|'))) {
337 argv[1] = alloca(cs - val + 1);
338 strlcpy(argv[1], val, cs - val + 1);
339 addr = cs + 1;
340 } else {
341 *(const char **)&argv[1] =
342 string_param(j->intparams[IP_INTERFACE]);
343 addr = val;
344 }
345 *(const char **)&argv[2] = "inet";
346 if (!(cs = strchr(addr, '/'))) {
347 argv[3] = addr;
348 *(const char **)&argv[4] = "netmask";
349 *(const char **)&argv[5] = "255.255.255.255";
350 argc = 6;
351 } else if (strchr(cs + 1, '.')) {
352 argv[3] = alloca(cs - addr + 1);
353 strlcpy(argv[3], addr, cs - addr + 1);
354 *(const char **)&argv[4] = "netmask";
355 *(const char **)&argv[5] = cs + 1;
356 argc = 6;
357 } else {
358 argv[3] = addr;
359 argc = 4;
360 }
361
362 if (!down) {
363 for (cs = strtok(extrap, " "); cs; cs = strtok(NULL, " ")) {
364 size_t len = strlen(cs) + 1;
365 argv[argc] = alloca(len);
366 strlcpy(argv[argc++], cs, len);
367 }
368 }
369
370 *(const char **)&argv[argc] = down ? "-alias" : "alias";
371 argv[argc + 1] = NULL;
372 break;
373#endif
374
375#ifdef INET6
376 case IP__IP6_IFADDR:
377 argc = 0;
378 val = alloca(strlen(comstring->s) + 1);
379 strcpy(val, comstring->s);
380 cs = val;
381 extrap = NULL;
382 while ((p = strchr(cs, ' ')) != NULL && strlen(p) > 1) {
383 if (extrap == NULL) {
384 *p = '\0';
385 extrap = p + 1;
386 }
387 cs = p + 1;
388 argc++;
389 }
390
391 argv = alloca((8 + argc) * sizeof(char *));
392 *(const char **)&argv[0] = _PATH_IFCONFIG;
393 if ((cs = strchr(val, '|'))) {
394 argv[1] = alloca(cs - val + 1);
395 strlcpy(argv[1], val, cs - val + 1);
396 addr = cs + 1;
397 } else {
398 *(const char **)&argv[1] =
399 string_param(j->intparams[IP_INTERFACE]);
400 addr = val;
401 }
402 *(const char **)&argv[2] = "inet6";
403 argv[3] = addr;
404 if (!(cs = strchr(addr, '/'))) {
405 *(const char **)&argv[4] = "prefixlen";
406 *(const char **)&argv[5] = "128";
407 argc = 6;
408 } else
409 argc = 4;
410
411 if (!down) {
412 for (cs = strtok(extrap, " "); cs; cs = strtok(NULL, " ")) {
413 size_t len = strlen(cs) + 1;
414 argv[argc] = alloca(len);
415 strlcpy(argv[argc++], cs, len);
416 }
417 }
418
419 *(const char **)&argv[argc] = down ? "-alias" : "alias";
420 argv[argc + 1] = NULL;
421 break;
422#endif
423
424 case IP_VNET_INTERFACE:
425 argv = alloca(5 * sizeof(char *));
426 *(const char **)&argv[0] = _PATH_IFCONFIG;
--- 517 unchanged lines hidden ---