Path: blob/main/sys/contrib/openzfs/module/zfs/dsl_deleg.c
48383 views
// SPDX-License-Identifier: CDDL-1.01/*2* CDDL HEADER START3*4* The contents of this file are subject to the terms of the5* Common Development and Distribution License (the "License").6* You may not use this file except in compliance with the License.7*8* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE9* or https://opensource.org/licenses/CDDL-1.0.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/21/*22* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.23* Copyright (c) 2011, 2015 by Delphix. All rights reserved.24*/2526/*27* DSL permissions are stored in a two level zap attribute28* mechanism. The first level identifies the "class" of29* entry. The class is identified by the first 2 letters of30* the attribute. The second letter "l" or "d" identifies whether31* it is a local or descendent permission. The first letter32* identifies the type of entry.33*34* ul$<id> identifies permissions granted locally for this userid.35* ud$<id> identifies permissions granted on descendent datasets for36* this userid.37* Ul$<id> identifies permission sets granted locally for this userid.38* Ud$<id> identifies permission sets granted on descendent datasets for39* this userid.40* gl$<id> identifies permissions granted locally for this groupid.41* gd$<id> identifies permissions granted on descendent datasets for42* this groupid.43* Gl$<id> identifies permission sets granted locally for this groupid.44* Gd$<id> identifies permission sets granted on descendent datasets for45* this groupid.46* el$ identifies permissions granted locally for everyone.47* ed$ identifies permissions granted on descendent datasets48* for everyone.49* El$ identifies permission sets granted locally for everyone.50* Ed$ identifies permission sets granted to descendent datasets for51* everyone.52* c-$ identifies permission to create at dataset creation time.53* C-$ identifies permission sets to grant locally at dataset creation54* time.55* s-$@<name> permissions defined in specified set @<name>56* S-$@<name> Sets defined in named set @<name>57*58* Each of the above entities points to another zap attribute that contains one59* attribute for each allowed permission, such as create, destroy,...60* All of the "upper" case class types will specify permission set names61* rather than permissions.62*63* Basically it looks something like this:64* ul$12 -> ZAP OBJ -> permissions...65*66* The ZAP OBJ is referred to as the jump object.67*/6869#include <sys/dmu.h>70#include <sys/dmu_objset.h>71#include <sys/dmu_tx.h>72#include <sys/dsl_dataset.h>73#include <sys/dsl_dir.h>74#include <sys/dsl_prop.h>75#include <sys/dsl_synctask.h>76#include <sys/dsl_deleg.h>77#include <sys/spa.h>78#include <sys/zap.h>79#include <sys/fs/zfs.h>80#include <sys/cred.h>81#include <sys/sunddi.h>8283#include "zfs_deleg.h"8485/*86* Validate that user is allowed to delegate specified permissions.87*88* In order to delegate "create" you must have "create"89* and "allow".90*/91int92dsl_deleg_can_allow(char *ddname, nvlist_t *nvp, cred_t *cr)93{94nvpair_t *whopair = NULL;95int error;9697if ((error = dsl_deleg_access(ddname, ZFS_DELEG_PERM_ALLOW, cr)) != 0)98return (error);99100while ((whopair = nvlist_next_nvpair(nvp, whopair))) {101nvlist_t *perms;102nvpair_t *permpair = NULL;103104VERIFY0(nvpair_value_nvlist(whopair, &perms));105106while ((permpair = nvlist_next_nvpair(perms, permpair))) {107const char *perm = nvpair_name(permpair);108109if (strcmp(perm, ZFS_DELEG_PERM_ALLOW) == 0)110return (SET_ERROR(EPERM));111112if ((error = dsl_deleg_access(ddname, perm, cr)) != 0)113return (error);114}115}116return (0);117}118119/*120* Validate that user is allowed to unallow specified permissions. They121* must have the 'allow' permission, and even then can only unallow122* perms for their uid.123*/124int125dsl_deleg_can_unallow(char *ddname, nvlist_t *nvp, cred_t *cr)126{127nvpair_t *whopair = NULL;128int error;129char idstr[32];130131if ((error = dsl_deleg_access(ddname, ZFS_DELEG_PERM_ALLOW, cr)) != 0)132return (error);133134(void) snprintf(idstr, sizeof (idstr), "%lld",135(longlong_t)crgetuid(cr));136137while ((whopair = nvlist_next_nvpair(nvp, whopair))) {138zfs_deleg_who_type_t type = nvpair_name(whopair)[0];139140if (type != ZFS_DELEG_USER &&141type != ZFS_DELEG_USER_SETS)142return (SET_ERROR(EPERM));143144if (strcmp(idstr, &nvpair_name(whopair)[3]) != 0)145return (SET_ERROR(EPERM));146}147return (0);148}149150typedef struct dsl_deleg_arg {151const char *dda_name;152nvlist_t *dda_nvlist;153} dsl_deleg_arg_t;154155static void156dsl_deleg_set_sync(void *arg, dmu_tx_t *tx)157{158dsl_deleg_arg_t *dda = arg;159dsl_dir_t *dd;160dsl_pool_t *dp = dmu_tx_pool(tx);161objset_t *mos = dp->dp_meta_objset;162nvpair_t *whopair = NULL;163uint64_t zapobj;164165VERIFY0(dsl_dir_hold(dp, dda->dda_name, FTAG, &dd, NULL));166167zapobj = dsl_dir_phys(dd)->dd_deleg_zapobj;168if (zapobj == 0) {169dmu_buf_will_dirty(dd->dd_dbuf, tx);170zapobj = dsl_dir_phys(dd)->dd_deleg_zapobj = zap_create(mos,171DMU_OT_DSL_PERMS, DMU_OT_NONE, 0, tx);172}173174while ((whopair = nvlist_next_nvpair(dda->dda_nvlist, whopair))) {175const char *whokey = nvpair_name(whopair);176nvlist_t *perms;177nvpair_t *permpair = NULL;178uint64_t jumpobj;179180perms = fnvpair_value_nvlist(whopair);181182if (zap_lookup(mos, zapobj, whokey, 8, 1, &jumpobj) != 0) {183jumpobj = zap_create_link(mos, DMU_OT_DSL_PERMS,184zapobj, whokey, tx);185}186187while ((permpair = nvlist_next_nvpair(perms, permpair))) {188const char *perm = nvpair_name(permpair);189uint64_t n = 0;190191VERIFY0(zap_update(mos, jumpobj, perm, 8, 1, &n, tx));192spa_history_log_internal_dd(dd, "permission update", tx,193"%s %s", whokey, perm);194}195}196dsl_dir_rele(dd, FTAG);197}198199static void200dsl_deleg_unset_sync(void *arg, dmu_tx_t *tx)201{202dsl_deleg_arg_t *dda = arg;203dsl_dir_t *dd;204dsl_pool_t *dp = dmu_tx_pool(tx);205objset_t *mos = dp->dp_meta_objset;206nvpair_t *whopair = NULL;207uint64_t zapobj;208209VERIFY0(dsl_dir_hold(dp, dda->dda_name, FTAG, &dd, NULL));210zapobj = dsl_dir_phys(dd)->dd_deleg_zapobj;211if (zapobj == 0) {212dsl_dir_rele(dd, FTAG);213return;214}215216while ((whopair = nvlist_next_nvpair(dda->dda_nvlist, whopair))) {217const char *whokey = nvpair_name(whopair);218nvlist_t *perms;219nvpair_t *permpair = NULL;220uint64_t jumpobj;221222if (nvpair_value_nvlist(whopair, &perms) != 0) {223if (zap_lookup(mos, zapobj, whokey, 8,2241, &jumpobj) == 0) {225(void) zap_remove(mos, zapobj, whokey, tx);226VERIFY0(zap_destroy(mos, jumpobj, tx));227}228spa_history_log_internal_dd(dd, "permission who remove",229tx, "%s", whokey);230continue;231}232233if (zap_lookup(mos, zapobj, whokey, 8, 1, &jumpobj) != 0)234continue;235236while ((permpair = nvlist_next_nvpair(perms, permpair))) {237const char *perm = nvpair_name(permpair);238uint64_t n = 0;239240(void) zap_remove(mos, jumpobj, perm, tx);241if (zap_count(mos, jumpobj, &n) == 0 && n == 0) {242(void) zap_remove(mos, zapobj,243whokey, tx);244VERIFY0(zap_destroy(mos,245jumpobj, tx));246}247spa_history_log_internal_dd(dd, "permission remove", tx,248"%s %s", whokey, perm);249}250}251dsl_dir_rele(dd, FTAG);252}253254static int255dsl_deleg_check(void *arg, dmu_tx_t *tx)256{257dsl_deleg_arg_t *dda = arg;258dsl_dir_t *dd;259int error;260261if (spa_version(dmu_tx_pool(tx)->dp_spa) <262SPA_VERSION_DELEGATED_PERMS) {263return (SET_ERROR(ENOTSUP));264}265266error = dsl_dir_hold(dmu_tx_pool(tx), dda->dda_name, FTAG, &dd, NULL);267if (error == 0)268dsl_dir_rele(dd, FTAG);269return (error);270}271272int273dsl_deleg_set(const char *ddname, nvlist_t *nvp, boolean_t unset)274{275dsl_deleg_arg_t dda;276277/* nvp must already have been verified to be valid */278279dda.dda_name = ddname;280dda.dda_nvlist = nvp;281282return (dsl_sync_task(ddname, dsl_deleg_check,283unset ? dsl_deleg_unset_sync : dsl_deleg_set_sync,284&dda, fnvlist_num_pairs(nvp), ZFS_SPACE_CHECK_RESERVED));285}286287/*288* Find all 'allow' permissions from a given point and then continue289* traversing up to the root.290*291* This function constructs an nvlist of nvlists.292* each setpoint is an nvlist composed of an nvlist of an nvlist293* of the individual * users/groups/everyone/create294* permissions.295*296* The nvlist will look like this.297*298* { source fsname -> { whokeys { permissions,...}, ...}}299*300* The fsname nvpairs will be arranged in a bottom up order. For example,301* if we have the following structure a/b/c then the nvpairs for the fsnames302* will be ordered a/b/c, a/b, a.303*/304int305dsl_deleg_get(const char *ddname, nvlist_t **nvp)306{307dsl_dir_t *dd, *startdd;308dsl_pool_t *dp;309int error;310objset_t *mos;311zap_cursor_t *basezc, *zc;312zap_attribute_t *baseza, *za;313char *source;314315error = dsl_pool_hold(ddname, FTAG, &dp);316if (error != 0)317return (error);318319error = dsl_dir_hold(dp, ddname, FTAG, &startdd, NULL);320if (error != 0) {321dsl_pool_rele(dp, FTAG);322return (error);323}324325dp = startdd->dd_pool;326mos = dp->dp_meta_objset;327328zc = kmem_alloc(sizeof (zap_cursor_t), KM_SLEEP);329za = zap_attribute_alloc();330basezc = kmem_alloc(sizeof (zap_cursor_t), KM_SLEEP);331baseza = zap_attribute_alloc();332source = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP);333VERIFY0(nvlist_alloc(nvp, NV_UNIQUE_NAME, KM_SLEEP));334335for (dd = startdd; dd != NULL; dd = dd->dd_parent) {336nvlist_t *sp_nvp;337uint64_t n;338339if (dsl_dir_phys(dd)->dd_deleg_zapobj == 0 ||340zap_count(mos,341dsl_dir_phys(dd)->dd_deleg_zapobj, &n) != 0 || n == 0)342continue;343344sp_nvp = fnvlist_alloc();345for (zap_cursor_init(basezc, mos,346dsl_dir_phys(dd)->dd_deleg_zapobj);347zap_cursor_retrieve(basezc, baseza) == 0;348zap_cursor_advance(basezc)) {349nvlist_t *perms_nvp;350351ASSERT(baseza->za_integer_length == 8);352ASSERT(baseza->za_num_integers == 1);353354perms_nvp = fnvlist_alloc();355for (zap_cursor_init(zc, mos, baseza->za_first_integer);356zap_cursor_retrieve(zc, za) == 0;357zap_cursor_advance(zc)) {358fnvlist_add_boolean(perms_nvp, za->za_name);359}360zap_cursor_fini(zc);361fnvlist_add_nvlist(sp_nvp, baseza->za_name, perms_nvp);362fnvlist_free(perms_nvp);363}364365zap_cursor_fini(basezc);366367dsl_dir_name(dd, source);368fnvlist_add_nvlist(*nvp, source, sp_nvp);369nvlist_free(sp_nvp);370}371372kmem_free(source, ZFS_MAX_DATASET_NAME_LEN);373zap_attribute_free(baseza);374kmem_free(basezc, sizeof (zap_cursor_t));375zap_attribute_free(za);376kmem_free(zc, sizeof (zap_cursor_t));377378dsl_dir_rele(startdd, FTAG);379dsl_pool_rele(dp, FTAG);380return (0);381}382383/*384* Routines for dsl_deleg_access() -- access checking.385*/386typedef struct perm_set {387avl_node_t p_node;388boolean_t p_matched;389char p_setname[ZFS_MAX_DELEG_NAME];390} perm_set_t;391392static int393perm_set_compare(const void *arg1, const void *arg2)394{395const perm_set_t *node1 = (const perm_set_t *)arg1;396const perm_set_t *node2 = (const perm_set_t *)arg2;397int val;398399val = strcmp(node1->p_setname, node2->p_setname);400401return (TREE_ISIGN(val));402}403404/*405* Determine whether a specified permission exists.406*407* First the base attribute has to be retrieved. i.e. ul$12408* Once the base object has been retrieved the actual permission409* is lookup up in the zap object the base object points to.410*411* Return 0 if permission exists, ENOENT if there is no whokey, EPERM if412* there is no perm in that jumpobj.413*/414static int415dsl_check_access(objset_t *mos, uint64_t zapobj,416char type, char checkflag, void *valp, const char *perm)417{418int error;419uint64_t jumpobj, zero;420char whokey[ZFS_MAX_DELEG_NAME];421422zfs_deleg_whokey(whokey, type, checkflag, valp);423error = zap_lookup(mos, zapobj, whokey, 8, 1, &jumpobj);424if (error == 0) {425error = zap_lookup(mos, jumpobj, perm, 8, 1, &zero);426if (error == ENOENT)427error = SET_ERROR(EPERM);428}429return (error);430}431432/*433* check a specified user/group for a requested permission434*/435static int436dsl_check_user_access(objset_t *mos, uint64_t zapobj, const char *perm,437int checkflag, cred_t *cr)438{439const gid_t *gids;440int ngids;441int i;442uint64_t id;443444/* check for user */445id = crgetuid(cr);446if (dsl_check_access(mos, zapobj,447ZFS_DELEG_USER, checkflag, &id, perm) == 0)448return (0);449450/* check for users primary group */451id = crgetgid(cr);452if (dsl_check_access(mos, zapobj,453ZFS_DELEG_GROUP, checkflag, &id, perm) == 0)454return (0);455456/* check for everyone entry */457id = -1;458if (dsl_check_access(mos, zapobj,459ZFS_DELEG_EVERYONE, checkflag, &id, perm) == 0)460return (0);461462/* check each supplemental group user is a member of */463ngids = crgetngroups(cr);464gids = crgetgroups(cr);465for (i = 0; i != ngids; i++) {466id = gids[i];467if (dsl_check_access(mos, zapobj,468ZFS_DELEG_GROUP, checkflag, &id, perm) == 0)469return (0);470}471472return (SET_ERROR(EPERM));473}474475/*476* Iterate over the sets specified in the specified zapobj477* and load them into the permsets avl tree.478*/479static int480dsl_load_sets(objset_t *mos, uint64_t zapobj,481char type, char checkflag, void *valp, avl_tree_t *avl)482{483zap_cursor_t zc;484zap_attribute_t *za;485perm_set_t *permnode;486avl_index_t idx;487uint64_t jumpobj;488int error;489char whokey[ZFS_MAX_DELEG_NAME];490491zfs_deleg_whokey(whokey, type, checkflag, valp);492493error = zap_lookup(mos, zapobj, whokey, 8, 1, &jumpobj);494if (error != 0)495return (error);496497za = zap_attribute_alloc();498for (zap_cursor_init(&zc, mos, jumpobj);499zap_cursor_retrieve(&zc, za) == 0;500zap_cursor_advance(&zc)) {501permnode = kmem_alloc(sizeof (perm_set_t), KM_SLEEP);502(void) strlcpy(permnode->p_setname, za->za_name,503sizeof (permnode->p_setname));504permnode->p_matched = B_FALSE;505506if (avl_find(avl, permnode, &idx) == NULL) {507avl_insert(avl, permnode, idx);508} else {509kmem_free(permnode, sizeof (perm_set_t));510}511}512zap_cursor_fini(&zc);513zap_attribute_free(za);514return (0);515}516517/*518* Load all permissions user based on cred belongs to.519*/520static void521dsl_load_user_sets(objset_t *mos, uint64_t zapobj, avl_tree_t *avl,522char checkflag, cred_t *cr)523{524const gid_t *gids;525int ngids, i;526uint64_t id;527528id = crgetuid(cr);529(void) dsl_load_sets(mos, zapobj,530ZFS_DELEG_USER_SETS, checkflag, &id, avl);531532id = crgetgid(cr);533(void) dsl_load_sets(mos, zapobj,534ZFS_DELEG_GROUP_SETS, checkflag, &id, avl);535536(void) dsl_load_sets(mos, zapobj,537ZFS_DELEG_EVERYONE_SETS, checkflag, NULL, avl);538539ngids = crgetngroups(cr);540gids = crgetgroups(cr);541for (i = 0; i != ngids; i++) {542id = gids[i];543(void) dsl_load_sets(mos, zapobj,544ZFS_DELEG_GROUP_SETS, checkflag, &id, avl);545}546}547548/*549* Check if user has requested permission.550*/551int552dsl_deleg_access_impl(dsl_dataset_t *ds, const char *perm, cred_t *cr)553{554dsl_dir_t *dd;555dsl_pool_t *dp;556void *cookie;557int error;558char checkflag;559objset_t *mos;560avl_tree_t permsets;561perm_set_t *setnode;562563dp = ds->ds_dir->dd_pool;564mos = dp->dp_meta_objset;565566if (dsl_delegation_on(mos) == B_FALSE)567return (SET_ERROR(ECANCELED));568569if (spa_version(dmu_objset_spa(dp->dp_meta_objset)) <570SPA_VERSION_DELEGATED_PERMS)571return (SET_ERROR(EPERM));572573if (ds->ds_is_snapshot) {574/*575* Snapshots are treated as descendents only,576* local permissions do not apply.577*/578checkflag = ZFS_DELEG_DESCENDENT;579} else {580checkflag = ZFS_DELEG_LOCAL;581}582583avl_create(&permsets, perm_set_compare, sizeof (perm_set_t),584offsetof(perm_set_t, p_node));585586ASSERT(dsl_pool_config_held(dp));587for (dd = ds->ds_dir; dd != NULL; dd = dd->dd_parent,588checkflag = ZFS_DELEG_DESCENDENT) {589uint64_t zapobj;590boolean_t expanded;591592/*593* If not in global zone then make sure594* the zoned property is set595*/596if (!INGLOBALZONE(curproc)) {597uint64_t zoned;598599if (dsl_prop_get_dd(dd,600zfs_prop_to_name(ZFS_PROP_ZONED),6018, 1, &zoned, NULL, B_FALSE) != 0)602break;603if (!zoned)604break;605}606zapobj = dsl_dir_phys(dd)->dd_deleg_zapobj;607608if (zapobj == 0)609continue;610611dsl_load_user_sets(mos, zapobj, &permsets, checkflag, cr);612again:613expanded = B_FALSE;614for (setnode = avl_first(&permsets); setnode;615setnode = AVL_NEXT(&permsets, setnode)) {616if (setnode->p_matched == B_TRUE)617continue;618619/* See if this set directly grants this permission */620error = dsl_check_access(mos, zapobj,621ZFS_DELEG_NAMED_SET, 0, setnode->p_setname, perm);622if (error == 0)623goto success;624if (error == EPERM)625setnode->p_matched = B_TRUE;626627/* See if this set includes other sets */628error = dsl_load_sets(mos, zapobj,629ZFS_DELEG_NAMED_SET_SETS, 0,630setnode->p_setname, &permsets);631if (error == 0)632setnode->p_matched = expanded = B_TRUE;633}634/*635* If we expanded any sets, that will define more sets,636* which we need to check.637*/638if (expanded)639goto again;640641error = dsl_check_user_access(mos, zapobj, perm, checkflag, cr);642if (error == 0)643goto success;644}645error = SET_ERROR(EPERM);646success:647648cookie = NULL;649while ((setnode = avl_destroy_nodes(&permsets, &cookie)) != NULL)650kmem_free(setnode, sizeof (perm_set_t));651652return (error);653}654655int656dsl_deleg_access(const char *dsname, const char *perm, cred_t *cr)657{658dsl_pool_t *dp;659dsl_dataset_t *ds;660int error;661662error = dsl_pool_hold(dsname, FTAG, &dp);663if (error != 0)664return (error);665error = dsl_dataset_hold(dp, dsname, FTAG, &ds);666if (error == 0) {667error = dsl_deleg_access_impl(ds, perm, cr);668dsl_dataset_rele(ds, FTAG);669}670dsl_pool_rele(dp, FTAG);671672return (error);673}674675/*676* Other routines.677*/678679static void680copy_create_perms(dsl_dir_t *dd, uint64_t pzapobj,681boolean_t dosets, uint64_t uid, dmu_tx_t *tx)682{683objset_t *mos = dd->dd_pool->dp_meta_objset;684uint64_t jumpobj, pjumpobj;685uint64_t zapobj = dsl_dir_phys(dd)->dd_deleg_zapobj;686zap_cursor_t zc;687zap_attribute_t *za;688char whokey[ZFS_MAX_DELEG_NAME];689690zfs_deleg_whokey(whokey,691dosets ? ZFS_DELEG_CREATE_SETS : ZFS_DELEG_CREATE,692ZFS_DELEG_LOCAL, NULL);693if (zap_lookup(mos, pzapobj, whokey, 8, 1, &pjumpobj) != 0)694return;695696if (zapobj == 0) {697dmu_buf_will_dirty(dd->dd_dbuf, tx);698zapobj = dsl_dir_phys(dd)->dd_deleg_zapobj = zap_create(mos,699DMU_OT_DSL_PERMS, DMU_OT_NONE, 0, tx);700}701702zfs_deleg_whokey(whokey,703dosets ? ZFS_DELEG_USER_SETS : ZFS_DELEG_USER,704ZFS_DELEG_LOCAL, &uid);705if (zap_lookup(mos, zapobj, whokey, 8, 1, &jumpobj) == ENOENT) {706jumpobj = zap_create(mos, DMU_OT_DSL_PERMS, DMU_OT_NONE, 0, tx);707VERIFY0(zap_add(mos, zapobj, whokey, 8, 1, &jumpobj, tx));708}709710za = zap_attribute_alloc();711for (zap_cursor_init(&zc, mos, pjumpobj);712zap_cursor_retrieve(&zc, za) == 0;713zap_cursor_advance(&zc)) {714uint64_t zero = 0;715ASSERT(za->za_integer_length == 8 && za->za_num_integers == 1);716717VERIFY0(zap_update(mos, jumpobj, za->za_name, 8, 1, &zero, tx));718}719zap_cursor_fini(&zc);720zap_attribute_free(za);721}722723/*724* set all create time permission on new dataset.725*/726void727dsl_deleg_set_create_perms(dsl_dir_t *sdd, dmu_tx_t *tx, cred_t *cr)728{729dsl_dir_t *dd;730uint64_t uid = crgetuid(cr);731732if (spa_version(dmu_objset_spa(sdd->dd_pool->dp_meta_objset)) <733SPA_VERSION_DELEGATED_PERMS)734return;735736for (dd = sdd->dd_parent; dd != NULL; dd = dd->dd_parent) {737uint64_t pzapobj = dsl_dir_phys(dd)->dd_deleg_zapobj;738739if (pzapobj == 0)740continue;741742copy_create_perms(sdd, pzapobj, B_FALSE, uid, tx);743copy_create_perms(sdd, pzapobj, B_TRUE, uid, tx);744}745}746747int748dsl_deleg_destroy(objset_t *mos, uint64_t zapobj, dmu_tx_t *tx)749{750zap_cursor_t zc;751zap_attribute_t *za;752753if (zapobj == 0)754return (0);755756za = zap_attribute_alloc();757for (zap_cursor_init(&zc, mos, zapobj);758zap_cursor_retrieve(&zc, za) == 0;759zap_cursor_advance(&zc)) {760ASSERT(za->za_integer_length == 8 && za->za_num_integers == 1);761VERIFY0(zap_destroy(mos, za->za_first_integer, tx));762}763zap_cursor_fini(&zc);764VERIFY0(zap_destroy(mos, zapobj, tx));765zap_attribute_free(za);766return (0);767}768769boolean_t770dsl_delegation_on(objset_t *os)771{772return (!!spa_delegation(os->os_spa));773}774775#if defined(_KERNEL)776EXPORT_SYMBOL(dsl_deleg_get);777EXPORT_SYMBOL(dsl_deleg_set);778#endif779780781