usr/src/lib/libzfs/common/libzfs_dataset.c
changeset 5993 6309c3c0a28f
parent 5977 33727f49aeaa
child 6168 51c045dcc498
equal deleted inserted replaced
5992:528b377af3c0 5993:6309c3c0a28f
  1587 	zfs_free_allows(*zfs_perms);
  1587 	zfs_free_allows(*zfs_perms);
  1588 	nvlist_free(nvlist);
  1588 	nvlist_free(nvlist);
  1589 	return (-1);
  1589 	return (-1);
  1590 }
  1590 }
  1591 
  1591 
       
  1592 static char *
       
  1593 zfs_deleg_perm_note(zfs_deleg_note_t note)
       
  1594 {
       
  1595 	/*
       
  1596 	 * Don't put newlines on end of lines
       
  1597 	 */
       
  1598 	switch (note) {
       
  1599 	case ZFS_DELEG_NOTE_CREATE:
       
  1600 		return (dgettext(TEXT_DOMAIN,
       
  1601 		    "Must also have the 'mount' ability"));
       
  1602 	case ZFS_DELEG_NOTE_DESTROY:
       
  1603 		return (dgettext(TEXT_DOMAIN,
       
  1604 		    "Must also have the 'mount' ability"));
       
  1605 	case ZFS_DELEG_NOTE_SNAPSHOT:
       
  1606 		return (dgettext(TEXT_DOMAIN,
       
  1607 		    "Must also have the 'mount' ability"));
       
  1608 	case ZFS_DELEG_NOTE_ROLLBACK:
       
  1609 		return (dgettext(TEXT_DOMAIN,
       
  1610 		    "Must also have the 'mount' ability"));
       
  1611 	case ZFS_DELEG_NOTE_CLONE:
       
  1612 		return (dgettext(TEXT_DOMAIN, "Must also have the 'create' "
       
  1613 		    "ability and 'mount'\n"
       
  1614 		    "\t\t\t\tability in the origin file system"));
       
  1615 	case ZFS_DELEG_NOTE_PROMOTE:
       
  1616 		return (dgettext(TEXT_DOMAIN, "Must also have the 'mount'\n"
       
  1617 		    "\t\t\t\tand 'promote' ability in the origin file system"));
       
  1618 	case ZFS_DELEG_NOTE_RENAME:
       
  1619 		return (dgettext(TEXT_DOMAIN, "Must also have the 'mount' "
       
  1620 		    "and 'create' \n\t\t\t\tability in the new parent"));
       
  1621 	case ZFS_DELEG_NOTE_RECEIVE:
       
  1622 		return (dgettext(TEXT_DOMAIN, "Must also have the 'mount'"
       
  1623 		    " and 'create' ability"));
       
  1624 	case ZFS_DELEG_NOTE_USERPROP:
       
  1625 		return (dgettext(TEXT_DOMAIN,
       
  1626 		    "Allows changing any user property"));
       
  1627 	case ZFS_DELEG_NOTE_ALLOW:
       
  1628 		return (dgettext(TEXT_DOMAIN,
       
  1629 		    "Must also have the permission that is being\n"
       
  1630 		    "\t\t\t\tallowed"));
       
  1631 	case ZFS_DELEG_NOTE_MOUNT:
       
  1632 		return (dgettext(TEXT_DOMAIN,
       
  1633 		    "Allows mount/umount of ZFS datasets"));
       
  1634 	case ZFS_DELEG_NOTE_SHARE:
       
  1635 		return (dgettext(TEXT_DOMAIN,
       
  1636 		    "Allows sharing file systems over NFS or SMB\n"
       
  1637 		    "\t\t\t\tprotocols"));
       
  1638 	case ZFS_DELEG_NOTE_NONE:
       
  1639 	default:
       
  1640 		return (dgettext(TEXT_DOMAIN, ""));
       
  1641 	}
       
  1642 }
       
  1643 
       
  1644 typedef enum {
       
  1645 	ZFS_DELEG_SUBCOMMAND,
       
  1646 	ZFS_DELEG_PROP,
       
  1647 	ZFS_DELEG_OTHER
       
  1648 } zfs_deleg_perm_type_t;
       
  1649 
       
  1650 /*
       
  1651  * is the permission a subcommand or other?
       
  1652  */
       
  1653 zfs_deleg_perm_type_t
       
  1654 zfs_deleg_perm_type(const char *perm)
       
  1655 {
       
  1656 	if (strcmp(perm, "userprop") == 0)
       
  1657 		return (ZFS_DELEG_OTHER);
       
  1658 	else
       
  1659 		return (ZFS_DELEG_SUBCOMMAND);
       
  1660 }
       
  1661 
       
  1662 static char *
       
  1663 zfs_deleg_perm_type_str(zfs_deleg_perm_type_t type)
       
  1664 {
       
  1665 	switch (type) {
       
  1666 	case ZFS_DELEG_SUBCOMMAND:
       
  1667 		return (dgettext(TEXT_DOMAIN, "subcommand"));
       
  1668 	case ZFS_DELEG_PROP:
       
  1669 		return (dgettext(TEXT_DOMAIN, "property"));
       
  1670 	case ZFS_DELEG_OTHER:
       
  1671 		return (dgettext(TEXT_DOMAIN, "other"));
       
  1672 	}
       
  1673 	return ("");
       
  1674 }
       
  1675 
       
  1676 /*ARGSUSED*/
       
  1677 static int
       
  1678 zfs_deleg_prop_cb(int prop, void *cb)
       
  1679 {
       
  1680 	if (zfs_prop_delegatable(prop))
       
  1681 		(void) fprintf(stderr, "%-15s %-15s\n", zfs_prop_to_name(prop),
       
  1682 		    zfs_deleg_perm_type_str(ZFS_DELEG_PROP));
       
  1683 
       
  1684 	return (ZPROP_CONT);
       
  1685 }
       
  1686 
       
  1687 void
       
  1688 zfs_deleg_permissions(void)
       
  1689 {
       
  1690 	int i;
       
  1691 
       
  1692 	(void) fprintf(stderr, "\n%-15s %-15s\t%s\n\n", "NAME",
       
  1693 	    "TYPE", "NOTES");
       
  1694 
       
  1695 	/*
       
  1696 	 * First print out the subcommands
       
  1697 	 */
       
  1698 	for (i = 0; zfs_deleg_perm_tab[i].z_perm != NULL; i++) {
       
  1699 		(void) fprintf(stderr, "%-15s %-15s\t%s\n",
       
  1700 		    zfs_deleg_perm_tab[i].z_perm,
       
  1701 		    zfs_deleg_perm_type_str(
       
  1702 		    zfs_deleg_perm_type(zfs_deleg_perm_tab[i].z_perm)),
       
  1703 		    zfs_deleg_perm_note(zfs_deleg_perm_tab[i].z_note));
       
  1704 	}
       
  1705 
       
  1706 	(void) zprop_iter(zfs_deleg_prop_cb, NULL, B_FALSE, B_TRUE,
       
  1707 	    ZFS_TYPE_DATASET|ZFS_TYPE_VOLUME);
       
  1708 }
       
  1709 
  1592 /*
  1710 /*
  1593  * Given a property name and value, set the property for the given dataset.
  1711  * Given a property name and value, set the property for the given dataset.
  1594  */
  1712  */
  1595 int
  1713 int
  1596 zfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval)
  1714 zfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval)