Ejemplo n.º 1
0
static ssize_t nfs_idmap_get_key(const char *name, size_t namelen,
				 const char *type, void *data,
				 size_t data_size, struct idmap *idmap)
{
	ssize_t ret = nfs_idmap_request_key(&key_type_id_resolver,
					    name, namelen, type, data,
					    data_size, NULL);
	if (ret < 0) {
		ret = nfs_idmap_request_key(&key_type_id_resolver_legacy,
					    name, namelen, type, data,
					    data_size, idmap);
	}
	return ret;
}
Ejemplo n.º 2
0
/* ID -> Name */
static ssize_t nfs_idmap_lookup_name(__u32 id, const char *type, char *buf, size_t buflen)
{
    char id_str[NFS_UINT_MAXLEN];
    int id_len;
    ssize_t ret;

    id_len = snprintf(id_str, sizeof(id_str), "%u", id);
    ret = nfs_idmap_request_key(id_str, id_len, type, buf, buflen);
    if (ret < 0)
        return -EINVAL;
    return ret;
}
Ejemplo n.º 3
0
/* Name -> ID */
static int nfs_idmap_lookup_id(const char *name, size_t namelen,
                               const char *type, __u32 *id)
{
    char id_str[NFS_UINT_MAXLEN];
    long id_long;
    ssize_t data_size;
    int ret = 0;

    data_size = nfs_idmap_request_key(name, namelen, type, id_str, NFS_UINT_MAXLEN);
    if (data_size <= 0) {
        ret = -EINVAL;
    } else {
        ret = strict_strtol(id_str, 10, &id_long);
        *id = (__u32)id_long;
    }
    return ret;
}
Ejemplo n.º 4
0
static ssize_t nfs_idmap_get_key(const char *name, size_t namelen,
				 const char *type, void *data,
				 size_t data_size, struct idmap *idmap)
{
	const struct cred *saved_cred;
	struct key *rkey;
	struct user_key_payload *payload;
	ssize_t ret;

	saved_cred = override_creds(id_resolver_cache);
	rkey = nfs_idmap_request_key(name, namelen, type, idmap);
	revert_creds(saved_cred);

	if (IS_ERR(rkey)) {
		ret = PTR_ERR(rkey);
		goto out;
	}

	rcu_read_lock();
	rkey->perm |= KEY_USR_VIEW;

	ret = key_validate(rkey);
	if (ret < 0)
		goto out_up;

	payload = rcu_dereference(rkey->payload.rcudata);
	if (IS_ERR_OR_NULL(payload)) {
		ret = PTR_ERR(payload);
		goto out_up;
	}

	ret = payload->datalen;
	if (ret > 0 && ret <= data_size)
		memcpy(data, payload->data, ret);
	else
		ret = -EINVAL;

out_up:
	rcu_read_unlock();
	key_put(rkey);
out:
	return ret;
}