diff options
Diffstat (limited to 'fs/nfsd/nfs4idmap.c')
-rw-r--r-- | fs/nfsd/nfs4idmap.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c index a1f10c0a6255..0ce12346df9c 100644 --- a/fs/nfsd/nfs4idmap.c +++ b/fs/nfsd/nfs4idmap.c | |||
@@ -65,7 +65,7 @@ MODULE_PARM_DESC(nfs4_disable_idmapping, | |||
65 | struct ent { | 65 | struct ent { |
66 | struct cache_head h; | 66 | struct cache_head h; |
67 | int type; /* User / Group */ | 67 | int type; /* User / Group */ |
68 | uid_t id; | 68 | u32 id; |
69 | char name[IDMAP_NAMESZ]; | 69 | char name[IDMAP_NAMESZ]; |
70 | char authname[IDMAP_NAMESZ]; | 70 | char authname[IDMAP_NAMESZ]; |
71 | }; | 71 | }; |
@@ -540,7 +540,7 @@ rqst_authname(struct svc_rqst *rqstp) | |||
540 | 540 | ||
541 | static __be32 | 541 | static __be32 |
542 | idmap_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen, | 542 | idmap_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen, |
543 | uid_t *id) | 543 | u32 *id) |
544 | { | 544 | { |
545 | struct ent *item, key = { | 545 | struct ent *item, key = { |
546 | .type = type, | 546 | .type = type, |
@@ -564,7 +564,7 @@ idmap_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen | |||
564 | } | 564 | } |
565 | 565 | ||
566 | static int | 566 | static int |
567 | idmap_id_to_name(struct svc_rqst *rqstp, int type, uid_t id, char *name) | 567 | idmap_id_to_name(struct svc_rqst *rqstp, int type, u32 id, char *name) |
568 | { | 568 | { |
569 | struct ent *item, key = { | 569 | struct ent *item, key = { |
570 | .id = id, | 570 | .id = id, |
@@ -587,7 +587,7 @@ idmap_id_to_name(struct svc_rqst *rqstp, int type, uid_t id, char *name) | |||
587 | } | 587 | } |
588 | 588 | ||
589 | static bool | 589 | static bool |
590 | numeric_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen, uid_t *id) | 590 | numeric_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen, u32 *id) |
591 | { | 591 | { |
592 | int ret; | 592 | int ret; |
593 | char buf[11]; | 593 | char buf[11]; |
@@ -603,7 +603,7 @@ numeric_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namel | |||
603 | } | 603 | } |
604 | 604 | ||
605 | static __be32 | 605 | static __be32 |
606 | do_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen, uid_t *id) | 606 | do_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen, u32 *id) |
607 | { | 607 | { |
608 | if (nfs4_disable_idmapping && rqstp->rq_cred.cr_flavor < RPC_AUTH_GSS) | 608 | if (nfs4_disable_idmapping && rqstp->rq_cred.cr_flavor < RPC_AUTH_GSS) |
609 | if (numeric_name_to_id(rqstp, type, name, namelen, id)) | 609 | if (numeric_name_to_id(rqstp, type, name, namelen, id)) |
@@ -616,7 +616,7 @@ do_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen, u | |||
616 | } | 616 | } |
617 | 617 | ||
618 | static int | 618 | static int |
619 | do_id_to_name(struct svc_rqst *rqstp, int type, uid_t id, char *name) | 619 | do_id_to_name(struct svc_rqst *rqstp, int type, u32 id, char *name) |
620 | { | 620 | { |
621 | if (nfs4_disable_idmapping && rqstp->rq_cred.cr_flavor < RPC_AUTH_GSS) | 621 | if (nfs4_disable_idmapping && rqstp->rq_cred.cr_flavor < RPC_AUTH_GSS) |
622 | return sprintf(name, "%u", id); | 622 | return sprintf(name, "%u", id); |
@@ -625,26 +625,40 @@ do_id_to_name(struct svc_rqst *rqstp, int type, uid_t id, char *name) | |||
625 | 625 | ||
626 | __be32 | 626 | __be32 |
627 | nfsd_map_name_to_uid(struct svc_rqst *rqstp, const char *name, size_t namelen, | 627 | nfsd_map_name_to_uid(struct svc_rqst *rqstp, const char *name, size_t namelen, |
628 | __u32 *id) | 628 | kuid_t *uid) |
629 | { | 629 | { |
630 | return do_name_to_id(rqstp, IDMAP_TYPE_USER, name, namelen, id); | 630 | __be32 status; |
631 | u32 id = -1; | ||
632 | status = do_name_to_id(rqstp, IDMAP_TYPE_USER, name, namelen, &id); | ||
633 | *uid = make_kuid(&init_user_ns, id); | ||
634 | if (!uid_valid(*uid)) | ||
635 | status = nfserr_badowner; | ||
636 | return status; | ||
631 | } | 637 | } |
632 | 638 | ||
633 | __be32 | 639 | __be32 |
634 | nfsd_map_name_to_gid(struct svc_rqst *rqstp, const char *name, size_t namelen, | 640 | nfsd_map_name_to_gid(struct svc_rqst *rqstp, const char *name, size_t namelen, |
635 | __u32 *id) | 641 | kgid_t *gid) |
636 | { | 642 | { |
637 | return do_name_to_id(rqstp, IDMAP_TYPE_GROUP, name, namelen, id); | 643 | __be32 status; |
644 | u32 id = -1; | ||
645 | status = do_name_to_id(rqstp, IDMAP_TYPE_GROUP, name, namelen, &id); | ||
646 | *gid = make_kgid(&init_user_ns, id); | ||
647 | if (!gid_valid(*gid)) | ||
648 | status = nfserr_badowner; | ||
649 | return status; | ||
638 | } | 650 | } |
639 | 651 | ||
640 | int | 652 | int |
641 | nfsd_map_uid_to_name(struct svc_rqst *rqstp, __u32 id, char *name) | 653 | nfsd_map_uid_to_name(struct svc_rqst *rqstp, kuid_t uid, char *name) |
642 | { | 654 | { |
655 | u32 id = from_kuid(&init_user_ns, uid); | ||
643 | return do_id_to_name(rqstp, IDMAP_TYPE_USER, id, name); | 656 | return do_id_to_name(rqstp, IDMAP_TYPE_USER, id, name); |
644 | } | 657 | } |
645 | 658 | ||
646 | int | 659 | int |
647 | nfsd_map_gid_to_name(struct svc_rqst *rqstp, __u32 id, char *name) | 660 | nfsd_map_gid_to_name(struct svc_rqst *rqstp, kgid_t gid, char *name) |
648 | { | 661 | { |
662 | u32 id = from_kgid(&init_user_ns, gid); | ||
649 | return do_id_to_name(rqstp, IDMAP_TYPE_GROUP, id, name); | 663 | return do_id_to_name(rqstp, IDMAP_TYPE_GROUP, id, name); |
650 | } | 664 | } |