command.c (256387) | command.c (269805) |
---|---|
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> | 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 $"); | 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) | 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; | 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: | 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 *)); | 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 *)); |
321 *(const char **)&argv[0] = _PATH_IFCONFIG; | 335 *(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); | 336 if ((cs = strchr(val, '|'))) { 337 argv[1] = alloca(cs - val + 1); 338 strlcpy(argv[1], val, cs - val + 1); |
325 addr = cs + 1; 326 } else { 327 *(const char **)&argv[1] = 328 string_param(j->intparams[IP_INTERFACE]); | 339 addr = cs + 1; 340 } else { 341 *(const char **)&argv[1] = 342 string_param(j->intparams[IP_INTERFACE]); |
329 addr = comstring->s; | 343 addr = val; |
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 } | 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 |
|
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: | 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: |
354 argv = alloca(8 * sizeof(char *)); | 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 *)); |
355 *(const char **)&argv[0] = _PATH_IFCONFIG; | 392 *(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); | 393 if ((cs = strchr(val, '|'))) { 394 argv[1] = alloca(cs - val + 1); 395 strlcpy(argv[1], val, cs - val + 1); |
359 addr = cs + 1; 360 } else { 361 *(const char **)&argv[1] = 362 string_param(j->intparams[IP_INTERFACE]); | 396 addr = cs + 1; 397 } else { 398 *(const char **)&argv[1] = 399 string_param(j->intparams[IP_INTERFACE]); |
363 addr = comstring->s; | 400 addr = val; |
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; | 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 |
|
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 --- | 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 --- |