^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Mapping of UID/GIDs to name and vice versa.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2002, 2003 The Regents of the University of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Michigan. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Marius Aamodt Eriksen <marius@umich.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * 1. Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * 2. Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * notice, this list of conditions and the following disclaimer in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * documentation and/or other materials provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * 3. Neither the name of the University nor the names of its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * contributors may be used to endorse or promote products derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/sunrpc/svc_xprt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include "idmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include "nfsd.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include "netns.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * Turn off idmapping when using AUTH_SYS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static bool nfs4_disable_idmapping = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) module_param(nfs4_disable_idmapping, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) MODULE_PARM_DESC(nfs4_disable_idmapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) "Turn off server's NFSv4 idmapping when using 'sec=sys'");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * Cache entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * XXX we know that IDMAP_NAMESZ < PAGE_SIZE, but it's ugly to rely on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct ent {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct cache_head h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int type; /* User / Group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) char name[IDMAP_NAMESZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) char authname[IDMAP_NAMESZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct rcu_head rcu_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* Common entry handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define ENT_HASHBITS 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define ENT_HASHMAX (1 << ENT_HASHBITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ent_init(struct cache_head *cnew, struct cache_head *citm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct ent *new = container_of(cnew, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct ent *itm = container_of(citm, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) new->id = itm->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) new->type = itm->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) strlcpy(new->name, itm->name, sizeof(new->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) strlcpy(new->authname, itm->authname, sizeof(new->authname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) ent_put(struct kref *ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct ent *map = container_of(ref, struct ent, h.ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) kfree_rcu(map, rcu_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static struct cache_head *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ent_alloc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct ent *e = kmalloc(sizeof(*e), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return &e->h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * ID -> Name cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) idtoname_hash(struct ent *ent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) uint32_t hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) hash = hash_str(ent->authname, ENT_HASHBITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) hash = hash_long(hash ^ ent->id, ENT_HASHBITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* Flip LSB for user/group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (ent->type == IDMAP_TYPE_GROUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) hash ^= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) idtoname_upcall(struct cache_detail *cd, struct cache_head *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return sunrpc_cache_pipe_upcall_timeout(cd, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) idtoname_request(struct cache_detail *cd, struct cache_head *ch, char **bpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) int *blen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct ent *ent = container_of(ch, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) char idstr[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) qword_add(bpp, blen, ent->authname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) snprintf(idstr, sizeof(idstr), "%u", ent->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) qword_add(bpp, blen, ent->type == IDMAP_TYPE_GROUP ? "group" : "user");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) qword_add(bpp, blen, idstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) (*bpp)[-1] = '\n';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) idtoname_match(struct cache_head *ca, struct cache_head *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct ent *a = container_of(ca, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct ent *b = container_of(cb, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return (a->id == b->id && a->type == b->type &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) strcmp(a->authname, b->authname) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) idtoname_show(struct seq_file *m, struct cache_detail *cd, struct cache_head *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct ent *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (h == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) seq_puts(m, "#domain type id [name]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) ent = container_of(h, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) seq_printf(m, "%s %s %u", ent->authname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) ent->type == IDMAP_TYPE_GROUP ? "group" : "user",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ent->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (test_bit(CACHE_VALID, &h->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) seq_printf(m, " %s", ent->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) warn_no_idmapd(struct cache_detail *detail, int has_died)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) printk("nfsd: nfsv4 idmapping failing: has idmapd %s?\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) has_died ? "died" : "not been started");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static int idtoname_parse(struct cache_detail *, char *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static struct ent *idtoname_lookup(struct cache_detail *, struct ent *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static struct ent *idtoname_update(struct cache_detail *, struct ent *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct ent *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static const struct cache_detail idtoname_cache_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) .hash_size = ENT_HASHMAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) .name = "nfs4.idtoname",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) .cache_put = ent_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) .cache_upcall = idtoname_upcall,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) .cache_request = idtoname_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) .cache_parse = idtoname_parse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) .cache_show = idtoname_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) .warn_no_listener = warn_no_idmapd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .match = idtoname_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) .init = ent_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) .update = ent_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) .alloc = ent_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) idtoname_parse(struct cache_detail *cd, char *buf, int buflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct ent ent, *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) char *buf1, *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) int error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (buf[buflen - 1] != '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return (-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) buf[buflen - 1]= '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) buf1 = kmalloc(PAGE_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (buf1 == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return (-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) memset(&ent, 0, sizeof(ent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* Authentication name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) len = qword_get(&buf, buf1, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (len <= 0 || len >= IDMAP_NAMESZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) memcpy(ent.authname, buf1, sizeof(ent.authname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* Type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (qword_get(&buf, buf1, PAGE_SIZE) <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) ent.type = strcmp(buf1, "user") == 0 ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) IDMAP_TYPE_USER : IDMAP_TYPE_GROUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /* ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (qword_get(&buf, buf1, PAGE_SIZE) <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) ent.id = simple_strtoul(buf1, &bp, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (bp == buf1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* expiry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) ent.h.expiry_time = get_expiry(&buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (ent.h.expiry_time == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) res = idtoname_lookup(cd, &ent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (!res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /* Name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) len = qword_get(&buf, buf1, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (len < 0 || len >= IDMAP_NAMESZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (len == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) set_bit(CACHE_NEGATIVE, &ent.h.flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) memcpy(ent.name, buf1, sizeof(ent.name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) res = idtoname_update(cd, &ent, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (res == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) cache_put(&res->h, cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) kfree(buf1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static struct ent *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) idtoname_lookup(struct cache_detail *cd, struct ent *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct cache_head *ch = sunrpc_cache_lookup_rcu(cd, &item->h,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) idtoname_hash(item));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return container_of(ch, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static struct ent *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) idtoname_update(struct cache_detail *cd, struct ent *new, struct ent *old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct cache_head *ch = sunrpc_cache_update(cd, &new->h, &old->h,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) idtoname_hash(new));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) return container_of(ch, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * Name -> ID cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) nametoid_hash(struct ent *ent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return hash_str(ent->name, ENT_HASHBITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) nametoid_upcall(struct cache_detail *cd, struct cache_head *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return sunrpc_cache_pipe_upcall_timeout(cd, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) nametoid_request(struct cache_detail *cd, struct cache_head *ch, char **bpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int *blen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct ent *ent = container_of(ch, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) qword_add(bpp, blen, ent->authname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) qword_add(bpp, blen, ent->type == IDMAP_TYPE_GROUP ? "group" : "user");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) qword_add(bpp, blen, ent->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) (*bpp)[-1] = '\n';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) nametoid_match(struct cache_head *ca, struct cache_head *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct ent *a = container_of(ca, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct ent *b = container_of(cb, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return (a->type == b->type && strcmp(a->name, b->name) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) strcmp(a->authname, b->authname) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) nametoid_show(struct seq_file *m, struct cache_detail *cd, struct cache_head *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct ent *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (h == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) seq_puts(m, "#domain type name [id]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) ent = container_of(h, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) seq_printf(m, "%s %s %s", ent->authname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) ent->type == IDMAP_TYPE_GROUP ? "group" : "user",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) ent->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (test_bit(CACHE_VALID, &h->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) seq_printf(m, " %u", ent->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static struct ent *nametoid_lookup(struct cache_detail *, struct ent *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static struct ent *nametoid_update(struct cache_detail *, struct ent *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct ent *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static int nametoid_parse(struct cache_detail *, char *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) static const struct cache_detail nametoid_cache_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) .hash_size = ENT_HASHMAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) .name = "nfs4.nametoid",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) .cache_put = ent_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) .cache_upcall = nametoid_upcall,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) .cache_request = nametoid_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) .cache_parse = nametoid_parse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) .cache_show = nametoid_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) .warn_no_listener = warn_no_idmapd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) .match = nametoid_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) .init = ent_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) .update = ent_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) .alloc = ent_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) nametoid_parse(struct cache_detail *cd, char *buf, int buflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct ent ent, *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) char *buf1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) int len, error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (buf[buflen - 1] != '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return (-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) buf[buflen - 1]= '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) buf1 = kmalloc(PAGE_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (buf1 == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return (-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) memset(&ent, 0, sizeof(ent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /* Authentication name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) len = qword_get(&buf, buf1, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (len <= 0 || len >= IDMAP_NAMESZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) memcpy(ent.authname, buf1, sizeof(ent.authname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) /* Type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (qword_get(&buf, buf1, PAGE_SIZE) <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) ent.type = strcmp(buf1, "user") == 0 ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) IDMAP_TYPE_USER : IDMAP_TYPE_GROUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) /* Name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) len = qword_get(&buf, buf1, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (len <= 0 || len >= IDMAP_NAMESZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) memcpy(ent.name, buf1, sizeof(ent.name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /* expiry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) ent.h.expiry_time = get_expiry(&buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (ent.h.expiry_time == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /* ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) error = get_int(&buf, &ent.id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (error == -EINVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (error == -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) set_bit(CACHE_NEGATIVE, &ent.h.flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) res = nametoid_lookup(cd, &ent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (res == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) res = nametoid_update(cd, &ent, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (res == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) cache_put(&res->h, cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) kfree(buf1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return (error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static struct ent *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) nametoid_lookup(struct cache_detail *cd, struct ent *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) struct cache_head *ch = sunrpc_cache_lookup_rcu(cd, &item->h,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) nametoid_hash(item));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return container_of(ch, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static struct ent *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) nametoid_update(struct cache_detail *cd, struct ent *new, struct ent *old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) struct cache_head *ch = sunrpc_cache_update(cd, &new->h, &old->h,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) nametoid_hash(new));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return container_of(ch, struct ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * Exported API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) nfsd_idmap_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) nn->idtoname_cache = cache_create_net(&idtoname_cache_template, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (IS_ERR(nn->idtoname_cache))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) return PTR_ERR(nn->idtoname_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) rv = cache_register_net(nn->idtoname_cache, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) goto destroy_idtoname_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) nn->nametoid_cache = cache_create_net(&nametoid_cache_template, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (IS_ERR(nn->nametoid_cache)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) rv = PTR_ERR(nn->nametoid_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) goto unregister_idtoname_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) rv = cache_register_net(nn->nametoid_cache, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) goto destroy_nametoid_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) destroy_nametoid_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) cache_destroy_net(nn->nametoid_cache, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) unregister_idtoname_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) cache_unregister_net(nn->idtoname_cache, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) destroy_idtoname_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) cache_destroy_net(nn->idtoname_cache, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) nfsd_idmap_shutdown(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) cache_unregister_net(nn->idtoname_cache, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) cache_unregister_net(nn->nametoid_cache, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) cache_destroy_net(nn->idtoname_cache, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) cache_destroy_net(nn->nametoid_cache, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) idmap_lookup(struct svc_rqst *rqstp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct ent *(*lookup_fn)(struct cache_detail *, struct ent *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct ent *key, struct cache_detail *detail, struct ent **item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) *item = lookup_fn(detail, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (!*item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) ret = cache_check(detail, &(*item)->h, &rqstp->rq_chandle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) if (ret == -ETIMEDOUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) struct ent *prev_item = *item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) *item = lookup_fn(detail, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if (*item != prev_item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) cache_put(&(*item)->h, detail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) rqst_authname(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) struct auth_domain *clp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) clp = rqstp->rq_gssclient ? rqstp->rq_gssclient : rqstp->rq_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) return clp->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) idmap_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) u32 *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) struct ent *item, key = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) .type = type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) if (namelen + 1 > sizeof(key.name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return nfserr_badowner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) memcpy(key.name, name, namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) key.name[namelen] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) strlcpy(key.authname, rqst_authname(rqstp), sizeof(key.authname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) ret = idmap_lookup(rqstp, nametoid_lookup, &key, nn->nametoid_cache, &item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (ret == -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return nfserr_badowner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return nfserrno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) *id = item->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) cache_put(&item->h, nn->nametoid_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) static __be32 encode_ascii_id(struct xdr_stream *xdr, u32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) char buf[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) __be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) len = sprintf(buf, "%u", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) p = xdr_reserve_space(xdr, len + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return nfserr_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) p = xdr_encode_opaque(p, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static __be32 idmap_id_to_name(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) struct svc_rqst *rqstp, int type, u32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) struct ent *item, key = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) .id = id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) .type = type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) __be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) strlcpy(key.authname, rqst_authname(rqstp), sizeof(key.authname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) ret = idmap_lookup(rqstp, idtoname_lookup, &key, nn->idtoname_cache, &item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (ret == -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) return encode_ascii_id(xdr, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) return nfserrno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) ret = strlen(item->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) WARN_ON_ONCE(ret > IDMAP_NAMESZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) p = xdr_reserve_space(xdr, ret + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) return nfserr_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) p = xdr_encode_opaque(p, item->name, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) cache_put(&item->h, nn->idtoname_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) numeric_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen, u32 *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) char buf[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) if (namelen + 1 > sizeof(buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) /* too long to represent a 32-bit id: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) /* Just to make sure it's null-terminated: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) memcpy(buf, name, namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) buf[namelen] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) ret = kstrtouint(buf, 10, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) return ret == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) do_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen, u32 *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (nfs4_disable_idmapping && rqstp->rq_cred.cr_flavor < RPC_AUTH_GSS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (numeric_name_to_id(rqstp, type, name, namelen, id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) * otherwise, fall through and try idmapping, for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) * backwards compatibility with clients sending names:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) return idmap_name_to_id(rqstp, type, name, namelen, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) static __be32 encode_name_from_id(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) struct svc_rqst *rqstp, int type, u32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) if (nfs4_disable_idmapping && rqstp->rq_cred.cr_flavor < RPC_AUTH_GSS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) return encode_ascii_id(xdr, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) return idmap_id_to_name(xdr, rqstp, type, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) nfsd_map_name_to_uid(struct svc_rqst *rqstp, const char *name, size_t namelen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) kuid_t *uid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) __be32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) u32 id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) if (name == NULL || namelen == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) return nfserr_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) status = do_name_to_id(rqstp, IDMAP_TYPE_USER, name, namelen, &id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) *uid = make_kuid(nfsd_user_namespace(rqstp), id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) if (!uid_valid(*uid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) status = nfserr_badowner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) nfsd_map_name_to_gid(struct svc_rqst *rqstp, const char *name, size_t namelen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) kgid_t *gid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) __be32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) u32 id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if (name == NULL || namelen == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) return nfserr_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) status = do_name_to_id(rqstp, IDMAP_TYPE_GROUP, name, namelen, &id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) *gid = make_kgid(nfsd_user_namespace(rqstp), id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (!gid_valid(*gid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) status = nfserr_badowner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) __be32 nfsd4_encode_user(struct xdr_stream *xdr, struct svc_rqst *rqstp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) kuid_t uid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) u32 id = from_kuid_munged(nfsd_user_namespace(rqstp), uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) return encode_name_from_id(xdr, rqstp, IDMAP_TYPE_USER, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) __be32 nfsd4_encode_group(struct xdr_stream *xdr, struct svc_rqst *rqstp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) kgid_t gid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) u32 id = from_kgid_munged(nfsd_user_namespace(rqstp), gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) return encode_name_from_id(xdr, rqstp, IDMAP_TYPE_GROUP, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }