示例#1
0
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;
}
示例#2
0
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(&params[psize], "lastjid");
	jailparam_import_raw(&params[psize++], &lastjid, sizeof lastjid);

	jailparam_init(&params[psize], "vnet");
	jailparam_import_raw(&params[psize++], &vs->vnet, sizeof(vs->vnet));

	jailparam_init(&params[psize], "name");
	jailparam_import_raw(&params[psize++], &vs->name, sizeof(vs->name));

	if (verbose == 0)
		goto done;

	jailparam_init(&params[psize], "path");
	jailparam_import_raw(&params[psize++], &vs->path, sizeof(vs->path));

	jailparam_init(&params[psize], "host.hostname");
	jailparam_import_raw(&params[psize++], &vs->hostname,
	    sizeof(vs->hostname));

	jailparam_init(&params[psize], "host.domainname");
	jailparam_import_raw(&params[psize++], &vs->domainname,
	    sizeof(vs->domainname));

	jailparam_init(&params[psize], "children.cur");
	jailparam_import_raw(&params[psize++], &vs->childcnt,
	    sizeof(vs->childcnt));

	if (verbose == 1)
		goto done;

	jailparam_init(&params[psize], "children.max");
	jailparam_import_raw(&params[psize++], &vs->childmax,
	    sizeof(vs->childmax));

	jailparam_init(&params[psize], "cpuset.id");
	jailparam_import_raw(&params[psize++], &vs->cpuset,
	    sizeof(vs->cpuset));

	jailparam_init(&params[psize], "parent");
	jailparam_import_raw(&params[psize++], &vs->parentjid,
	    sizeof(vs->parentjid));

	jailparam_init(&params[psize], "allow.raw_sockets");
	jailparam_import_raw(&params[psize++], &vs->rawsock,
	    sizeof(vs->rawsock));

	jailparam_init(&params[psize], "allow.socket_af");
	jailparam_import_raw(&params[psize++], &vs->socket_af,
	    sizeof(vs->socket_af));

	jailparam_init(&params[psize], "allow.mount");
	jailparam_import_raw(&params[psize++], &vs->mount, sizeof(vs->mount));

done:
	vs->jid = jailparam_get(params, psize, 0);
	jailparam_free(params, psize);
	return (vs->jid);
}