Add vfs.nfsd.nfsd_enable_uidtostring, which works just like

vfs.nfsd.nfsd_enable_stringtouid, but in reverse - when set to 1,
it forces the NFSv4 server to return numeric UIDs and GIDs instead
of "user@domain" strings. This helps with clients that can't
translate returned identifiers, eg when rerooting.

The same can be achieved by just never running nfsuserd(8),
but the sysctl is useful to toggle the behaviour back and forth
without rebooting.

Reviewed by:	rmacklem (earlier version)
MFC after:	2 weeks
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D11326
This commit is contained in:
Edward Tomasz Napierala 2017-06-26 13:11:21 +00:00
parent 16454bee3a
commit 6a3450e178
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=320359
2 changed files with 7 additions and 3 deletions

View File

@ -68,6 +68,7 @@ gid_t nfsrv_defaultgid = GID_NOGROUP;
int nfsrv_lease = NFSRV_LEASE;
int ncl_mbuf_mlen = MLEN;
int nfsd_enable_stringtouid = 0;
int nfsd_enable_uidtostring = 0;
NFSNAMEIDMUTEX;
NFSSOCKMUTEX;
extern int nfsrv_lughashsize;
@ -2561,7 +2562,7 @@ nfsv4_uidtostr(uid_t uid, u_char **cpp, int *retlenp, NFSPROC_T *p)
cnt = 0;
tryagain:
if (nfsrv_dnsnamelen > 0) {
if (nfsrv_dnsnamelen > 0 && !nfsd_enable_uidtostring) {
/*
* Always map nfsrv_defaultuid to "nobody".
*/
@ -2671,7 +2672,7 @@ nfsrv_getgrpscred(struct ucred *oldcred)
cnt = 0;
uid = oldcred->cr_uid;
tryagain:
if (nfsrv_dnsnamelen > 0) {
if (nfsrv_dnsnamelen > 0 && !nfsd_enable_uidtostring) {
hp = NFSUSERHASH(uid);
mtx_lock(&hp->mtx);
TAILQ_FOREACH(usrp, &hp->lughead, lug_numhash) {
@ -2823,7 +2824,7 @@ nfsv4_gidtostr(gid_t gid, u_char **cpp, int *retlenp, NFSPROC_T *p)
cnt = 0;
tryagain:
if (nfsrv_dnsnamelen > 0) {
if (nfsrv_dnsnamelen > 0 && !nfsd_enable_uidtostring) {
/*
* Always map nfsrv_defaultgid to "nogroup".
*/

View File

@ -87,6 +87,7 @@ static int nfs_commit_miss;
extern int nfsrv_issuedelegs;
extern int nfsrv_dolocallocks;
extern int nfsd_enable_stringtouid;
extern int nfsd_enable_uidtostring;
SYSCTL_NODE(_vfs, OID_AUTO, nfsd, CTLFLAG_RW, 0, "NFS server");
SYSCTL_INT(_vfs_nfsd, OID_AUTO, mirrormnt, CTLFLAG_RW,
@ -103,6 +104,8 @@ SYSCTL_INT(_vfs_nfsd, OID_AUTO, debuglevel, CTLFLAG_RW, &nfsd_debuglevel,
0, "Debug level for NFS server");
SYSCTL_INT(_vfs_nfsd, OID_AUTO, enable_stringtouid, CTLFLAG_RW,
&nfsd_enable_stringtouid, 0, "Enable nfsd to accept numeric owner_names");
SYSCTL_INT(_vfs_nfsd, OID_AUTO, enable_uidtostring, CTLFLAG_RW,
&nfsd_enable_uidtostring, 0, "Make nfsd always send numeric owner_names");
#define MAX_REORDERED_RPC 16
#define NUM_HEURISTIC 1031