- deleg_type |= ZFS_DELEG_PERM_LOCAL;
- break;
- case 'd':
- if (who_type == ZFS_DELEG_CREATE ||
- who_type == ZFS_DELEG_NAMED_SET)
- usage(B_FALSE);
-
- deleg_type |= ZFS_DELEG_PERM_DESCENDENT;
- break;
- case 'r':
- *recurse = B_TRUE;
- break;
- case 'c':
- if (who_type != ZFS_DELEG_WHO_UNKNOWN)
- usage(B_FALSE);
- if (deleg_type)
- usage(B_FALSE);
- who_type = ZFS_DELEG_CREATE;
- break;
- case 's':
- if (who_type != ZFS_DELEG_WHO_UNKNOWN)
- usage(B_FALSE);
- if (deleg_type)
- usage(B_FALSE);
- who_type = ZFS_DELEG_NAMED_SET;
- break;
- case 'u':
- if (who_type != ZFS_DELEG_WHO_UNKNOWN)
- usage(B_FALSE);
- who_type = ZFS_DELEG_USER;
- who = optarg;
- break;
- case 'g':
- if (who_type != ZFS_DELEG_WHO_UNKNOWN)
- usage(B_FALSE);
- who_type = ZFS_DELEG_GROUP;
- who = optarg;
- break;
- case 'e':
- if (who_type != ZFS_DELEG_WHO_UNKNOWN)
- usage(B_FALSE);
- who_type = ZFS_DELEG_EVERYONE;
- break;
- default:
- usage(B_FALSE);
- break;
- }
- }
-
- if (deleg_type == 0)
- deleg_type = ZFS_DELEG_PERM_LOCALDESCENDENT;
-
- *argc -= optind;
- *argv += optind;
-
- if (unallow == B_FALSE && *argc == 1) {
- /*
- * Only print permissions if no options were processed
- */
- if (optind == 1)
- return (1);
- else
- usage(B_FALSE);
- }
-
- /*
- * initialize variables for zfs_build_perms based on number
- * of arguments.
- * 3 arguments ==> zfs [un]allow joe perm,perm,perm <dataset> or
- * zfs [un]allow -s @set1 perm,perm <dataset>
- * 2 arguments ==> zfs [un]allow -c perm,perm <dataset> or
- * zfs [un]allow -u|-g <name> perm <dataset> or
- * zfs [un]allow -e perm,perm <dataset>
- * zfs unallow joe <dataset>
- * zfs unallow -s @set1 <dataset>
- * 1 argument ==> zfs [un]allow -e <dataset> or
- * zfs [un]allow -c <dataset>
- */
-
- switch (*argc) {
- case 3:
- perms = (*argv)[1];
- who = (*argv)[0];
- *ds = (*argv)[2];
-
- /*
- * advance argc/argv for do_allow cases.
- * for do_allow case make sure who have a know who type
- * and its not a permission set.
- */
- if (unallow == B_TRUE) {
- *argc -= 2;
- *argv += 2;
- } else if (who_type != ZFS_DELEG_WHO_UNKNOWN &&
- who_type != ZFS_DELEG_NAMED_SET)
- usage(B_FALSE);
- break;
-
- case 2:
- if (unallow == B_TRUE && (who_type == ZFS_DELEG_EVERYONE ||
- who_type == ZFS_DELEG_CREATE || who != NULL)) {
- perms = (*argv)[0];
- *ds = (*argv)[1];
- } else {
- if (unallow == B_FALSE &&
- (who_type == ZFS_DELEG_WHO_UNKNOWN ||
- who_type == ZFS_DELEG_NAMED_SET))
- usage(B_FALSE);
- else if (who_type == ZFS_DELEG_WHO_UNKNOWN ||
- who_type == ZFS_DELEG_NAMED_SET)
- who = (*argv)[0];
- else if (who_type != ZFS_DELEG_NAMED_SET)
- perms = (*argv)[0];
- *ds = (*argv)[1];
- }
- if (unallow == B_TRUE) {
- (*argc)--;
- (*argv)++;
- }
- break;
-
- case 1:
- if (unallow == B_FALSE)
- usage(B_FALSE);
- if (who == NULL && who_type != ZFS_DELEG_CREATE &&
- who_type != ZFS_DELEG_EVERYONE)
- usage(B_FALSE);
- *ds = (*argv)[0];
- break;
-
- default:
- usage(B_FALSE);
- }
-
- if (strrchr(*ds, '@')) {
- (void) fprintf(stderr,
- gettext("Can't set or remove 'allow' permissions "
- "on snapshots.\n"));
- return (-1);
- }
-
- if ((zhp = zfs_open(g_zfs, *ds, ZFS_TYPE_DATASET)) == NULL)
- return (-1);
-
- if ((zfs_build_perms(zhp, who, perms,
- who_type, deleg_type, zperms)) != 0) {
- zfs_close(zhp);
- return (-1);
- }
- zfs_close(zhp);
- return (0);
-}
-
-static int
-zfs_do_allow(int argc, char **argv)
-{
- char *ds;
- nvlist_t *zperms = NULL;
- zfs_handle_t *zhp;
- int unused;
- int ret;
-
- if ((ret = parse_allow_args(&argc, &argv, B_FALSE, &ds,
- &unused, &zperms)) == -1)
- return (1);
-
- if (ret == 1)
- return (zfs_print_allows(argv[0]));
-
- if ((zhp = zfs_open(g_zfs, ds, ZFS_TYPE_DATASET)) == NULL)
- return (1);
-
- if (zfs_perm_set(zhp, zperms)) {
- zfs_close(zhp);
- nvlist_free(zperms);
- return (1);
- }
- nvlist_free(zperms);
- zfs_close(zhp);
-
- return (0);
-}
-
-static int
-unallow_callback(zfs_handle_t *zhp, void *data)
-{
- nvlist_t *nvp = (nvlist_t *)data;
- int error;
-
- error = zfs_perm_remove(zhp, nvp);
- if (error) {
- (void) fprintf(stderr, gettext("Failed to remove permissions "
- "on %s\n"), zfs_get_name(zhp));
- }
- return (error);
-}
-
-static int
-zfs_do_unallow(int argc, char **argv)
-{
- int recurse = B_FALSE;
- char *ds;
- int error;
- nvlist_t *zperms = NULL;
- int flags = 0;
-
- if (parse_allow_args(&argc, &argv, B_TRUE,
- &ds, &recurse, &zperms) == -1)
- return (1);
-
- if (recurse)
- flags |= ZFS_ITER_RECURSE;
- error = zfs_for_each(argc, argv, flags,
- ZFS_TYPE_FILESYSTEM|ZFS_TYPE_VOLUME, NULL,
- NULL, unallow_callback, (void *)zperms);
-
- if (zperms)
- nvlist_free(zperms);
-
- return (error);
-}
-
-typedef struct get_all_cbdata {
- zfs_handle_t **cb_handles;
- size_t cb_alloc;
- size_t cb_used;
- uint_t cb_types;
- boolean_t cb_verbose;
-} get_all_cbdata_t;
-
-#define CHECK_SPINNER 30
-#define SPINNER_TIME 3 /* seconds */
-#define MOUNT_TIME 5 /* seconds */