static bool pwd_allowed_field(const nvlist_t *limits, const char *field) { if (limits == NULL) return (true); /* * If no limit was set on allowed fields, then all fields are allowed. */ if (!nvlist_exists_nvlist(limits, "fields")) return (true); limits = nvlist_get_nvlist(limits, "fields"); return (nvlist_exists_null(limits, field)); }
static bool pwd_allowed_cmd(const nvlist_t *limits, const char *cmd) { if (limits == NULL) return (true); /* * If no limit was set on allowed commands, then all commands * are allowed. */ if (!nvlist_exists_nvlist(limits, "cmds")) return (true); limits = nvlist_get_nvlist(limits, "cmds"); return (nvlist_exists_null(limits, cmd)); }
int main(void) { nvlist_t *nvl; printf("1..232\n"); nvl = nvlist_create(0); CHECK(!nvlist_exists(nvl, "nvlist/null")); CHECK(!nvlist_exists_null(nvl, "nvlist/null")); CHECK(!nvlist_exists_bool(nvl, "nvlist/null")); CHECK(!nvlist_exists_number(nvl, "nvlist/null")); CHECK(!nvlist_exists_string(nvl, "nvlist/null")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/null")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/null")); CHECK(!nvlist_exists_binary(nvl, "nvlist/null")); nvlist_add_null(nvl, "nvlist/null"); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists(nvl, "nvlist/null")); CHECK(nvlist_exists_null(nvl, "nvlist/null")); CHECK(!nvlist_exists_bool(nvl, "nvlist/null")); CHECK(!nvlist_exists_number(nvl, "nvlist/null")); CHECK(!nvlist_exists_string(nvl, "nvlist/null")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/null")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/null")); CHECK(!nvlist_exists_binary(nvl, "nvlist/null")); CHECK(!nvlist_exists(nvl, "nvlist/bool")); CHECK(!nvlist_exists_null(nvl, "nvlist/bool")); CHECK(!nvlist_exists_bool(nvl, "nvlist/bool")); CHECK(!nvlist_exists_number(nvl, "nvlist/bool")); CHECK(!nvlist_exists_string(nvl, "nvlist/bool")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/bool")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/bool")); CHECK(!nvlist_exists_binary(nvl, "nvlist/bool")); nvlist_add_bool(nvl, "nvlist/bool", true); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists(nvl, "nvlist/bool")); CHECK(!nvlist_exists_null(nvl, "nvlist/bool")); CHECK(nvlist_exists_bool(nvl, "nvlist/bool")); CHECK(!nvlist_exists_number(nvl, "nvlist/bool")); CHECK(!nvlist_exists_string(nvl, "nvlist/bool")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/bool")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/bool")); CHECK(!nvlist_exists_binary(nvl, "nvlist/bool")); CHECK(!nvlist_exists(nvl, "nvlist/number")); CHECK(!nvlist_exists_null(nvl, "nvlist/number")); CHECK(!nvlist_exists_bool(nvl, "nvlist/number")); CHECK(!nvlist_exists_number(nvl, "nvlist/number")); CHECK(!nvlist_exists_string(nvl, "nvlist/number")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/number")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/number")); CHECK(!nvlist_exists_binary(nvl, "nvlist/number")); nvlist_add_number(nvl, "nvlist/number", 0); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists(nvl, "nvlist/number")); CHECK(!nvlist_exists_null(nvl, "nvlist/number")); CHECK(!nvlist_exists_bool(nvl, "nvlist/number")); CHECK(nvlist_exists_number(nvl, "nvlist/number")); CHECK(!nvlist_exists_string(nvl, "nvlist/number")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/number")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/number")); CHECK(!nvlist_exists_binary(nvl, "nvlist/number")); CHECK(!nvlist_exists(nvl, "nvlist/string")); CHECK(!nvlist_exists_null(nvl, "nvlist/string")); CHECK(!nvlist_exists_bool(nvl, "nvlist/string")); CHECK(!nvlist_exists_number(nvl, "nvlist/string")); CHECK(!nvlist_exists_string(nvl, "nvlist/string")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/string")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/string")); CHECK(!nvlist_exists_binary(nvl, "nvlist/string")); nvlist_add_string(nvl, "nvlist/string", "test"); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists(nvl, "nvlist/string")); CHECK(!nvlist_exists_null(nvl, "nvlist/string")); CHECK(!nvlist_exists_bool(nvl, "nvlist/string")); CHECK(!nvlist_exists_number(nvl, "nvlist/string")); CHECK(nvlist_exists_string(nvl, "nvlist/string")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/string")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/string")); CHECK(!nvlist_exists_binary(nvl, "nvlist/string")); CHECK(!nvlist_exists(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_null(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_bool(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_number(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_string(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_binary(nvl, "nvlist/nvlist")); nvlist_add_nvlist(nvl, "nvlist/nvlist", nvl); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_null(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_bool(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_number(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_string(nvl, "nvlist/nvlist")); CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_binary(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_null(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_bool(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_number(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_string(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_binary(nvl, "nvlist/descriptor")); nvlist_add_descriptor(nvl, "nvlist/descriptor", STDERR_FILENO); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_null(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_bool(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_number(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_string(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/descriptor")); CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_binary(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists(nvl, "nvlist/binary")); CHECK(!nvlist_exists_null(nvl, "nvlist/binary")); CHECK(!nvlist_exists_bool(nvl, "nvlist/binary")); CHECK(!nvlist_exists_number(nvl, "nvlist/binary")); CHECK(!nvlist_exists_string(nvl, "nvlist/binary")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/binary")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/binary")); CHECK(!nvlist_exists_binary(nvl, "nvlist/binary")); nvlist_add_binary(nvl, "nvlist/binary", "test", 4); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists(nvl, "nvlist/binary")); CHECK(!nvlist_exists_null(nvl, "nvlist/binary")); CHECK(!nvlist_exists_bool(nvl, "nvlist/binary")); CHECK(!nvlist_exists_number(nvl, "nvlist/binary")); CHECK(!nvlist_exists_string(nvl, "nvlist/binary")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/binary")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/binary")); CHECK(nvlist_exists_binary(nvl, "nvlist/binary")); CHECK(nvlist_exists(nvl, "nvlist/null")); CHECK(nvlist_exists(nvl, "nvlist/bool")); CHECK(nvlist_exists(nvl, "nvlist/number")); CHECK(nvlist_exists(nvl, "nvlist/string")); CHECK(nvlist_exists(nvl, "nvlist/nvlist")); CHECK(nvlist_exists(nvl, "nvlist/descriptor")); CHECK(nvlist_exists(nvl, "nvlist/binary")); CHECK(nvlist_exists_null(nvl, "nvlist/null")); CHECK(nvlist_exists_bool(nvl, "nvlist/bool")); CHECK(nvlist_exists_number(nvl, "nvlist/number")); CHECK(nvlist_exists_string(nvl, "nvlist/string")); CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist")); CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor")); CHECK(nvlist_exists_binary(nvl, "nvlist/binary")); nvlist_free_null(nvl, "nvlist/null"); CHECK(!nvlist_exists(nvl, "nvlist/null")); CHECK(nvlist_exists(nvl, "nvlist/bool")); CHECK(nvlist_exists(nvl, "nvlist/number")); CHECK(nvlist_exists(nvl, "nvlist/string")); CHECK(nvlist_exists(nvl, "nvlist/nvlist")); CHECK(nvlist_exists(nvl, "nvlist/descriptor")); CHECK(nvlist_exists(nvl, "nvlist/binary")); CHECK(!nvlist_exists_null(nvl, "nvlist/null")); CHECK(nvlist_exists_bool(nvl, "nvlist/bool")); CHECK(nvlist_exists_number(nvl, "nvlist/number")); CHECK(nvlist_exists_string(nvl, "nvlist/string")); CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist")); CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor")); CHECK(nvlist_exists_binary(nvl, "nvlist/binary")); nvlist_free_bool(nvl, "nvlist/bool"); CHECK(!nvlist_exists(nvl, "nvlist/null")); CHECK(!nvlist_exists(nvl, "nvlist/bool")); CHECK(nvlist_exists(nvl, "nvlist/number")); CHECK(nvlist_exists(nvl, "nvlist/string")); CHECK(nvlist_exists(nvl, "nvlist/nvlist")); CHECK(nvlist_exists(nvl, "nvlist/descriptor")); CHECK(nvlist_exists(nvl, "nvlist/binary")); CHECK(!nvlist_exists_null(nvl, "nvlist/null")); CHECK(!nvlist_exists_bool(nvl, "nvlist/bool")); CHECK(nvlist_exists_number(nvl, "nvlist/number")); CHECK(nvlist_exists_string(nvl, "nvlist/string")); CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist")); CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor")); CHECK(nvlist_exists_binary(nvl, "nvlist/binary")); nvlist_free_number(nvl, "nvlist/number"); CHECK(!nvlist_exists(nvl, "nvlist/null")); CHECK(!nvlist_exists(nvl, "nvlist/bool")); CHECK(!nvlist_exists(nvl, "nvlist/number")); CHECK(nvlist_exists(nvl, "nvlist/string")); CHECK(nvlist_exists(nvl, "nvlist/nvlist")); CHECK(nvlist_exists(nvl, "nvlist/descriptor")); CHECK(nvlist_exists(nvl, "nvlist/binary")); CHECK(!nvlist_exists_null(nvl, "nvlist/null")); CHECK(!nvlist_exists_bool(nvl, "nvlist/bool")); CHECK(!nvlist_exists_number(nvl, "nvlist/number")); CHECK(nvlist_exists_string(nvl, "nvlist/string")); CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist")); CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor")); CHECK(nvlist_exists_binary(nvl, "nvlist/binary")); nvlist_free_string(nvl, "nvlist/string"); CHECK(!nvlist_exists(nvl, "nvlist/null")); CHECK(!nvlist_exists(nvl, "nvlist/bool")); CHECK(!nvlist_exists(nvl, "nvlist/number")); CHECK(!nvlist_exists(nvl, "nvlist/string")); CHECK(nvlist_exists(nvl, "nvlist/nvlist")); CHECK(nvlist_exists(nvl, "nvlist/descriptor")); CHECK(nvlist_exists(nvl, "nvlist/binary")); CHECK(!nvlist_exists_null(nvl, "nvlist/null")); CHECK(!nvlist_exists_bool(nvl, "nvlist/bool")); CHECK(!nvlist_exists_number(nvl, "nvlist/number")); CHECK(!nvlist_exists_string(nvl, "nvlist/string")); CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist")); CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor")); CHECK(nvlist_exists_binary(nvl, "nvlist/binary")); nvlist_free_nvlist(nvl, "nvlist/nvlist"); CHECK(!nvlist_exists(nvl, "nvlist/null")); CHECK(!nvlist_exists(nvl, "nvlist/bool")); CHECK(!nvlist_exists(nvl, "nvlist/number")); CHECK(!nvlist_exists(nvl, "nvlist/string")); CHECK(!nvlist_exists(nvl, "nvlist/nvlist")); CHECK(nvlist_exists(nvl, "nvlist/descriptor")); CHECK(nvlist_exists(nvl, "nvlist/binary")); CHECK(!nvlist_exists_null(nvl, "nvlist/null")); CHECK(!nvlist_exists_bool(nvl, "nvlist/bool")); CHECK(!nvlist_exists_number(nvl, "nvlist/number")); CHECK(!nvlist_exists_string(nvl, "nvlist/string")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist")); CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor")); CHECK(nvlist_exists_binary(nvl, "nvlist/binary")); nvlist_free_descriptor(nvl, "nvlist/descriptor"); CHECK(!nvlist_exists(nvl, "nvlist/null")); CHECK(!nvlist_exists(nvl, "nvlist/bool")); CHECK(!nvlist_exists(nvl, "nvlist/number")); CHECK(!nvlist_exists(nvl, "nvlist/string")); CHECK(!nvlist_exists(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists(nvl, "nvlist/descriptor")); CHECK(nvlist_exists(nvl, "nvlist/binary")); CHECK(!nvlist_exists_null(nvl, "nvlist/null")); CHECK(!nvlist_exists_bool(nvl, "nvlist/bool")); CHECK(!nvlist_exists_number(nvl, "nvlist/number")); CHECK(!nvlist_exists_string(nvl, "nvlist/string")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/descriptor")); CHECK(nvlist_exists_binary(nvl, "nvlist/binary")); nvlist_free_binary(nvl, "nvlist/binary"); CHECK(!nvlist_exists(nvl, "nvlist/null")); CHECK(!nvlist_exists(nvl, "nvlist/bool")); CHECK(!nvlist_exists(nvl, "nvlist/number")); CHECK(!nvlist_exists(nvl, "nvlist/string")); CHECK(!nvlist_exists(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists(nvl, "nvlist/binary")); CHECK(!nvlist_exists_null(nvl, "nvlist/null")); CHECK(!nvlist_exists_bool(nvl, "nvlist/bool")); CHECK(!nvlist_exists_number(nvl, "nvlist/number")); CHECK(!nvlist_exists_string(nvl, "nvlist/string")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/descriptor")); CHECK(!nvlist_exists_binary(nvl, "nvlist/binary")); CHECK(nvlist_empty(nvl)); nvlist_destroy(nvl); return (0); }
int main(void) { const nvlist_t *cnvl; nvlist_t *nvl; printf("1..94\n"); nvl = nvlist_create(0); CHECK(!nvlist_exists_null(nvl, "nvlist/null")); nvlist_add_null(nvl, "nvlist/null"); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_null(nvl, "nvlist/null")); CHECK(!nvlist_exists_bool(nvl, "nvlist/bool/true")); nvlist_add_bool(nvl, "nvlist/bool/true", true); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_bool(nvl, "nvlist/bool/true")); CHECK(!nvlist_exists_bool(nvl, "nvlist/bool/false")); nvlist_add_bool(nvl, "nvlist/bool/false", false); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_bool(nvl, "nvlist/bool/false")); CHECK(!nvlist_exists_number(nvl, "nvlist/number/0")); nvlist_add_number(nvl, "nvlist/number/0", 0); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_number(nvl, "nvlist/number/0")); CHECK(!nvlist_exists_number(nvl, "nvlist/number/1")); nvlist_add_number(nvl, "nvlist/number/1", 1); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_number(nvl, "nvlist/number/1")); CHECK(!nvlist_exists_number(nvl, "nvlist/number/-1")); nvlist_add_number(nvl, "nvlist/number/-1", -1); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_number(nvl, "nvlist/number/-1")); CHECK(!nvlist_exists_number(nvl, "nvlist/number/UINT64_MAX")); nvlist_add_number(nvl, "nvlist/number/UINT64_MAX", UINT64_MAX); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_number(nvl, "nvlist/number/UINT64_MAX")); CHECK(!nvlist_exists_number(nvl, "nvlist/number/INT64_MIN")); nvlist_add_number(nvl, "nvlist/number/INT64_MIN", INT64_MIN); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_number(nvl, "nvlist/number/INT64_MIN")); CHECK(!nvlist_exists_number(nvl, "nvlist/number/INT64_MAX")); nvlist_add_number(nvl, "nvlist/number/INT64_MAX", INT64_MAX); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_number(nvl, "nvlist/number/INT64_MAX")); CHECK(!nvlist_exists_string(nvl, "nvlist/string/")); nvlist_add_string(nvl, "nvlist/string/", ""); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_string(nvl, "nvlist/string/")); CHECK(!nvlist_exists_string(nvl, "nvlist/string/x")); nvlist_add_string(nvl, "nvlist/string/x", "x"); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_string(nvl, "nvlist/string/x")); CHECK(!nvlist_exists_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz")); nvlist_add_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz"); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz")); CHECK(!nvlist_exists_string(nvl, "nvlist/stringf/")); nvlist_add_stringf(nvl, "nvlist/stringf/", "%s", ""); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_string(nvl, "nvlist/stringf/")); CHECK(!nvlist_exists_string(nvl, "nvlist/stringf/x")); nvlist_add_stringf(nvl, "nvlist/stringf/x", "%s", "x"); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_string(nvl, "nvlist/stringf/x")); CHECK(!nvlist_exists_string(nvl, "nvlist/stringf/666Xabc")); nvlist_add_stringf(nvl, "nvlist/stringf/666Xabc", "%d%c%s", 666, 'X', "abc"); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_string(nvl, "nvlist/stringf/666Xabc")); CHECK(!nvlist_exists_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO")); nvlist_add_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO", STDERR_FILENO); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO")); CHECK(!nvlist_exists_binary(nvl, "nvlist/binary/x")); nvlist_add_binary(nvl, "nvlist/binary/x", "x", 1); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_binary(nvl, "nvlist/binary/x")); CHECK(!nvlist_exists_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz")); nvlist_add_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist")); nvlist_add_nvlist(nvl, "nvlist/nvlist", nvl); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist")); CHECK(nvlist_exists_null(nvl, "nvlist/null")); CHECK(nvlist_exists_bool(nvl, "nvlist/bool/true")); CHECK(nvlist_exists_bool(nvl, "nvlist/bool/false")); CHECK(nvlist_exists_number(nvl, "nvlist/number/0")); CHECK(nvlist_exists_number(nvl, "nvlist/number/1")); CHECK(nvlist_exists_number(nvl, "nvlist/number/-1")); CHECK(nvlist_exists_number(nvl, "nvlist/number/UINT64_MAX")); CHECK(nvlist_exists_number(nvl, "nvlist/number/INT64_MIN")); CHECK(nvlist_exists_number(nvl, "nvlist/number/INT64_MAX")); CHECK(nvlist_exists_string(nvl, "nvlist/string/")); CHECK(nvlist_exists_string(nvl, "nvlist/string/x")); CHECK(nvlist_exists_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz")); CHECK(nvlist_exists_string(nvl, "nvlist/stringf/")); CHECK(nvlist_exists_string(nvl, "nvlist/stringf/x")); CHECK(nvlist_exists_string(nvl, "nvlist/stringf/666Xabc")); CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO")); CHECK(nvlist_exists_binary(nvl, "nvlist/binary/x")); CHECK(nvlist_exists_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz")); CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist")); cnvl = nvlist_get_nvlist(nvl, "nvlist/nvlist"); CHECK(nvlist_exists_null(cnvl, "nvlist/null")); CHECK(nvlist_exists_bool(cnvl, "nvlist/bool/true")); CHECK(nvlist_exists_bool(cnvl, "nvlist/bool/false")); CHECK(nvlist_exists_number(cnvl, "nvlist/number/0")); CHECK(nvlist_exists_number(cnvl, "nvlist/number/1")); CHECK(nvlist_exists_number(cnvl, "nvlist/number/-1")); CHECK(nvlist_exists_number(cnvl, "nvlist/number/UINT64_MAX")); CHECK(nvlist_exists_number(cnvl, "nvlist/number/INT64_MIN")); CHECK(nvlist_exists_number(cnvl, "nvlist/number/INT64_MAX")); CHECK(nvlist_exists_string(cnvl, "nvlist/string/")); CHECK(nvlist_exists_string(cnvl, "nvlist/string/x")); CHECK(nvlist_exists_string(cnvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz")); CHECK(nvlist_exists_string(cnvl, "nvlist/stringf/")); CHECK(nvlist_exists_string(cnvl, "nvlist/stringf/x")); CHECK(nvlist_exists_string(cnvl, "nvlist/stringf/666Xabc")); CHECK(nvlist_exists_descriptor(cnvl, "nvlist/descriptor/STDERR_FILENO")); CHECK(nvlist_exists_binary(cnvl, "nvlist/binary/x")); CHECK(nvlist_exists_binary(cnvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz")); nvlist_destroy(nvl); return (0); }
static int sysctl_command(const char *cmd, const nvlist_t *limits, nvlist_t *nvlin, nvlist_t *nvlout) { const char *name; const void *newp; void *oldp; uint64_t operation; size_t oldlen, newlen; size_t *oldlenp; int error; if (strcmp(cmd, "sysctl") != 0) return (EINVAL); error = sysctl_check_one(nvlin, false); if (error != 0) return (error); name = nvlist_get_string(nvlin, "name"); operation = nvlist_get_number(nvlin, "operation"); if (!sysctl_allowed(limits, name, operation)) return (ENOTCAPABLE); if ((operation & CAP_SYSCTL_WRITE) != 0) { if (!nvlist_exists_binary(nvlin, "newp")) return (EINVAL); newp = nvlist_get_binary(nvlin, "newp", &newlen); assert(newp != NULL && newlen > 0); } else { newp = NULL; newlen = 0; } if ((operation & CAP_SYSCTL_READ) != 0) { if (nvlist_exists_null(nvlin, "justsize")) { oldp = NULL; oldlen = 0; oldlenp = &oldlen; } else { if (!nvlist_exists_number(nvlin, "oldlen")) return (EINVAL); oldlen = (size_t)nvlist_get_number(nvlin, "oldlen"); if (oldlen == 0) return (EINVAL); oldp = calloc(1, oldlen); if (oldp == NULL) return (ENOMEM); oldlenp = &oldlen; } } else { oldp = NULL; oldlen = 0; oldlenp = NULL; } if (sysctlbyname(name, oldp, oldlenp, newp, newlen) == -1) { error = errno; free(oldp); return (error); } if ((operation & CAP_SYSCTL_READ) != 0) { if (nvlist_exists_null(nvlin, "justsize")) nvlist_add_number(nvlout, "oldlen", (uint64_t)oldlen); else nvlist_move_binary(nvlout, "oldp", oldp, oldlen); } return (0); }