static int add_param(const char *name, void *value, size_t valuelen, struct jailparam *source, unsigned flags) { struct jailparam *param, *tparams; int i, tnparams; static int paramlistsize; /* The pseudo-parameter "all" scans the list of available parameters. */ if (!strcmp(name, "all")) { tnparams = jailparam_all(&tparams); if (tnparams < 0) xo_errx(1, "%s", jail_errmsg); qsort(tparams, (size_t)tnparams, sizeof(struct jailparam), sort_param); for (i = 0; i < tnparams; i++) add_param(tparams[i].jp_name, NULL, (size_t)0, tparams + i, flags); free(tparams); return -1; } /* Check for repeat parameters. */ for (i = 0; i < nparams; i++) if (!strcmp(name, params[i].jp_name)) { if (value != NULL && jailparam_import_raw(params + i, value, valuelen) < 0) xo_errx(1, "%s", jail_errmsg); params[i].jp_flags |= flags; if (source != NULL) jailparam_free(source, 1); return i; } /* Make sure there is room for the new param record. */ if (!nparams) { paramlistsize = 32; params = malloc(paramlistsize * sizeof(*params)); param_parent = malloc(paramlistsize * sizeof(*param_parent)); if (params == NULL || param_parent == NULL) xo_err(1, "malloc"); } else if (nparams >= paramlistsize) { paramlistsize *= 2; params = realloc(params, paramlistsize * sizeof(*params)); param_parent = realloc(param_parent, paramlistsize * sizeof(*param_parent)); if (params == NULL || param_parent == NULL) xo_err(1, "realloc"); } /* Look up the parameter. */ param_parent[nparams] = -1; param = params + nparams++; if (source != NULL) { *param = *source; param->jp_flags |= flags; return param - params; } if (jailparam_init(param, name) < 0 || (value != NULL ? jailparam_import_raw(param, value, valuelen) : jailparam_import(param, value)) < 0) { if (flags & JP_OPT) { nparams--; return (-1); } xo_errx(1, "%s", jail_errmsg); } param->jp_flags = flags; return param - params; }
static int getjail(vstat_t *vs, int lastjid, int verbose) { struct jailparam params[32]; /* Must be > max(psize). */ int psize = 0; bzero(params, sizeof(params)); bzero(vs, sizeof(*vs)); jailparam_init(¶ms[psize], "lastjid"); jailparam_import_raw(¶ms[psize++], &lastjid, sizeof lastjid); jailparam_init(¶ms[psize], "vnet"); jailparam_import_raw(¶ms[psize++], &vs->vnet, sizeof(vs->vnet)); jailparam_init(¶ms[psize], "name"); jailparam_import_raw(¶ms[psize++], &vs->name, sizeof(vs->name)); if (verbose == 0) goto done; jailparam_init(¶ms[psize], "path"); jailparam_import_raw(¶ms[psize++], &vs->path, sizeof(vs->path)); jailparam_init(¶ms[psize], "host.hostname"); jailparam_import_raw(¶ms[psize++], &vs->hostname, sizeof(vs->hostname)); jailparam_init(¶ms[psize], "host.domainname"); jailparam_import_raw(¶ms[psize++], &vs->domainname, sizeof(vs->domainname)); jailparam_init(¶ms[psize], "children.cur"); jailparam_import_raw(¶ms[psize++], &vs->childcnt, sizeof(vs->childcnt)); if (verbose == 1) goto done; jailparam_init(¶ms[psize], "children.max"); jailparam_import_raw(¶ms[psize++], &vs->childmax, sizeof(vs->childmax)); jailparam_init(¶ms[psize], "cpuset.id"); jailparam_import_raw(¶ms[psize++], &vs->cpuset, sizeof(vs->cpuset)); jailparam_init(¶ms[psize], "parent"); jailparam_import_raw(¶ms[psize++], &vs->parentjid, sizeof(vs->parentjid)); jailparam_init(¶ms[psize], "allow.raw_sockets"); jailparam_import_raw(¶ms[psize++], &vs->rawsock, sizeof(vs->rawsock)); jailparam_init(¶ms[psize], "allow.socket_af"); jailparam_import_raw(¶ms[psize++], &vs->socket_af, sizeof(vs->socket_af)); jailparam_init(¶ms[psize], "allow.mount"); jailparam_import_raw(¶ms[psize++], &vs->mount, sizeof(vs->mount)); done: vs->jid = jailparam_get(params, psize, 0); jailparam_free(params, psize); return (vs->jid); }