aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2011-02-22 18:44:31 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2011-03-11 15:39:26 -0500
commit5cf36cfdc8caa2724738ad0842c5c3dd02f309dc (patch)
tree2a863892f48d4f437c9cf2f3cad5951bf6962bc4 /fs/nfs
parent75247affd7930cc3dcf57f850f0d7898379ef3b3 (diff)
NFSv4: If the server sends us a numeric uid/gid then accept it
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/idmap.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c
index 18696882f1c6..cbe6e2fa8cef 100644
--- a/fs/nfs/idmap.c
+++ b/fs/nfs/idmap.c
@@ -33,6 +33,24 @@
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */ 35 */
36#include <linux/types.h>
37#include <linux/string.h>
38#include <linux/kernel.h>
39
40static int nfs_map_string_to_numeric(const char *name, size_t namelen, __u32 *res)
41{
42 unsigned long val;
43 char buf[16];
44
45 if (memchr(name, '@', namelen) != NULL || namelen >= sizeof(buf))
46 return 0;
47 memcpy(buf, name, namelen);
48 buf[namelen] = '\0';
49 if (strict_strtoul(buf, 0, &val) != 0)
50 return 0;
51 *res = val;
52 return 1;
53}
36 54
37#ifdef CONFIG_NFS_USE_NEW_IDMAPPER 55#ifdef CONFIG_NFS_USE_NEW_IDMAPPER
38 56
@@ -42,7 +60,6 @@
42#include <linux/keyctl.h> 60#include <linux/keyctl.h>
43#include <linux/key-type.h> 61#include <linux/key-type.h>
44#include <linux/rcupdate.h> 62#include <linux/rcupdate.h>
45#include <linux/kernel.h>
46#include <linux/err.h> 63#include <linux/err.h>
47 64
48#include <keys/user-type.h> 65#include <keys/user-type.h>
@@ -221,11 +238,15 @@ static int nfs_idmap_lookup_id(const char *name, size_t namelen,
221 238
222int nfs_map_name_to_uid(struct nfs_client *clp, const char *name, size_t namelen, __u32 *uid) 239int nfs_map_name_to_uid(struct nfs_client *clp, const char *name, size_t namelen, __u32 *uid)
223{ 240{
241 if (nfs_map_string_to_numeric(name, namelen, uid))
242 return 0;
224 return nfs_idmap_lookup_id(name, namelen, "uid", uid); 243 return nfs_idmap_lookup_id(name, namelen, "uid", uid);
225} 244}
226 245
227int nfs_map_group_to_gid(struct nfs_client *clp, const char *name, size_t namelen, __u32 *gid) 246int nfs_map_group_to_gid(struct nfs_client *clp, const char *name, size_t namelen, __u32 *gid)
228{ 247{
248 if (nfs_map_string_to_numeric(name, namelen, gid))
249 return 0;
229 return nfs_idmap_lookup_id(name, namelen, "gid", gid); 250 return nfs_idmap_lookup_id(name, namelen, "gid", gid);
230} 251}
231 252
@@ -243,7 +264,6 @@ int nfs_map_gid_to_group(struct nfs_client *clp, __u32 gid, char *buf, size_t bu
243#include <linux/module.h> 264#include <linux/module.h>
244#include <linux/mutex.h> 265#include <linux/mutex.h>
245#include <linux/init.h> 266#include <linux/init.h>
246#include <linux/types.h>
247#include <linux/slab.h> 267#include <linux/slab.h>
248#include <linux/socket.h> 268#include <linux/socket.h>
249#include <linux/in.h> 269#include <linux/in.h>
@@ -699,6 +719,8 @@ int nfs_map_name_to_uid(struct nfs_client *clp, const char *name, size_t namelen
699{ 719{
700 struct idmap *idmap = clp->cl_idmap; 720 struct idmap *idmap = clp->cl_idmap;
701 721
722 if (nfs_map_string_to_numeric(name, namelen, uid))
723 return 0;
702 return nfs_idmap_id(idmap, &idmap->idmap_user_hash, name, namelen, uid); 724 return nfs_idmap_id(idmap, &idmap->idmap_user_hash, name, namelen, uid);
703} 725}
704 726
@@ -706,6 +728,8 @@ int nfs_map_group_to_gid(struct nfs_client *clp, const char *name, size_t namele
706{ 728{
707 struct idmap *idmap = clp->cl_idmap; 729 struct idmap *idmap = clp->cl_idmap;
708 730
731 if (nfs_map_string_to_numeric(name, namelen, uid))
732 return 0;
709 return nfs_idmap_id(idmap, &idmap->idmap_group_hash, name, namelen, uid); 733 return nfs_idmap_id(idmap, &idmap->idmap_group_hash, name, namelen, uid);
710} 734}
711 735