jls.c (195462) | jls.c (195870) |
---|---|
1/*- 2 * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> 3 * Copyright (c) 2008 Bjoern A. Zeeb <bz@FreeBSD.org> 4 * Copyright (c) 2009 James Gritton <jamie@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 13 unchanged lines hidden (view full) --- 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 26 * SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> 3 * Copyright (c) 2008 Bjoern A. Zeeb <bz@FreeBSD.org> 4 * Copyright (c) 2009 James Gritton <jamie@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 13 unchanged lines hidden (view full) --- 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 26 * SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/usr.sbin/jls/jls.c 195462 2009-07-08 15:57:22Z jamie $"); | 30__FBSDID("$FreeBSD: head/usr.sbin/jls/jls.c 195870 2009-07-25 14:48:57Z jamie $"); |
31 32#include <sys/param.h> 33#include <sys/jail.h> 34#include <sys/socket.h> 35#include <sys/sysctl.h> 36 37#include <arpa/inet.h> 38#include <netinet/in.h> --- 13 unchanged lines hidden (view full) --- 52#define PRINT_DEFAULT 0x01 53#define PRINT_HEADER 0x02 54#define PRINT_NAMEVAL 0x04 55#define PRINT_QUOTED 0x08 56#define PRINT_SKIP 0x10 57#define PRINT_VERBOSE 0x20 58 59static struct jailparam *params; | 31 32#include <sys/param.h> 33#include <sys/jail.h> 34#include <sys/socket.h> 35#include <sys/sysctl.h> 36 37#include <arpa/inet.h> 38#include <netinet/in.h> --- 13 unchanged lines hidden (view full) --- 52#define PRINT_DEFAULT 0x01 53#define PRINT_HEADER 0x02 54#define PRINT_NAMEVAL 0x04 55#define PRINT_QUOTED 0x08 56#define PRINT_SKIP 0x10 57#define PRINT_VERBOSE 0x20 58 59static struct jailparam *params; |
60static int *param_noparent; | 60static int *param_parent; |
61static int nparams; 62 63static int add_param(const char *name, void *value, size_t valuelen, 64 struct jailparam *source, unsigned flags); 65static int sort_param(const void *a, const void *b); 66static char *noname(const char *name); 67static char *nononame(const char *name); 68static int print_jail(int pflags, int jflags); 69static void quoted_print(char *str); 70 71int 72main(int argc, char **argv) 73{ | 61static int nparams; 62 63static int add_param(const char *name, void *value, size_t valuelen, 64 struct jailparam *source, unsigned flags); 65static int sort_param(const void *a, const void *b); 66static char *noname(const char *name); 67static char *nononame(const char *name); 68static int print_jail(int pflags, int jflags); 69static void quoted_print(char *str); 70 71int 72main(int argc, char **argv) 73{ |
74 char *dot, *ep, *jname, *nname; | 74 char *dot, *ep, *jname; |
75 int c, i, jflags, jid, lastjid, pflags, spc; 76 77 jname = NULL; 78 pflags = jflags = jid = 0; 79 while ((c = getopt(argc, argv, "adj:hnqsv")) >= 0) 80 switch (c) { 81 case 'a': 82 case 'd': --- 51 unchanged lines hidden (view full) --- 134 add_param("path", NULL, (size_t)0, NULL, JP_USER); 135 } 136 } else 137 while (optind < argc) 138 add_param(argv[optind++], NULL, (size_t)0, NULL, 139 JP_USER); 140 141 if (pflags & PRINT_SKIP) { | 75 int c, i, jflags, jid, lastjid, pflags, spc; 76 77 jname = NULL; 78 pflags = jflags = jid = 0; 79 while ((c = getopt(argc, argv, "adj:hnqsv")) >= 0) 80 switch (c) { 81 case 'a': 82 case 'd': --- 51 unchanged lines hidden (view full) --- 134 add_param("path", NULL, (size_t)0, NULL, JP_USER); 135 } 136 } else 137 while (optind < argc) 138 add_param(argv[optind++], NULL, (size_t)0, NULL, 139 JP_USER); 140 141 if (pflags & PRINT_SKIP) { |
142 /* Check for parameters with boolean parents. */ | 142 /* Check for parameters with jailsys parents. */ |
143 for (i = 0; i < nparams; i++) { 144 if ((params[i].jp_flags & JP_USER) && 145 (dot = strchr(params[i].jp_name, '.'))) { 146 *dot = 0; | 143 for (i = 0; i < nparams; i++) { 144 if ((params[i].jp_flags & JP_USER) && 145 (dot = strchr(params[i].jp_name, '.'))) { 146 *dot = 0; |
147 nname = noname(params[i].jp_name); | 147 param_parent[i] = add_param(params[i].jp_name, 148 NULL, (size_t)0, NULL, JP_OPT); |
148 *dot = '.'; | 149 *dot = '.'; |
149 param_noparent[i] = 150 add_param(nname, NULL, (size_t)0, NULL, 151 JP_OPT); 152 free(nname); | |
153 } 154 } 155 } 156 157 /* Add the index key parameters. */ 158 if (jid != 0) 159 add_param("jid", &jid, sizeof(jid), NULL, 0); 160 else if (jname != NULL) --- 71 unchanged lines hidden (view full) --- 232 jailparam_free(source, 1); 233 return i; 234 } 235 236 /* Make sure there is room for the new param record. */ 237 if (!nparams) { 238 paramlistsize = 32; 239 params = malloc(paramlistsize * sizeof(*params)); | 150 } 151 } 152 } 153 154 /* Add the index key parameters. */ 155 if (jid != 0) 156 add_param("jid", &jid, sizeof(jid), NULL, 0); 157 else if (jname != NULL) --- 71 unchanged lines hidden (view full) --- 229 jailparam_free(source, 1); 230 return i; 231 } 232 233 /* Make sure there is room for the new param record. */ 234 if (!nparams) { 235 paramlistsize = 32; 236 params = malloc(paramlistsize * sizeof(*params)); |
240 param_noparent = 241 malloc(paramlistsize * sizeof(*param_noparent)); 242 if (params == NULL || param_noparent == NULL) | 237 param_parent = malloc(paramlistsize * sizeof(*param_parent)); 238 if (params == NULL || param_parent == NULL) |
243 err(1, "malloc"); 244 } else if (nparams >= paramlistsize) { 245 paramlistsize *= 2; 246 params = realloc(params, paramlistsize * sizeof(*params)); | 239 err(1, "malloc"); 240 } else if (nparams >= paramlistsize) { 241 paramlistsize *= 2; 242 params = realloc(params, paramlistsize * sizeof(*params)); |
247 param_noparent = realloc(param_noparent, 248 paramlistsize * sizeof(*param_noparent)); 249 if (params == NULL || param_noparent == NULL) | 243 param_parent = realloc(param_parent, 244 paramlistsize * sizeof(*param_parent)); 245 if (params == NULL || param_parent == NULL) |
250 err(1, "realloc"); 251 } 252 253 /* Look up the parameter. */ | 246 err(1, "realloc"); 247 } 248 249 /* Look up the parameter. */ |
254 param_noparent[nparams] = -1; | 250 param_parent[nparams] = -1; |
255 param = params + nparams++; 256 if (source != NULL) { 257 *param = *source; 258 param->jp_flags |= flags; 259 return param - params; 260 } 261 if (jailparam_init(param, name) < 0) 262 errx(1, "%s", jail_errmsg); --- 119 unchanged lines hidden (view full) --- 382 errx(1, "%s", jail_errmsg); 383 } 384 for (i = spc = 0; i < nparams; i++) { 385 if (!(params[i].jp_flags & JP_USER)) 386 continue; 387 if ((pflags & PRINT_SKIP) && 388 ((!(params[i].jp_ctltype & 389 (CTLFLAG_WR | CTLFLAG_TUN))) || | 251 param = params + nparams++; 252 if (source != NULL) { 253 *param = *source; 254 param->jp_flags |= flags; 255 return param - params; 256 } 257 if (jailparam_init(param, name) < 0) 258 errx(1, "%s", jail_errmsg); --- 119 unchanged lines hidden (view full) --- 378 errx(1, "%s", jail_errmsg); 379 } 380 for (i = spc = 0; i < nparams; i++) { 381 if (!(params[i].jp_flags & JP_USER)) 382 continue; 383 if ((pflags & PRINT_SKIP) && 384 ((!(params[i].jp_ctltype & 385 (CTLFLAG_WR | CTLFLAG_TUN))) || |
390 (param_noparent[i] >= 0 && 391 *(int *)params[param_noparent[i]].jp_value))) | 386 (param_parent[i] >= 0 && 387 *(int *)params[param_parent[i]].jp_value != 388 JAIL_SYS_NEW))) |
392 continue; 393 if (spc) 394 putchar(' '); 395 else 396 spc = 1; 397 if (pflags & PRINT_NAMEVAL) { 398 /* 399 * Generally "name=value", but for booleans --- 69 unchanged lines hidden --- | 389 continue; 390 if (spc) 391 putchar(' '); 392 else 393 spc = 1; 394 if (pflags & PRINT_NAMEVAL) { 395 /* 396 * Generally "name=value", but for booleans --- 69 unchanged lines hidden --- |