4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 #pragma ident "@(#)zfs_deleg.c 1.5 08/02/07 SMI"
30 #include <sys/systm.h>
31 #include <sys/sunddi.h>
32 #include <sys/ctype.h>
37 #include <libnvpair.h>
40 /* XXX includes zfs_context.h, so why bother with the above? */
41 #include <sys/dsl_deleg.h>
43 #include "zfs_deleg.h"
44 #include "zfs_namecheck.h"
49 * Keep this table in sorted order
51 * This table is used for displaying all permissions for
55 zfs_deleg_perm_tab_t zfs_deleg_perm_tab[] = {
56 {ZFS_DELEG_PERM_ALLOW, ZFS_DELEG_NOTE_ALLOW},
57 {ZFS_DELEG_PERM_CLONE, ZFS_DELEG_NOTE_CLONE },
58 {ZFS_DELEG_PERM_CREATE, ZFS_DELEG_NOTE_CREATE },
59 {ZFS_DELEG_PERM_DESTROY, ZFS_DELEG_NOTE_DESTROY },
60 {ZFS_DELEG_PERM_MOUNT, ZFS_DELEG_NOTE_MOUNT },
61 {ZFS_DELEG_PERM_PROMOTE, ZFS_DELEG_NOTE_PROMOTE },
62 {ZFS_DELEG_PERM_RECEIVE, ZFS_DELEG_NOTE_RECEIVE },
63 {ZFS_DELEG_PERM_RENAME, ZFS_DELEG_NOTE_RENAME },
64 {ZFS_DELEG_PERM_ROLLBACK, ZFS_DELEG_NOTE_ROLLBACK },
65 {ZFS_DELEG_PERM_SNAPSHOT, ZFS_DELEG_NOTE_SNAPSHOT },
66 {ZFS_DELEG_PERM_SHARE, ZFS_DELEG_NOTE_SHARE },
67 {ZFS_DELEG_PERM_SEND, ZFS_DELEG_NOTE_NONE },
68 {ZFS_DELEG_PERM_USERPROP, ZFS_DELEG_NOTE_USERPROP },
69 {NULL, ZFS_DELEG_NOTE_NONE }
73 zfs_valid_permission_name(const char *perm)
75 if (zfs_deleg_canonicalize_perm(perm))
78 return (permset_namecheck(perm, NULL, NULL));
82 zfs_deleg_canonicalize_perm(const char *perm)
87 for (i = 0; zfs_deleg_perm_tab[i].z_perm != NULL; i++) {
88 if (strcmp(perm, zfs_deleg_perm_tab[i].z_perm) == 0)
92 prop = zfs_name_to_prop(perm);
93 if (prop != ZPROP_INVAL && zfs_prop_delegatable(prop))
94 return (zfs_prop_to_name(prop));
100 zfs_validate_who(char *who)
104 if (who[2] != ZFS_DELEG_FIELD_SEP_CHR)
109 case ZFS_DELEG_GROUP:
110 case ZFS_DELEG_USER_SETS:
111 case ZFS_DELEG_GROUP_SETS:
112 if (who[1] != ZFS_DELEG_LOCAL && who[1] != ZFS_DELEG_DESCENDENT)
114 for (p = &who[3]; *p; p++)
119 case ZFS_DELEG_NAMED_SET:
120 case ZFS_DELEG_NAMED_SET_SETS:
121 if (who[1] != ZFS_DELEG_NA)
123 return (permset_namecheck(&who[3], NULL, NULL));
125 case ZFS_DELEG_CREATE:
126 case ZFS_DELEG_CREATE_SETS:
127 if (who[1] != ZFS_DELEG_NA)
133 case ZFS_DELEG_EVERYONE:
134 case ZFS_DELEG_EVERYONE_SETS:
135 if (who[1] != ZFS_DELEG_LOCAL && who[1] != ZFS_DELEG_DESCENDENT)
149 zfs_deleg_verify_nvlist(nvlist_t *nvp)
151 nvpair_t *who, *perm_name;
158 who = nvlist_next_nvpair(nvp, NULL);
163 if (zfs_validate_who(nvpair_name(who)))
166 error = nvlist_lookup_nvlist(nvp, nvpair_name(who), &perms);
168 if (error && error != ENOENT)
173 perm_name = nvlist_next_nvpair(perms, NULL);
174 if (perm_name == NULL) {
178 error = zfs_valid_permission_name(
179 nvpair_name(perm_name));
182 } while (perm_name = nvlist_next_nvpair(perms, perm_name));
183 } while (who = nvlist_next_nvpair(nvp, who));
188 * Construct the base attribute name. The base attribute names
189 * are the "key" to locate the jump objects which contain the actual
190 * permissions. The base attribute names are encoded based on
191 * type of entry and whether it is a local or descendent permission.
194 * attr - attribute name return string, attribute is assumed to be
195 * ZFS_MAX_DELEG_NAME long.
196 * type - type of entry to construct
197 * inheritchr - inheritance type (local,descendent, or NA for create and
198 * permission set definitions
199 * data - is either a permission set name or a 64 bit uid/gid.
202 zfs_deleg_whokey(char *attr, zfs_deleg_who_type_t type,
203 char inheritchr, void *data)
205 int len = ZFS_MAX_DELEG_NAME;
210 case ZFS_DELEG_GROUP:
211 case ZFS_DELEG_USER_SETS:
212 case ZFS_DELEG_GROUP_SETS:
213 (void) snprintf(attr, len, "%c%c%c%lld", type, inheritchr,
214 ZFS_DELEG_FIELD_SEP_CHR, (longlong_t)*id);
216 case ZFS_DELEG_NAMED_SET_SETS:
217 case ZFS_DELEG_NAMED_SET:
218 (void) snprintf(attr, len, "%c-%c%s", type,
219 ZFS_DELEG_FIELD_SEP_CHR, (char *)data);
221 case ZFS_DELEG_CREATE:
222 case ZFS_DELEG_CREATE_SETS:
223 (void) snprintf(attr, len, "%c-%c", type,
224 ZFS_DELEG_FIELD_SEP_CHR);
226 case ZFS_DELEG_EVERYONE:
227 case ZFS_DELEG_EVERYONE_SETS:
228 (void) snprintf(attr, len, "%c%c%c", type, inheritchr,
229 ZFS_DELEG_FIELD_SEP_CHR);
232 ASSERT(!"bad zfs_deleg_who_type_t");