Esempio n. 1
0
/*
 * Get the label if any of a zfs filesystem.  Get the dataset, then
 * get its mlslabel property, convert as needed, and return it.  If
 * there's no mlslabel or it is the default one, return NULL.
 */
static ts_label_t *
getflabel_zfs(vfs_t *vfsp)
{
	int		error;
	ts_label_t	*tsl = NULL;
	refstr_t	*resource_ref;
	bslabel_t	ds_sl;
	char		ds_hexsl[MAXNAMELEN];
	const char	*osname;

	resource_ref = vfs_getresource(vfsp);
	osname = refstr_value(resource_ref);

	error = dsl_prop_get(osname, zfs_prop_to_name(ZFS_PROP_MLSLABEL),
	    1, sizeof (ds_hexsl), &ds_hexsl, NULL);
	refstr_rele(resource_ref);

	if ((error) || (strcasecmp(ds_hexsl, ZFS_MLSLABEL_DEFAULT) == 0))
		return (NULL);
	if (hexstr_to_label(ds_hexsl, &ds_sl) != 0)
		return (NULL);

	tsl = labelalloc(&ds_sl, default_doi, KM_SLEEP);
	return (tsl);
}
Esempio n. 2
0
/*
 * Get the current property value.  It may have changed by the time this
 * function returns, so it is NOT safe to follow up with
 * dsl_prop_register() and assume that the value has not changed in
 * between.
 *
 * Return 0 on success, ENOENT if ddname is invalid.
 */
int
dsl_prop_get_integer(const char *ddname, const char *propname,
    uint64_t *valuep, char *setpoint)
{
	return (dsl_prop_get(ddname, propname, 8, 1, valuep, setpoint));
}
Esempio n. 3
0
int
dsl_crypto_key_inherit(const char *dsname)
{
    char keysource[MAXNAMELEN];
    char setpoint[MAXNAMELEN];
    dsl_dataset_t *ids;
    int error;
    zcrypt_key_t *wrappingkey;
    zfs_crypt_key_status_t keystatus;
    spa_t *spa;
    dsl_pool_t *dp;

    /*
     * Try inheriting the wrapping key from our parent
     */
    error = dsl_pool_hold(dsname, FTAG, &dp);
    if (error != 0)
        return (error);

    error = dsl_dataset_keystatus_byname(dp, dsname, &keystatus);
    if (error != 0) {
        dsl_pool_rele(dp, FTAG);
        return (error);
    }
    if (keystatus == ZFS_CRYPT_KEY_NONE) {
        dsl_pool_rele(dp, FTAG);
        return (0);
    }
    if (keystatus == ZFS_CRYPT_KEY_AVAILABLE) {
        dsl_pool_rele(dp, FTAG);
        return (EEXIST);
    }

    error = dsl_prop_get(dsname, zfs_prop_to_name(ZFS_PROP_KEYSOURCE), 1,
                         sizeof (keysource), &keysource, setpoint);
    if (error != 0) {
        dsl_pool_rele(dp, FTAG);
        return (error);
    }

    if (strcmp(setpoint, dsname) == 0) {
        dsl_pool_rele(dp, FTAG);
        return (ENOENT);
    }

    error = dsl_dataset_hold(dp, setpoint, FTAG, &ids);
    if (error != 0) {
        dsl_pool_rele(dp, FTAG);
        return (error);
    }

    spa = dsl_dataset_get_spa(ids);
    wrappingkey = zcrypt_key_copy(zcrypt_keystore_find_wrappingkey(spa,
                                  ids->ds_object));
    dsl_dataset_rele(ids, FTAG);
    dsl_pool_rele(dp, FTAG);

    if (wrappingkey == NULL)
        return (ENOENT);

    error = dsl_crypto_key_load(dsname, wrappingkey);

    return (error);
}