33
33
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34
34
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
35
*/
36
+ #include <linux/types.h>
37
+ #include <linux/string.h>
38
+ #include <linux/kernel.h>
39
+
40
+ static int nfs_map_string_to_numeric (const char * name , size_t namelen , __u32 * res )
41
+ {
42
+ unsigned long val ;
43
+ char buf [16 ];
44
+
45
+ if (memchr (name , '@' , namelen ) != NULL || namelen >= sizeof (buf ))
46
+ return 0 ;
47
+ memcpy (buf , name , namelen );
48
+ buf [namelen ] = '\0' ;
49
+ if (strict_strtoul (buf , 0 , & val ) != 0 )
50
+ return 0 ;
51
+ * res = val ;
52
+ return 1 ;
53
+ }
36
54
37
55
#ifdef CONFIG_NFS_USE_NEW_IDMAPPER
38
56
42
60
#include <linux/keyctl.h>
43
61
#include <linux/key-type.h>
44
62
#include <linux/rcupdate.h>
45
- #include <linux/kernel.h>
46
63
#include <linux/err.h>
47
64
48
65
#include <keys/user-type.h>
@@ -221,11 +238,15 @@ static int nfs_idmap_lookup_id(const char *name, size_t namelen,
221
238
222
239
int nfs_map_name_to_uid (struct nfs_client * clp , const char * name , size_t namelen , __u32 * uid )
223
240
{
241
+ if (nfs_map_string_to_numeric (name , namelen , uid ))
242
+ return 0 ;
224
243
return nfs_idmap_lookup_id (name , namelen , "uid" , uid );
225
244
}
226
245
227
246
int nfs_map_group_to_gid (struct nfs_client * clp , const char * name , size_t namelen , __u32 * gid )
228
247
{
248
+ if (nfs_map_string_to_numeric (name , namelen , gid ))
249
+ return 0 ;
229
250
return nfs_idmap_lookup_id (name , namelen , "gid" , gid );
230
251
}
231
252
@@ -243,7 +264,6 @@ int nfs_map_gid_to_group(struct nfs_client *clp, __u32 gid, char *buf, size_t bu
243
264
#include <linux/module.h>
244
265
#include <linux/mutex.h>
245
266
#include <linux/init.h>
246
- #include <linux/types.h>
247
267
#include <linux/slab.h>
248
268
#include <linux/socket.h>
249
269
#include <linux/in.h>
@@ -699,13 +719,17 @@ int nfs_map_name_to_uid(struct nfs_client *clp, const char *name, size_t namelen
699
719
{
700
720
struct idmap * idmap = clp -> cl_idmap ;
701
721
722
+ if (nfs_map_string_to_numeric (name , namelen , uid ))
723
+ return 0 ;
702
724
return nfs_idmap_id (idmap , & idmap -> idmap_user_hash , name , namelen , uid );
703
725
}
704
726
705
727
int nfs_map_group_to_gid (struct nfs_client * clp , const char * name , size_t namelen , __u32 * uid )
706
728
{
707
729
struct idmap * idmap = clp -> cl_idmap ;
708
730
731
+ if (nfs_map_string_to_numeric (name , namelen , uid ))
732
+ return 0 ;
709
733
return nfs_idmap_id (idmap , & idmap -> idmap_group_hash , name , namelen , uid );
710
734
}
711
735
0 commit comments