aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorBryan Schumaker <bjschuma@netapp.com>2012-01-26 16:54:23 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2012-02-06 18:48:01 -0500
commite6499c6f4b5f56a16f8b8ef60529c1da28b13aea (patch)
tree9212b8d42b0cb24e68c46509e3d924f2b9d30f41 /fs
parent2d3fe01c36a9b881fae89c5bdf4085a4d7d53ae1 (diff)
NFS: Fall back on old idmapper if request_key() fails
This patch removes the CONFIG_NFS_USE_NEW_IDMAPPER compile option. First, the idmapper will attempt to map the id using /sbin/request-key and nfsidmap. If this fails (if /etc/request-key.conf is not configured properly) then the idmapper will call the legacy code to perform the mapping. I left a comment stating where the legacy code begins to make it easier for somebody to remove in the future. Signed-off-by: Bryan Schumaker <bjschuma@netapp.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/nfs/Kconfig11
-rw-r--r--fs/nfs/idmap.c91
-rw-r--r--fs/nfs/sysctl.c2
3 files changed, 37 insertions, 67 deletions
diff --git a/fs/nfs/Kconfig b/fs/nfs/Kconfig
index dbcd82126aed..021d2cf6938a 100644
--- a/fs/nfs/Kconfig
+++ b/fs/nfs/Kconfig
@@ -132,14 +132,3 @@ config NFS_USE_KERNEL_DNS
132 select DNS_RESOLVER 132 select DNS_RESOLVER
133 select KEYS 133 select KEYS
134 default y 134 default y
135
136config NFS_USE_NEW_IDMAPPER
137 bool "Use the new idmapper upcall routine"
138 depends on NFS_V4 && KEYS
139 help
140 Say Y here if you want NFS to use the new idmapper upcall functions.
141 You will need /sbin/request-key (usually provided by the keyutils
142 package). For details, read
143 <file:Documentation/filesystems/nfs/idmapper.txt>.
144
145 If you are unsure, say N.
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c
index 62264e0b1ddb..e0ecd5a7e19a 100644
--- a/fs/nfs/idmap.c
+++ b/fs/nfs/idmap.c
@@ -142,8 +142,6 @@ static int nfs_map_numeric_to_string(__u32 id, char *buf, size_t buflen)
142 return snprintf(buf, buflen, "%u", id); 142 return snprintf(buf, buflen, "%u", id);
143} 143}
144 144
145#ifdef CONFIG_NFS_USE_NEW_IDMAPPER
146
147#include <linux/cred.h> 145#include <linux/cred.h>
148#include <linux/sunrpc/sched.h> 146#include <linux/sunrpc/sched.h>
149#include <linux/nfs4.h> 147#include <linux/nfs4.h>
@@ -169,7 +167,7 @@ struct key_type key_type_id_resolver = {
169 .read = user_read, 167 .read = user_read,
170}; 168};
171 169
172int nfs_idmap_init(void) 170static int nfs_idmap_init_keyring(void)
173{ 171{
174 struct cred *cred; 172 struct cred *cred;
175 struct key *keyring; 173 struct key *keyring;
@@ -211,7 +209,7 @@ failed_put_cred:
211 return ret; 209 return ret;
212} 210}
213 211
214void nfs_idmap_quit(void) 212static void nfs_idmap_quit_keyring(void)
215{ 213{
216 key_revoke(id_resolver_cache->thread_keyring); 214 key_revoke(id_resolver_cache->thread_keyring);
217 unregister_key_type(&key_type_id_resolver); 215 unregister_key_type(&key_type_id_resolver);
@@ -328,43 +326,7 @@ static int nfs_idmap_lookup_id(const char *name, size_t namelen,
328 return ret; 326 return ret;
329} 327}
330 328
331int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid) 329/* idmap classic begins here */
332{
333 if (nfs_map_string_to_numeric(name, namelen, uid))
334 return 0;
335 return nfs_idmap_lookup_id(name, namelen, "uid", uid);
336}
337
338int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *gid)
339{
340 if (nfs_map_string_to_numeric(name, namelen, gid))
341 return 0;
342 return nfs_idmap_lookup_id(name, namelen, "gid", gid);
343}
344
345int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen)
346{
347 int ret = -EINVAL;
348
349 if (!(server->caps & NFS_CAP_UIDGID_NOMAP))
350 ret = nfs_idmap_lookup_name(uid, "user", buf, buflen);
351 if (ret < 0)
352 ret = nfs_map_numeric_to_string(uid, buf, buflen);
353 return ret;
354}
355int nfs_map_gid_to_group(const struct nfs_server *server, __u32 gid, char *buf, size_t buflen)
356{
357 int ret = -EINVAL;
358
359 if (!(server->caps & NFS_CAP_UIDGID_NOMAP))
360 ret = nfs_idmap_lookup_name(gid, "group", buf, buflen);
361 if (ret < 0)
362 ret = nfs_map_numeric_to_string(gid, buf, buflen);
363 return ret;
364}
365
366#else /* CONFIG_NFS_USE_NEW_IDMAPPER not defined */
367
368#include <linux/module.h> 330#include <linux/module.h>
369#include <linux/mutex.h> 331#include <linux/mutex.h>
370#include <linux/init.h> 332#include <linux/init.h>
@@ -600,12 +562,21 @@ static struct notifier_block nfs_idmap_block = {
600 562
601int nfs_idmap_init(void) 563int nfs_idmap_init(void)
602{ 564{
603 return rpc_pipefs_notifier_register(&nfs_idmap_block); 565 int ret;
566 ret = nfs_idmap_init_keyring();
567 if (ret != 0)
568 goto out;
569 ret = rpc_pipefs_notifier_register(&nfs_idmap_block);
570 if (ret != 0)
571 nfs_idmap_quit_keyring();
572out:
573 return ret;
604} 574}
605 575
606void nfs_idmap_quit(void) 576void nfs_idmap_quit(void)
607{ 577{
608 rpc_pipefs_notifier_unregister(&nfs_idmap_block); 578 rpc_pipefs_notifier_unregister(&nfs_idmap_block);
579 nfs_idmap_quit_keyring();
609} 580}
610 581
611/* 582/*
@@ -930,19 +901,27 @@ static unsigned int fnvhash32(const void *buf, size_t buflen)
930int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid) 901int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid)
931{ 902{
932 struct idmap *idmap = server->nfs_client->cl_idmap; 903 struct idmap *idmap = server->nfs_client->cl_idmap;
904 int ret = -EINVAL;
933 905
934 if (nfs_map_string_to_numeric(name, namelen, uid)) 906 if (nfs_map_string_to_numeric(name, namelen, uid))
935 return 0; 907 return 0;
936 return nfs_idmap_id(idmap, &idmap->idmap_user_hash, name, namelen, uid); 908 ret = nfs_idmap_lookup_id(name, namelen, "uid", uid);
909 if (ret < 0)
910 ret = nfs_idmap_id(idmap, &idmap->idmap_user_hash, name, namelen, uid);
911 return ret;
937} 912}
938 913
939int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid) 914int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *gid)
940{ 915{
941 struct idmap *idmap = server->nfs_client->cl_idmap; 916 struct idmap *idmap = server->nfs_client->cl_idmap;
917 int ret = -EINVAL;
942 918
943 if (nfs_map_string_to_numeric(name, namelen, uid)) 919 if (nfs_map_string_to_numeric(name, namelen, gid))
944 return 0; 920 return 0;
945 return nfs_idmap_id(idmap, &idmap->idmap_group_hash, name, namelen, uid); 921 ret = nfs_idmap_lookup_id(name, namelen, "gid", gid);
922 if (ret < 0)
923 ret = nfs_idmap_id(idmap, &idmap->idmap_group_hash, name, namelen, gid);
924 return ret;
946} 925}
947 926
948int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen) 927int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen)
@@ -950,22 +929,26 @@ int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, s
950 struct idmap *idmap = server->nfs_client->cl_idmap; 929 struct idmap *idmap = server->nfs_client->cl_idmap;
951 int ret = -EINVAL; 930 int ret = -EINVAL;
952 931
953 if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) 932 if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) {
954 ret = nfs_idmap_name(idmap, &idmap->idmap_user_hash, uid, buf); 933 ret = nfs_idmap_lookup_name(uid, "user", buf, buflen);
934 if (ret < 0)
935 ret = nfs_idmap_name(idmap, &idmap->idmap_user_hash, uid, buf);
936 }
955 if (ret < 0) 937 if (ret < 0)
956 ret = nfs_map_numeric_to_string(uid, buf, buflen); 938 ret = nfs_map_numeric_to_string(uid, buf, buflen);
957 return ret; 939 return ret;
958} 940}
959int nfs_map_gid_to_group(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen) 941int nfs_map_gid_to_group(const struct nfs_server *server, __u32 gid, char *buf, size_t buflen)
960{ 942{
961 struct idmap *idmap = server->nfs_client->cl_idmap; 943 struct idmap *idmap = server->nfs_client->cl_idmap;
962 int ret = -EINVAL; 944 int ret = -EINVAL;
963 945
964 if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) 946 if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) {
965 ret = nfs_idmap_name(idmap, &idmap->idmap_group_hash, uid, buf); 947 ret = nfs_idmap_lookup_name(gid, "group", buf, buflen);
948 if (ret < 0)
949 ret = nfs_idmap_name(idmap, &idmap->idmap_group_hash, gid, buf);
950 }
966 if (ret < 0) 951 if (ret < 0)
967 ret = nfs_map_numeric_to_string(uid, buf, buflen); 952 ret = nfs_map_numeric_to_string(gid, buf, buflen);
968 return ret; 953 return ret;
969} 954}
970
971#endif /* CONFIG_NFS_USE_NEW_IDMAPPER */
diff --git a/fs/nfs/sysctl.c b/fs/nfs/sysctl.c
index 978aaeb8a093..ad4d2e787b20 100644
--- a/fs/nfs/sysctl.c
+++ b/fs/nfs/sysctl.c
@@ -32,7 +32,6 @@ static ctl_table nfs_cb_sysctls[] = {
32 .extra1 = (int *)&nfs_set_port_min, 32 .extra1 = (int *)&nfs_set_port_min,
33 .extra2 = (int *)&nfs_set_port_max, 33 .extra2 = (int *)&nfs_set_port_max,
34 }, 34 },
35#ifndef CONFIG_NFS_USE_NEW_IDMAPPER
36 { 35 {
37 .procname = "idmap_cache_timeout", 36 .procname = "idmap_cache_timeout",
38 .data = &nfs_idmap_cache_timeout, 37 .data = &nfs_idmap_cache_timeout,
@@ -40,7 +39,6 @@ static ctl_table nfs_cb_sysctls[] = {
40 .mode = 0644, 39 .mode = 0644,
41 .proc_handler = proc_dointvec_jiffies, 40 .proc_handler = proc_dointvec_jiffies,
42 }, 41 },
43#endif /* CONFIG_NFS_USE_NEW_IDMAPPER */
44#endif 42#endif
45 { 43 {
46 .procname = "nfs_mountpoint_timeout", 44 .procname = "nfs_mountpoint_timeout",