diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2013-02-01 06:21:47 -0500 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2013-02-13 09:15:29 -0500 |
commit | 9f309c86cf343c59c79d25d9bde5d4a895d2e81f (patch) | |
tree | 6be602b278f429a8c20795270305cb381615ccc6 /fs/nfs | |
parent | 54f834cd5501fb5fc801e4719a3ad0c894a3af2c (diff) |
nfs: Convert idmap to use kuids and kgids
Convert nfs_map_name_to_uid to return a kuid_t value.
Convert nfs_map_name_to_gid to return a kgid_t value.
Convert nfs_map_uid_to_name to take a kuid_t paramater.
Convert nfs_map_gid_to_name to take a kgid_t paramater.
Tweak nfs_fattr_map_owner_to_name to use a kuid_t intermediate value.
Tweak nfs_fattr_map_group_to_name to use a kgid_t intermediate value.
Which makes these functions properly handle kuids and kgids, including
erroring of the generated kuid or kgid is invalid.
Cc: "J. Bruce Fields" <bfields@fieldses.org>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r-- | fs/nfs/idmap.c | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c index f77017c4e28b..b9623d19d599 100644 --- a/fs/nfs/idmap.c +++ b/fs/nfs/idmap.c | |||
@@ -97,7 +97,7 @@ static void nfs_fattr_free_group_name(struct nfs_fattr *fattr) | |||
97 | static bool nfs_fattr_map_owner_name(struct nfs_server *server, struct nfs_fattr *fattr) | 97 | static bool nfs_fattr_map_owner_name(struct nfs_server *server, struct nfs_fattr *fattr) |
98 | { | 98 | { |
99 | struct nfs4_string *owner = fattr->owner_name; | 99 | struct nfs4_string *owner = fattr->owner_name; |
100 | __u32 uid; | 100 | kuid_t uid; |
101 | 101 | ||
102 | if (!(fattr->valid & NFS_ATTR_FATTR_OWNER_NAME)) | 102 | if (!(fattr->valid & NFS_ATTR_FATTR_OWNER_NAME)) |
103 | return false; | 103 | return false; |
@@ -111,7 +111,7 @@ static bool nfs_fattr_map_owner_name(struct nfs_server *server, struct nfs_fattr | |||
111 | static bool nfs_fattr_map_group_name(struct nfs_server *server, struct nfs_fattr *fattr) | 111 | static bool nfs_fattr_map_group_name(struct nfs_server *server, struct nfs_fattr *fattr) |
112 | { | 112 | { |
113 | struct nfs4_string *group = fattr->group_name; | 113 | struct nfs4_string *group = fattr->group_name; |
114 | __u32 gid; | 114 | kgid_t gid; |
115 | 115 | ||
116 | if (!(fattr->valid & NFS_ATTR_FATTR_GROUP_NAME)) | 116 | if (!(fattr->valid & NFS_ATTR_FATTR_GROUP_NAME)) |
117 | return false; | 117 | return false; |
@@ -837,43 +837,61 @@ idmap_release_pipe(struct inode *inode) | |||
837 | nfs_idmap_abort_pipe_upcall(idmap, -EPIPE); | 837 | nfs_idmap_abort_pipe_upcall(idmap, -EPIPE); |
838 | } | 838 | } |
839 | 839 | ||
840 | int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid) | 840 | int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, kuid_t *uid) |
841 | { | 841 | { |
842 | struct idmap *idmap = server->nfs_client->cl_idmap; | 842 | struct idmap *idmap = server->nfs_client->cl_idmap; |
843 | __u32 id = -1; | ||
844 | int ret = 0; | ||
843 | 845 | ||
844 | if (nfs_map_string_to_numeric(name, namelen, uid)) | 846 | if (!nfs_map_string_to_numeric(name, namelen, &id)) |
845 | return 0; | 847 | ret = nfs_idmap_lookup_id(name, namelen, "uid", &id, idmap); |
846 | return nfs_idmap_lookup_id(name, namelen, "uid", uid, idmap); | 848 | if (ret == 0) { |
849 | *uid = make_kuid(&init_user_ns, id); | ||
850 | if (!uid_valid(*uid)) | ||
851 | ret = -ERANGE; | ||
852 | } | ||
853 | return ret; | ||
847 | } | 854 | } |
848 | 855 | ||
849 | int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *gid) | 856 | int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, kgid_t *gid) |
850 | { | 857 | { |
851 | struct idmap *idmap = server->nfs_client->cl_idmap; | 858 | struct idmap *idmap = server->nfs_client->cl_idmap; |
859 | __u32 id = -1; | ||
860 | int ret = 0; | ||
852 | 861 | ||
853 | if (nfs_map_string_to_numeric(name, namelen, gid)) | 862 | if (!nfs_map_string_to_numeric(name, namelen, &id)) |
854 | return 0; | 863 | ret = nfs_idmap_lookup_id(name, namelen, "gid", &id, idmap); |
855 | return nfs_idmap_lookup_id(name, namelen, "gid", gid, idmap); | 864 | if (ret == 0) { |
865 | *gid = make_kgid(&init_user_ns, id); | ||
866 | if (!gid_valid(*gid)) | ||
867 | ret = -ERANGE; | ||
868 | } | ||
869 | return ret; | ||
856 | } | 870 | } |
857 | 871 | ||
858 | int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen) | 872 | int nfs_map_uid_to_name(const struct nfs_server *server, kuid_t uid, char *buf, size_t buflen) |
859 | { | 873 | { |
860 | struct idmap *idmap = server->nfs_client->cl_idmap; | 874 | struct idmap *idmap = server->nfs_client->cl_idmap; |
861 | int ret = -EINVAL; | 875 | int ret = -EINVAL; |
876 | __u32 id; | ||
862 | 877 | ||
878 | id = from_kuid(&init_user_ns, uid); | ||
863 | if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) | 879 | if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) |
864 | ret = nfs_idmap_lookup_name(uid, "user", buf, buflen, idmap); | 880 | ret = nfs_idmap_lookup_name(id, "user", buf, buflen, idmap); |
865 | if (ret < 0) | 881 | if (ret < 0) |
866 | ret = nfs_map_numeric_to_string(uid, buf, buflen); | 882 | ret = nfs_map_numeric_to_string(id, buf, buflen); |
867 | return ret; | 883 | return ret; |
868 | } | 884 | } |
869 | int nfs_map_gid_to_group(const struct nfs_server *server, __u32 gid, char *buf, size_t buflen) | 885 | int nfs_map_gid_to_group(const struct nfs_server *server, kgid_t gid, char *buf, size_t buflen) |
870 | { | 886 | { |
871 | struct idmap *idmap = server->nfs_client->cl_idmap; | 887 | struct idmap *idmap = server->nfs_client->cl_idmap; |
872 | int ret = -EINVAL; | 888 | int ret = -EINVAL; |
889 | __u32 id; | ||
873 | 890 | ||
891 | id = from_kgid(&init_user_ns, gid); | ||
874 | if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) | 892 | if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) |
875 | ret = nfs_idmap_lookup_name(gid, "group", buf, buflen, idmap); | 893 | ret = nfs_idmap_lookup_name(id, "group", buf, buflen, idmap); |
876 | if (ret < 0) | 894 | if (ret < 0) |
877 | ret = nfs_map_numeric_to_string(gid, buf, buflen); | 895 | ret = nfs_map_numeric_to_string(id, buf, buflen); |
878 | return ret; | 896 | return ret; |
879 | } | 897 | } |