1 /*
2  * include/linux/nfs_idmap.h
3  *
4  *  UID and GID to name mapping for clients.
5  *
6  *  Copyright (c) 2002 The Regents of the University of Michigan.
7  *  All rights reserved.
8  *
9  *  Marius Aamodt Eriksen <marius@umich.edu>
10  *
11  *  Redistribution and use in source and binary forms, with or without
12  *  modification, are permitted provided that the following conditions
13  *  are met:
14  *
15  *  1. Redistributions of source code must retain the above copyright
16  *     notice, this list of conditions and the following disclaimer.
17  *  2. Redistributions in binary form must reproduce the above copyright
18  *     notice, this list of conditions and the following disclaimer in the
19  *     documentation and/or other materials provided with the distribution.
20  *  3. Neither the name of the University nor the names of its
21  *     contributors may be used to endorse or promote products derived
22  *     from this software without specific prior written permission.
23  *
24  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
25  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31  *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 #ifndef NFS_IDMAP_H
38 #define NFS_IDMAP_H
39 
40 #include <linux/types.h>
41 
42 /* XXX from bits/utmp.h  */
43 #define IDMAP_NAMESZ  128
44 
45 #define IDMAP_TYPE_USER  0
46 #define IDMAP_TYPE_GROUP 1
47 
48 #define IDMAP_CONV_IDTONAME 0
49 #define IDMAP_CONV_NAMETOID 1
50 
51 #define IDMAP_STATUS_INVALIDMSG 0x01
52 #define IDMAP_STATUS_AGAIN      0x02
53 #define IDMAP_STATUS_LOOKUPFAIL 0x04
54 #define IDMAP_STATUS_SUCCESS    0x08
55 
56 struct idmap_msg {
57 	__u8  im_type;
58 	__u8  im_conv;
59 	char  im_name[IDMAP_NAMESZ];
60 	__u32 im_id;
61 	__u8  im_status;
62 };
63 
64 #ifdef __KERNEL__
65 
66 /* Forward declaration to make this header independent of others */
67 struct nfs_client;
68 struct nfs_server;
69 struct nfs_fattr;
70 struct nfs4_string;
71 
72 #ifdef CONFIG_NFS_V4
73 int nfs_idmap_init(void);
74 void nfs_idmap_quit(void);
75 #else
nfs_idmap_init(void)76 static inline int nfs_idmap_init(void)
77 {
78 	return 0;
79 }
80 
nfs_idmap_quit(void)81 static inline void nfs_idmap_quit(void)
82 {}
83 #endif
84 
85 int nfs_idmap_new(struct nfs_client *);
86 void nfs_idmap_delete(struct nfs_client *);
87 
88 void nfs_fattr_init_names(struct nfs_fattr *fattr,
89 		struct nfs4_string *owner_name,
90 		struct nfs4_string *group_name);
91 void nfs_fattr_free_names(struct nfs_fattr *);
92 void nfs_fattr_map_and_free_names(struct nfs_server *, struct nfs_fattr *);
93 
94 int nfs_map_name_to_uid(const struct nfs_server *, const char *, size_t, __u32 *);
95 int nfs_map_group_to_gid(const struct nfs_server *, const char *, size_t, __u32 *);
96 int nfs_map_uid_to_name(const struct nfs_server *, __u32, char *, size_t);
97 int nfs_map_gid_to_group(const struct nfs_server *, __u32, char *, size_t);
98 
99 extern unsigned int nfs_idmap_cache_timeout;
100 #endif /* __KERNEL__ */
101 
102 #endif /* NFS_IDMAP_H */
103