static int pci_iov_init(device_t dev, uint16_t num_vfs, const nvlist_t *config) { const nvlist_t *device, *driver_config; device = nvlist_get_nvlist(config, PF_CONFIG_NAME); driver_config = nvlist_get_nvlist(device, DRIVER_CONFIG_NAME); return (PCI_IOV_INIT(dev, num_vfs, driver_config)); }
static void pci_iov_enumerate_vfs(struct pci_devinfo *dinfo, const nvlist_t *config, uint16_t first_rid, uint16_t rid_stride) { char device_name[VF_MAX_NAME]; const nvlist_t *device, *driver_config, *iov_config; device_t bus, dev, vf; struct pcicfg_iov *iov; struct pci_devinfo *vfinfo; size_t size; int i, error; uint16_t vid, did, next_rid; iov = dinfo->cfg.iov; dev = dinfo->cfg.dev; bus = device_get_parent(dev); size = dinfo->cfg.devinfo_size; next_rid = first_rid; vid = pci_get_vendor(dev); did = IOV_READ(dinfo, PCIR_SRIOV_VF_DID, 2); for (i = 0; i < iov->iov_num_vfs; i++, next_rid += rid_stride) { snprintf(device_name, sizeof(device_name), VF_PREFIX"%d", i); device = nvlist_get_nvlist(config, device_name); iov_config = nvlist_get_nvlist(device, IOV_CONFIG_NAME); driver_config = nvlist_get_nvlist(device, DRIVER_CONFIG_NAME); vf = PCI_CREATE_IOV_CHILD(bus, dev, next_rid, vid, did); if (vf == NULL) break; /* * If we are creating passthrough devices then force the ppt * driver to attach to prevent a VF driver from claiming the * VFs. */ if (nvlist_get_bool(iov_config, "passthrough")) device_set_devclass_fixed(vf, "ppt"); vfinfo = device_get_ivars(vf); vfinfo->cfg.iov = iov; vfinfo->cfg.vf.index = i; pci_iov_add_bars(iov, vfinfo); error = PCI_IOV_ADD_VF(dev, i, driver_config); if (error != 0) { device_printf(dev, "Failed to add VF %d\n", i); pci_delete_child(bus, vf); } } bus_generic_attach(bus); }
static void print_schema(const char *dev_name) { nvlist_t *schema; const nvlist_t *iov_schema, *driver_schema, *pf_schema, *vf_schema; int fd; fd = open_device(dev_name); schema = get_schema(fd); pf_schema = nvlist_get_nvlist(schema, PF_CONFIG_NAME); iov_schema = nvlist_get_nvlist(pf_schema, IOV_CONFIG_NAME); driver_schema = nvlist_get_nvlist(pf_schema, DRIVER_CONFIG_NAME); printf( "The following configuration parameters may be configured on the PF:\n"); print_subsystem_schema(iov_schema); print_subsystem_schema(driver_schema); vf_schema = nvlist_get_nvlist(schema, VF_SCHEMA_NAME); iov_schema = nvlist_get_nvlist(vf_schema, IOV_CONFIG_NAME); driver_schema = nvlist_get_nvlist(vf_schema, DRIVER_CONFIG_NAME); printf( "\nThe following configuration parameters may be configured on a VF:\n"); print_subsystem_schema(iov_schema); print_subsystem_schema(driver_schema); nvlist_destroy(schema); close(fd); }
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)); }
static bool pwd_allowed_user(const nvlist_t *limits, const char *uname, uid_t uid) { const char *name; void *cookie; int type; if (limits == NULL) return (true); /* * If no limit was set on allowed users, then all users are allowed. */ if (!nvlist_exists_nvlist(limits, "users")) return (true); limits = nvlist_get_nvlist(limits, "users"); cookie = NULL; while ((name = nvlist_next(limits, &type, &cookie)) != NULL) { switch (type) { case NV_TYPE_NUMBER: if (uid != (uid_t)-1 && nvlist_get_number(limits, name) == (uint64_t)uid) { return (true); } break; case NV_TYPE_STRING: if (uname != NULL && strcmp(nvlist_get_string(limits, name), uname) == 0) { return (true); } break; default: PJDLOG_ABORT("Unexpected type %d.", type); } } return (false); }
static int pwd_limit(const nvlist_t *oldlimits, const nvlist_t *newlimits) { const nvlist_t *limits; const char *name; void *cookie; int error, type; if (oldlimits != NULL && nvlist_exists_nvlist(oldlimits, "cmds") && !nvlist_exists_nvlist(newlimits, "cmds")) { return (ENOTCAPABLE); } if (oldlimits != NULL && nvlist_exists_nvlist(oldlimits, "fields") && !nvlist_exists_nvlist(newlimits, "fields")) { return (ENOTCAPABLE); } if (oldlimits != NULL && nvlist_exists_nvlist(oldlimits, "users") && !nvlist_exists_nvlist(newlimits, "users")) { return (ENOTCAPABLE); } cookie = NULL; while ((name = nvlist_next(newlimits, &type, &cookie)) != NULL) { if (type != NV_TYPE_NVLIST) return (EINVAL); limits = nvlist_get_nvlist(newlimits, name); if (strcmp(name, "cmds") == 0) error = pwd_allowed_cmds(oldlimits, limits); else if (strcmp(name, "fields") == 0) error = pwd_allowed_fields(oldlimits, limits); else if (strcmp(name, "users") == 0) error = pwd_allowed_users(oldlimits, limits); else error = EINVAL; if (error != 0) return (error); } return (0); }
static bool grp_allowed_group(const nvlist_t *limits, const char *gname, gid_t gid) { const char *name; void *cookie; int type; if (limits == NULL) return (true); /* * If no limit was set on allowed groups, then all groups are allowed. */ if (!nvlist_exists_nvlist(limits, "groups")) return (true); limits = nvlist_get_nvlist(limits, "groups"); cookie = NULL; while ((name = nvlist_next(limits, &type, &cookie)) != NULL) { switch (type) { case NV_TYPE_NUMBER: if (gid != (gid_t)-1 && nvlist_get_number(limits, name) == (uint64_t)gid) { return (true); } break; case NV_TYPE_STRING: if (gname != NULL && strcmp(nvlist_get_string(limits, name), gname) == 0) { return (true); } break; default: abort(); } } return (false); }
static void print_subsystem_schema(const nvlist_t * subsystem_schema) { const char *name, *type; const nvlist_t *parameter; void *it; int nvtype; it = NULL; while ((name = nvlist_next(subsystem_schema, &nvtype, &it)) != NULL) { parameter = nvlist_get_nvlist(subsystem_schema, name); type = nvlist_get_string(parameter, TYPE_SCHEMA_NAME); printf("\t%s : %s", name, type); if (dnvlist_get_bool(parameter, REQUIRED_SCHEMA_NAME, false)) printf(" (required)"); else if (nvlist_exists(parameter, DEFAULT_SCHEMA_NAME)) print_default_value(parameter, type); else printf(" (optional)"); printf("\n"); } }
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); }
int cap_getaddrinfo(cap_channel_t *chan, const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res) { struct addrinfo *firstai, *prevai, *curai; unsigned int ii; const nvlist_t *nvlai; char nvlname[64]; nvlist_t *nvl; int error, n; nvl = nvlist_create(0); nvlist_add_string(nvl, "cmd", "getaddrinfo"); nvlist_add_string(nvl, "hostname", hostname); nvlist_add_string(nvl, "servname", servname); if (hints != NULL) { nvlist_add_number(nvl, "hints.ai_flags", (uint64_t)hints->ai_flags); nvlist_add_number(nvl, "hints.ai_family", (uint64_t)hints->ai_family); nvlist_add_number(nvl, "hints.ai_socktype", (uint64_t)hints->ai_socktype); nvlist_add_number(nvl, "hints.ai_protocol", (uint64_t)hints->ai_protocol); } nvl = cap_xfer_nvlist(chan, nvl, 0); if (nvl == NULL) return (EAI_MEMORY); if (nvlist_get_number(nvl, "error") != 0) { error = (int)nvlist_get_number(nvl, "error"); nvlist_destroy(nvl); return (error); } nvlai = NULL; firstai = prevai = curai = NULL; for (ii = 0; ; ii++) { n = snprintf(nvlname, sizeof(nvlname), "res%u", ii); assert(n > 0 && n < (int)sizeof(nvlname)); if (!nvlist_exists_nvlist(nvl, nvlname)) break; nvlai = nvlist_get_nvlist(nvl, nvlname); curai = addrinfo_unpack(nvlai); if (curai == NULL) break; if (prevai != NULL) prevai->ai_next = curai; else if (firstai == NULL) firstai = curai; prevai = curai; } nvlist_destroy(nvl); if (curai == NULL && nvlai != NULL) { if (firstai == NULL) freeaddrinfo(firstai); return (EAI_MEMORY); } *res = firstai; return (0); }
static void parent(int sock) { nvlist_t *nvl; const nvlist_t *cnvl; const char *name, *cname; void *cookie, *ccookie; int type, ctype; size_t size; nvl = nvlist_recv(sock); CHECK(nvlist_error(nvl) == 0); if (nvlist_error(nvl) != 0) err(1, "nvlist_recv() failed"); cookie = NULL; name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_BOOL); CHECK(strcmp(name, "nvlist/bool/true") == 0); CHECK(nvlist_get_bool(nvl, name) == true); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_BOOL); CHECK(strcmp(name, "nvlist/bool/false") == 0); CHECK(nvlist_get_bool(nvl, name) == false); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_NUMBER); CHECK(strcmp(name, "nvlist/number/0") == 0); CHECK(nvlist_get_number(nvl, name) == 0); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_NUMBER); CHECK(strcmp(name, "nvlist/number/1") == 0); CHECK(nvlist_get_number(nvl, name) == 1); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_NUMBER); CHECK(strcmp(name, "nvlist/number/-1") == 0); CHECK((int)nvlist_get_number(nvl, name) == -1); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_NUMBER); CHECK(strcmp(name, "nvlist/number/UINT64_MAX") == 0); CHECK(nvlist_get_number(nvl, name) == UINT64_MAX); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_NUMBER); CHECK(strcmp(name, "nvlist/number/INT64_MIN") == 0); CHECK((int64_t)nvlist_get_number(nvl, name) == INT64_MIN); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_NUMBER); CHECK(strcmp(name, "nvlist/number/INT64_MAX") == 0); CHECK((int64_t)nvlist_get_number(nvl, name) == INT64_MAX); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_STRING); CHECK(strcmp(name, "nvlist/string/") == 0); CHECK(strcmp(nvlist_get_string(nvl, name), "") == 0); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_STRING); CHECK(strcmp(name, "nvlist/string/x") == 0); CHECK(strcmp(nvlist_get_string(nvl, name), "x") == 0); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_STRING); CHECK(strcmp(name, "nvlist/string/abcdefghijklmnopqrstuvwxyz") == 0); CHECK(strcmp(nvlist_get_string(nvl, name), "abcdefghijklmnopqrstuvwxyz") == 0); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_DESCRIPTOR); CHECK(strcmp(name, "nvlist/descriptor/STDERR_FILENO") == 0); CHECK(fd_is_valid(nvlist_get_descriptor(nvl, name))); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_BINARY); CHECK(strcmp(name, "nvlist/binary/x") == 0); CHECK(memcmp(nvlist_get_binary(nvl, name, NULL), "x", 1) == 0); CHECK(memcmp(nvlist_get_binary(nvl, name, &size), "x", 1) == 0); CHECK(size == 1); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_BINARY); CHECK(strcmp(name, "nvlist/binary/abcdefghijklmnopqrstuvwxyz") == 0); CHECK(memcmp(nvlist_get_binary(nvl, name, NULL), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0); CHECK(memcmp(nvlist_get_binary(nvl, name, &size), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0); CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz")); name = nvlist_next(nvl, &type, &cookie); CHECK(name != NULL); CHECK(type == NV_TYPE_NVLIST); CHECK(strcmp(name, "nvlist/nvlist") == 0); cnvl = nvlist_get_nvlist(nvl, name); ccookie = NULL; cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_BOOL); CHECK(strcmp(cname, "nvlist/bool/true") == 0); CHECK(nvlist_get_bool(cnvl, cname) == true); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_BOOL); CHECK(strcmp(cname, "nvlist/bool/false") == 0); CHECK(nvlist_get_bool(cnvl, cname) == false); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_NUMBER); CHECK(strcmp(cname, "nvlist/number/0") == 0); CHECK(nvlist_get_number(cnvl, cname) == 0); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_NUMBER); CHECK(strcmp(cname, "nvlist/number/1") == 0); CHECK(nvlist_get_number(cnvl, cname) == 1); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_NUMBER); CHECK(strcmp(cname, "nvlist/number/-1") == 0); CHECK((int)nvlist_get_number(cnvl, cname) == -1); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_NUMBER); CHECK(strcmp(cname, "nvlist/number/UINT64_MAX") == 0); CHECK(nvlist_get_number(cnvl, cname) == UINT64_MAX); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_NUMBER); CHECK(strcmp(cname, "nvlist/number/INT64_MIN") == 0); CHECK((int64_t)nvlist_get_number(cnvl, cname) == INT64_MIN); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_NUMBER); CHECK(strcmp(cname, "nvlist/number/INT64_MAX") == 0); CHECK((int64_t)nvlist_get_number(cnvl, cname) == INT64_MAX); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_STRING); CHECK(strcmp(cname, "nvlist/string/") == 0); CHECK(strcmp(nvlist_get_string(cnvl, cname), "") == 0); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_STRING); CHECK(strcmp(cname, "nvlist/string/x") == 0); CHECK(strcmp(nvlist_get_string(cnvl, cname), "x") == 0); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_STRING); CHECK(strcmp(cname, "nvlist/string/abcdefghijklmnopqrstuvwxyz") == 0); CHECK(strcmp(nvlist_get_string(cnvl, cname), "abcdefghijklmnopqrstuvwxyz") == 0); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_DESCRIPTOR); CHECK(strcmp(cname, "nvlist/descriptor/STDERR_FILENO") == 0); CHECK(fd_is_valid(nvlist_get_descriptor(cnvl, cname))); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_BINARY); CHECK(strcmp(cname, "nvlist/binary/x") == 0); CHECK(memcmp(nvlist_get_binary(cnvl, cname, NULL), "x", 1) == 0); CHECK(memcmp(nvlist_get_binary(cnvl, cname, &size), "x", 1) == 0); CHECK(size == 1); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname != NULL); CHECK(ctype == NV_TYPE_BINARY); CHECK(strcmp(cname, "nvlist/binary/abcdefghijklmnopqrstuvwxyz") == 0); CHECK(memcmp(nvlist_get_binary(cnvl, cname, NULL), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0); CHECK(memcmp(nvlist_get_binary(cnvl, cname, &size), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0); CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz")); cname = nvlist_next(cnvl, &ctype, &ccookie); CHECK(cname == NULL); name = nvlist_next(nvl, &type, &cookie); CHECK(name == NULL); }
int main(void) { const nvlist_t *cnvl; nvlist_t *nvl; size_t size; printf("1..83\n"); nvl = nvlist_create(0); CHECK(!nvlist_exists_bool(nvl, "nvlist/bool/true")); nvlist_add_bool(nvl, "nvlist/bool/true", true); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_get_bool(nvl, "nvlist/bool/true") == true); CHECK(!nvlist_exists_bool(nvl, "nvlist/bool/false")); nvlist_add_bool(nvl, "nvlist/bool/false", false); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_get_bool(nvl, "nvlist/bool/false") == false); CHECK(!nvlist_exists_number(nvl, "nvlist/number/0")); nvlist_add_number(nvl, "nvlist/number/0", 0); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_get_number(nvl, "nvlist/number/0") == 0); CHECK(!nvlist_exists_number(nvl, "nvlist/number/1")); nvlist_add_number(nvl, "nvlist/number/1", 1); CHECK(nvlist_error(nvl) == 0); CHECK(nvlist_get_number(nvl, "nvlist/number/1") == 1); CHECK(!nvlist_exists_number(nvl, "nvlist/number/-1")); nvlist_add_number(nvl, "nvlist/number/-1", -1); CHECK(nvlist_error(nvl) == 0); CHECK((int)nvlist_get_number(nvl, "nvlist/number/-1") == -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_get_number(nvl, "nvlist/number/UINT64_MAX") == 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((int64_t)nvlist_get_number(nvl, "nvlist/number/INT64_MIN") == 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((int64_t)nvlist_get_number(nvl, "nvlist/number/INT64_MAX") == INT64_MAX); CHECK(!nvlist_exists_string(nvl, "nvlist/string/")); nvlist_add_string(nvl, "nvlist/string/", ""); CHECK(nvlist_error(nvl) == 0); CHECK(strcmp(nvlist_get_string(nvl, "nvlist/string/"), "") == 0); CHECK(!nvlist_exists_string(nvl, "nvlist/string/x")); nvlist_add_string(nvl, "nvlist/string/x", "x"); CHECK(nvlist_error(nvl) == 0); CHECK(strcmp(nvlist_get_string(nvl, "nvlist/string/x"), "x") == 0); CHECK(!nvlist_exists_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz")); nvlist_add_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz"); CHECK(nvlist_error(nvl) == 0); CHECK(strcmp(nvlist_get_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz"), "abcdefghijklmnopqrstuvwxyz") == 0); 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(fd_is_valid(nvlist_get_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(memcmp(nvlist_get_binary(nvl, "nvlist/binary/x", NULL), "x", 1) == 0); CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/x", &size), "x", 1) == 0); CHECK(size == 1); CHECK(!nvlist_exists_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz")); nvlist_add_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")); CHECK(nvlist_error(nvl) == 0); CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", NULL), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0); CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", &size), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0); CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz")); CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist")); nvlist_add_nvlist(nvl, "nvlist/nvlist", nvl); CHECK(nvlist_error(nvl) == 0); cnvl = nvlist_get_nvlist(nvl, "nvlist/nvlist"); CHECK(nvlist_get_bool(cnvl, "nvlist/bool/true") == true); CHECK(nvlist_get_bool(cnvl, "nvlist/bool/false") == false); CHECK(nvlist_get_number(cnvl, "nvlist/number/0") == 0); CHECK(nvlist_get_number(cnvl, "nvlist/number/1") == 1); CHECK((int)nvlist_get_number(cnvl, "nvlist/number/-1") == -1); CHECK(nvlist_get_number(cnvl, "nvlist/number/UINT64_MAX") == UINT64_MAX); CHECK((int64_t)nvlist_get_number(cnvl, "nvlist/number/INT64_MIN") == INT64_MIN); CHECK((int64_t)nvlist_get_number(cnvl, "nvlist/number/INT64_MAX") == INT64_MAX); CHECK(strcmp(nvlist_get_string(cnvl, "nvlist/string/"), "") == 0); CHECK(strcmp(nvlist_get_string(cnvl, "nvlist/string/x"), "x") == 0); CHECK(strcmp(nvlist_get_string(cnvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz"), "abcdefghijklmnopqrstuvwxyz") == 0); /* TODO */ CHECK(memcmp(nvlist_get_binary(cnvl, "nvlist/binary/x", NULL), "x", 1) == 0); CHECK(memcmp(nvlist_get_binary(cnvl, "nvlist/binary/x", &size), "x", 1) == 0); CHECK(size == 1); CHECK(memcmp(nvlist_get_binary(cnvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", NULL), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0); CHECK(memcmp(nvlist_get_binary(cnvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", &size), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0); CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz")); CHECK(nvlist_get_bool(nvl, "nvlist/bool/true") == true); CHECK(nvlist_get_bool(nvl, "nvlist/bool/false") == false); CHECK(nvlist_get_number(nvl, "nvlist/number/0") == 0); CHECK(nvlist_get_number(nvl, "nvlist/number/1") == 1); CHECK((int)nvlist_get_number(nvl, "nvlist/number/-1") == -1); CHECK(nvlist_get_number(nvl, "nvlist/number/UINT64_MAX") == UINT64_MAX); CHECK((int64_t)nvlist_get_number(nvl, "nvlist/number/INT64_MIN") == INT64_MIN); CHECK((int64_t)nvlist_get_number(nvl, "nvlist/number/INT64_MAX") == INT64_MAX); CHECK(strcmp(nvlist_get_string(nvl, "nvlist/string/"), "") == 0); CHECK(strcmp(nvlist_get_string(nvl, "nvlist/string/x"), "x") == 0); CHECK(strcmp(nvlist_get_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz"), "abcdefghijklmnopqrstuvwxyz") == 0); CHECK(fd_is_valid(nvlist_get_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO"))); CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/x", NULL), "x", 1) == 0); CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/x", &size), "x", 1) == 0); CHECK(size == 1); CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", NULL), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0); CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", &size), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0); CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz")); nvlist_destroy(nvl); return (0); }