NFSv3 UID/GID mapping
Subsystems (3)
Dear NFS developers,
Here is the NFSv3 uid/gid mapping implementation (both kernel and nfs-utils parts). Userspace part uses idmap daemon from CITI NFSv4, so the NFSv4 patches are required.
Look at this, please. Any kind of feedback will be appreciated.
Signature · 2 lines
Best regards, Ed V. Bartosh
fs/nfsd/auth.c renamed from fs/nfsd.orig/auth.c +34 -1
@@ -4,11 +4,17 @@* Copyright (C) 1995, 1996 Olaf Kirch <[email protected]> */ +#include <linux/config.h> #include <linux/types.h> #include <linux/sched.h> #include <linux/sunrpc/svc.h> #include <linux/sunrpc/svcauth.h> #include <linux/nfsd/nfsd.h> +#ifdef CONFIG_NFSD3_IDMAP +#include <linux/nfsd_idmap.h> +#endif + +#define NFSDDBG_FACILITY NFSDDBG_AUTH#define CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
@@ -17,6 +23,33 @@struct svc_cred *cred = &rqstp->rq_cred;int i;int ret; + +#ifdef CONFIG_NFSD3_IDMAP +__u32 uidm =IDMAP_UID_NONE ; +__u32 gidm =IDMAP_UID_NONE ; + +if (exp->ex_flags &NFSEXP_IDMAPD ) { +struct group_info *gi; + ret =nfsd3_map_uid_to_uid (rqstp, cred->cr_uid, &uidm); +if (ret ==0 && uidm !=IDMAP_UID_NONE ) + cred->cr_uid = uidm; + + ret =nfsd3_map_gid_to_gid (rqstp, cred->cr_gid, &gidm); +if (ret ==0 && gidm !=IDMAP_UID_NONE ) + cred->cr_gid = gidm; + + gi =groups_alloc (cred->cr_group_info->ngroups); +if (gi) { +for (i =0 ; i < cred->cr_group_info->ngroups; i++) { + ret =nfsd3_map_gid_to_gid (rqstp,GROUP_AT (cred->cr_group_info, i), &gidm); +if (ret ==0 && gidm !=IDMAP_UID_NONE ) +GROUP_AT (gi, i) = gidm; + } +put_group_info (cred->cr_group_info); + cred->cr_group_info = gi; + } + } +#else if (exp->ex_flags &NFSEXP_ALLSQUASH ) { cred->cr_uid = exp->ex_anon_uid;
@@ -40,7 +73,7 @@put_group_info (cred->cr_group_info); cred->cr_group_info = gi; } - +#endif if (cred->cr_uid != (uid_t) -1 ) current->fsuid = cred->cr_uid;else
fs/nfsd/export.c renamed from fs/nfsd.orig/export.c +1 -0
@@ -1010,6 +1010,7 @@ { NFSEXP_ALLSQUASH, {"all_squash", ""}}, { NFSEXP_ASYNC, {"async", "sync"}}, { NFSEXP_GATHERED_WRITES, {"wdelay", "no_wdelay"}}, + { NFSEXP_IDMAPD, {"mapping=idmapd", ""}}, { NFSEXP_NOHIDE, {"nohide", ""}}, { NFSEXP_CROSSMOUNT, {"crossmnt", ""}}, { NFSEXP_NOSUBTREECHECK, {"no_subtree_check", ""}},
fs/nfsd/Makefile renamed from fs/nfsd.orig/Makefile +1 -0
@@ -7,5 +7,6 @@ nfsd-y := nfssvc.o nfsctl.o nfsproc.o nfsfh.o vfs.o \ export.o auth.o lockd.o nfscache.o nfsxdr.o stats.o nfsd-$(CONFIG_NFSD_V3) += nfs3proc.o nfs3xdr.o +nfsd-$(CONFIG_NFSD3_IDMAP) += nfs3idmap.o nfsd-$(CONFIG_NFSD_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4idmap.o nfsd-objs := $(nfsd-y)
fs/nfsd/nfsctl.c renamed from fs/nfsd.orig/nfsctl.c +6 -0
@@ -438,6 +436,9 @@nfsd_cache_init ();/* RPC reply cache */ nfsd_export_init ();/* Exports table */ nfsd_lockd_init ();/* lockd->nfsd callbacks */ +#ifdef CONFIG_NFSD3_IDMAP +nfsd3_idmap_init ();/* User/Group ID mapping */ +#endif /* CONFIG_NFSD3_IDMAP */ #ifdef CONFIG_NFSD_V4 nfsd_idmap_init ();/* Name to ID mapping */ #endif /* CONFIG_NFSD_V4 */
@@ -467,6 +468,9 @@remove_proc_entry ("fs/nfs" ,NULL );nfsd_stat_shutdown ();nfsd_lockd_shutdown (); +#ifdef CONFIG_NFSD3_IDMAP +nfsd3_idmap_shutdown (); +#endif /* CONFIG_NFSD3_IDMAP */ #ifdef CONFIG_NFSD_V4 nfsd_idmap_shutdown ();#endif /* CONFIG_NFSD_V4 */
include/linux/nfsd_idmap.h renamed from include/linux/nfsd_idmap.h.orig +12 -0
@@ -51,4 +51,16 @@int nfsd_map_uid_to_name (struct svc_rqst *,__u32 ,char *);int nfsd_map_gid_to_name (struct svc_rqst *,__u32 ,char *); +#ifdef CONFIG_NFSD3_IDMAP + +#define IDMAP_UID_NONE ((uid_t)-1) + +void nfsd3_idmap_init (void ); +void nfsd3_idmap_shutdown (void ); + +int nfsd3_map_uid_to_uid (struct svc_rqst *rqstp,__u32 id,__u32 *idm); + +int nfsd3_map_gid_to_gid (struct svc_rqst *rqstp,__u32 id,__u32 *idm); +#endif +#endif /* LINUX_NFSD_IDMAP_H */
include/linux/nfsd/export.h renamed from include/linux/nfsd/export.h~ +2 -1
@@ -32,7 +32,8 @@#define NFSEXP_ALLSQUASH 0x0008#define NFSEXP_ASYNC 0x0010#define NFSEXP_GATHERED_WRITES 0x0020 -/* 40 80 100 currently unused */ +#define NFSEXP_IDMAPD 0x0040 +/* 80 100 currently unused */ #define NFSEXP_NOHIDE 0x0200#define NFSEXP_NOSUBTREECHECK 0x0400#define NFSEXP_NOAUTHNLM 0x0800/* Don't authenticate NLM requests - just trust */
fs/Kconfig renamed from fs/Kconfig.orig +7 -0
@@ -1373,6 +1373,13 @@ If you would like to include the NFSv3 server as well as the NFSv2 server, say Y here. If unsure, say Y. +config NFSD3_IDMAP + bool "Provide NFS User/Group ID Mapping support (EXPERIMENTAL)" + depends on NFSD_V3 && EXPERIMENTAL + help + If you want NFSv3 server to map client's UID or/and GID to + the server's one, say Y here. If unsure, say N. + config NFSD_V4 bool "Provide NFSv4 server support (EXPERIMENTAL)" depends on NFSD_V3 && EXPERIMENTAL
fs/nfsd/nfs3idmap.c renamed from fs/nfsd.orig/nfs3idmap.c +444 -0
444 lines not on this page · raw message
utils/idmapd/idmapd.c renamed from utils/idmapd/idmapd.c.orig +73 -6
137 lines not on this page · raw message
utils/idmapd/nfs_idmap.h renamed from utils/idmapd/nfs_idmap.h.orig +4 -0
@@ -45,6 +45,7 @@#define IDMAP_CONV_IDTONAME 0#define IDMAP_CONV_NAMETOID 1 +#define IDMAP_CONV_IDTOID 2#define IDMAP_STATUS_INVALIDMSG 0x01#define IDMAP_STATUS_AGAIN 0x02
@@ -53,11 +54,14 @@#define IDMAP_MAXMSGSZ 256 +#define IDMAP_UID_NONE ((u_int32_t)-1) +struct idmap_msg {u_int8_t im_type;u_int8_t im_conv;char im_name[IDMAP_NAMESZ ];u_int32_t im_id; +u_int32_t im_idm;u_int8_t im_status; };
support/export/nfsctl.c renamed from support/export/nfsctl.c~ +6 -2
@@ -90,8 +90,12 @@if (stat (exp->m_export.m_path, &stb) <0 )return 0 ; -if (exp->m_export.e_maptype !=CLE_MAP_IDENT ) { -xlog (L_ERROR ,"%s: unsupported mapping; kernel supports only 'identity' (default)" , +if (exp->m_export.e_maptype !=CLE_MAP_IDENT +#ifdef UGIDMAP_SUPPORTED + && exp->m_export.e_maptype !=CLE_MAP_IDMAPD +#endif + ) { +xlog (L_ERROR ,"%s: unsupported mapping; kernel supports only 'identity' (default) and 'idmapd'" , exp->m_export.m_path); errno =EINVAL ;return 0 ;
configure.in renamed from configure.in.orig +14 -3
@@ -40,12 +40,12 @@ fi AC_SUBST(enable_nfsv3) AC_ARG_ENABLE(kprefix, - [ --enable-kprefix install progs as rpc.knfsd etc], + [ --enable-kprefix install progs as rpc.knfsd etc], test "$enableval" = "yes" && kprefix=k, kprefix=) AC_SUBST(kprefix) AC_ARG_ENABLE(secure-statd, - [ --enable-secure-statd Only lockd can use statd (security)], + [ --enable-secure-statd Only lockd can use statd (security)], test "$enableval" = "yes" && secure_statd=yes, secure_statd=no) if test "$secure_statd" = yes; then
@@ -53,7 +53,7 @@ fi AC_SUBST(secure_statd) AC_ARG_ENABLE(rquotad, - [ --enable-rquotad enable rquotad], + [ --enable-rquotad enable rquotad], enable_rquotad=$enableval, enable_rquotad=yes) if test "$enable_rquotad" = yes; then
@@ -62,6 +62,17 @@ RQUOTAD= fi AC_SUBST(RQUOTAD) +AC_ARG_ENABLE(ugidmapping, + [ --enable-uidmapping enable uid/gid mapping], + enable_ugidmapping=$enableval, + enable_ugidmapping=no) + if test "$enable_ugidmapping" = yes; then + AC_DEFINE(UGIDMAP_SUPPORTED) + else + enable_ugidmapping= + fi + AC_SUBST(enable_ugidmapping) + dnl AC_ARG_ENABLE(frob, enable frobnicator,, enable_frob=test) AC_CONFIG_HEADER(support/include/config.h)
rules.mk +1 -1
@@ -70,7 +70,7 @@ # Cleaning rules ################################################################## clean distclean:: - rm -f *.o *~ \#* a.out core + rm -f *.o *~ *.a \#* a.out core distclean:: rm -f LOG X Y Z x y z .depend
support/nfs/exports.c renamed from support/nfs/exports.c.orig +12 -4
@@ -197,6 +197,9 @@case CLE_MAP_IDENT :fprintf (fp,"identity," );break ; +case CLE_MAP_IDMAPD : +fprintf (fp,"idmapd," ); +break ;case CLE_MAP_UGIDD :fprintf (fp,"ugidd," );break ;
@@ -374,8 +377,11 @@ ep->e_flags &= ~NFSEXP_NOAUTHNLM ; else if (strcmp(opt, "insecure_locks") == 0) ep->e_flags |= NFSEXP_NOAUTHNLM; - else if (strncmp(opt, "mapping=", 8) == 0) + else if (strncmp(opt, "mapping=", 8) == 0) { ep->e_maptype = parsemaptype(opt+8); + if (ep->e_maptype == CLE_MAP_IDMAPD) + ep->e_flags |= NFSEXP_IDMAPD; + } else if (strcmp(opt, "map_identity") == 0) /* old style */ ep->e_maptype = CLE_MAP_IDENT; else if (strcmp(opt, "map_daemon") == 0) /* old style */
@@ -528,11 +534,13 @@static int parsemaptype (char *type) { -if (!strcmp (type,"identity" )) +if (!strncmp (type,"identity" ,8 ))return CLE_MAP_IDENT ; -if (!strcmp (type,"ugidd" )) +if (!strncmp (type,"idmapd" ,6 )) +return CLE_MAP_IDMAPD ; +if (!strncmp (type,"ugidd" ,5 ))return CLE_MAP_UGIDD ; -if (!strcmp (type,"file" )) +if (!strncmp (type,"file" ,4 ))return CLE_MAP_FILE ;syntaxerr ("invalid map type" );return CLE_MAP_IDENT ;/* default */
support/include/config.h.in renamed from support/include/config.h.in~ +4 -0
@@ -29,3 +29,7 @@ #undef HAVE_KRB5 /* XXX: you don't want to know: */ #undef USE_PRIVATE_KRB5_FUNCTIONS + +/* Define this if you want uid/gid mapping support compiled in + */ +#undef UGIDMAP_SUPPORTED
utils/exportfs/exportfs.c renamed from utils/exportfs/exportfs.c~ +2 -0
@@ -142,6 +142,8 @@if (!new_cache)xtab_mount_write (); +export_freeall (); +return export_errno; }
support/include/nfslib.h renamed from support/include/nfslib.h~ +1 -0
@@ -53,6 +53,7 @@CLE_MAP_IDENT =0 ,CLE_MAP_FILE ,CLE_MAP_UGIDD , + CLE_MAP_IDMAPD, };/*
support/include/nfs/export.h renamed from support/include/nfs/export.h~ +2 -1
@@ -17,7 +17,8 @@#define NFSEXP_ALLSQUASH 0x0008#define NFSEXP_ASYNC 0x0010#define NFSEXP_GATHERED_WRITES 0x0020 -/* 40, 80, 100 unused */ +#define NFSEXP_IDMAPD 0x0040 +/* 80, 100 unused */ #define NFSEXP_NOHIDE 0x0200#define NFSEXP_NOSUBTREECHECK 0x0400#define NFSEXP_NOAUTHNLM 0x0800
utils/idmapd/idmapd.conf renamed from utils/idmapd/idmapd.conf~ +4 -0
@@ -8,3 +8,7 @@ Nobody-User = nobody Nobody-Group = nobody + +[Mapping3] + +
Quoted 3 lines · Ed V. Bartosh
Here is the NFSv3 uid/gid mapping implementation (both kernel and nfs-utils parts). Userspace part uses idmap daemon from CITI NFSv4, so the NFSv4 patches are required.
Just out of curiosity:
* This does the server side only. Have you looked at the client side at all?
* What sort of applications are you considering for this?
Quoted 1 line
Look at this, please. Any kind of feedback will be appreciated.
Do you also need to do map the id's in nfs3xdr.c:xdr_encode_setattr() and xdr_decode_fattr()?
Is IDMAP_UID_NONE really needed, or could you just use an ENOENT return?
We need to figure out a way to do this without duplicating so much code from nfs4idmap.c.
Also note some of that code is wrong. (See the nfsd_idmap patches in
http://www.citi.umich.edu/projects/nfsv4/linux/kernel-patches/2.6.6-rc1-3/).
--Bruce Fields
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
Quoted 8 lines · J. Bruce Fields
Quoted 3 lines · Ed V. Bartosh
Here is the NFSv3 uid/gid mapping implementation (both kernel and nfs-utils parts). Userspace part uses idmap daemon from CITI NFSv4, so the NFSv4 patches are required.
Just out of curiosity:
* This does the server side only. Have you looked at the client side at all?
No. It's just a server-side mapping. I think we don't need to rely on client for that. There are many other possibilities to change uids on client side. Also client-based solution is less secure than server-side one and also it's the linux-only solution.
Quoted 2 lines
* What sort of applications are you considering for this?
I'm considering that this should be used in cases when there is no possibility to have equal uids on the NFS server and client. For example we have this situation when we use the same share as SMB and NFS share and we have to map uids of NFS users to uids of samba users (preferable windows boxes). In our situation this mapping is required because we need server XFS ACLs to work properly for any type of clients.
I think there are many other situations when it may be useful to use this kind of mapping.
Quoted 4 lines
Quoted 1 line
Look at this, please. Any kind of feedback will be appreciated.
Do you also need to do map the id's in nfs3xdr.c:xdr_encode_setattr() and
xdr_decode_fattr()?
Yes, I do. Thank you.
Quoted 2 lines
Is
IDMAP_UID_NONEreally needed, or could you just use an ENOENT return?
It's not important, i think, because '(uid_t) -1' is already used in auth.c, I've just named it. But, yes, it can be used partly. I mean that uids which can't be mapped will be passed from userspace in any case and we'll need to check it somewhere.
Quoted 2 lines
We need to figure out a way to do this without duplicating so much code from
nfs4idmap.c.
Yes, we need it, but it's not too much code. I think that there is sense to move only deferred request handling functions somewhere in separate file and use it from nfs4 and nfs3 idmap functions.
Quoted 3 lines
Also note some of that code is wrong. (See the
nfsd_idmappatches in
http://www.citi.umich.edu/projects/nfsv4/linux/kernel-patches/2.6.6-rc1-3/).
Yes, sure. When I worked on this patches there where only CITI patches for 2.6.5 available. I used them for my work.
Thank you for your feedback.
I'll change the code according to your suggestions.
BTW, Is any chance for this functionality to be in mainstream sometime ?
Signature · 12 lines
Best regards, Ed V. Bartosh ------------------------------------------------------- This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek For a limited time only, get FREE Ground shipping on all orders of $35 or more. Hurry up and shop folks, this offer expires April 30th! http://www.thinkgeek.com/freeshipping/?cpg=12297 _______________________________________________ NFS maillist - [email protected] https://lists.sourceforge.net/lists/listinfo/nfs
Quoted 3 lines · Ed V. Bartosh
It's just a server-side mapping. I think we don't need to rely on client for that. There are many other possibilities to change uids on client side.
The situation where I can imagine it being useful is when you had a client (maybe a laptop) that you wanted to be able to access shares on servers in different uid domains (possibly simultaneously).
Quoted 2 lines
Also client-based solution is less secure than server-side one and also it's the linux-only solution.
I don't see the argument there.
Quoted 2 lines
I think there are many other situations when it may be useful to use this kind of mapping.
Sure. I think someone on the linux kernel mailing list said they wanted to able to squash ranges of uid's.
Quoted 3 lines
Quoted 2 lines
Do you also need to do map the id's in nfs3xdr.c:xdr_encode_setattr() and
xdr_decode_fattr()?Yes, I do. Thank you.
That means you need a second mapping: in addition to mapping remove clients' id's to local server id's, you need the inverse mapping from local id's to the clients' id's (to get ls right).
Quoted 5 lines
Quoted 2 lines
We need to figure out a way to do this without duplicating so much code from
nfs4idmap.c.Yes, we need it, but it's not too much code. I think that there is sense to move only deferred request handling functions somewhere in separate file and use it from nfs4 and nfs3 idmap functions.
OK.
Quoted 1 line
BTW, Is any chance for this functionality to be in mainstream sometime ?
It seems useful, but it's not really up to me.
--Bruce Fields
-------------------------------------------------------
This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek For a limited time only, get FREE Ground shipping on all orders of $35 or more. Hurry up and shop folks, this offer expires April 30th!
http://www.thinkgeek.com/freeshipping/?cpg=12297
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs