xref: /illumos-gate/usr/src/uts/common/nfs/nfsid_map.h (revision 4eaa471005973e11a6110b69fe990530b3b95a38)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _NFSID_MAP_H
28 #define	_NFSID_MAP_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifndef _KERNEL
33 #include <stddef.h>
34 #endif
35 #include <sys/sysmacros.h>
36 #include <sys/types.h>
37 
38 /*
39  * NFSv4 id mapping daemon
40  *
41  * This daemon is used by the kernel to map strings in the form
42  * "user@dns_domain" from an integer form or vice-versa.  The daemon
43  * uses the system configured name services for the mapping.
44  *
45  * The status results determines if a mapping was successful.
46  *
47  * The mapping is cached in the kernel, so that expensive upcalls are
48  * reduced to a minimum.
49  */
50 
51 #ifdef	__cplusplus
52 extern "C" {
53 #endif
54 
55 /*
56  * mapid commands
57  */
58 #define	NFSMAPID_STR_UID	1
59 #define	NFSMAPID_UID_STR	2
60 #define	NFSMAPID_STR_GID	3
61 #define	NFSMAPID_GID_STR	4
62 
63 /*
64  * We are passing in arguments in a variable length struct
65  * similar to a dirent_t. We break apart a utf8string into
66  * its components and allocate a struct long enough to hold
67  * the string and a NUL terminator.  The caller must ensure the
68  * terminator is set.
69  */
70 struct mapid_arg {
71 	uint_t	cmd;
72 	union {
73 		uid_t		uid;
74 		gid_t		gid;
75 		int		len;
76 	} u_arg;
77 	char str[1];
78 };
79 typedef struct mapid_arg mapid_arg_t;
80 
81 /*
82  * The actual required size of the args, rounded up to a 64 bit boundary
83  */
84 #define	MAPID_ARG_LEN(str_length)	\
85 	((offsetof(mapid_arg_t, str[0]) + 1 + (str_length) + 7) & ~ 7)
86 
87 /*
88  * Return status codes
89  */
90 #define	NFSMAPID_OK		0
91 
92 /*
93  * numeric string is mapped to its literal number
94  */
95 #define	NFSMAPID_NUMSTR		1
96 
97 /*
98  * Value cannot be mapped, badly formed string
99  */
100 #define	NFSMAPID_UNMAPPABLE	2
101 
102 /*
103  * Caller provided invalid arguments
104  */
105 #define	NFSMAPID_INVALID	3
106 
107 /*
108  * Internal error in daemon e.g. out of memory, can't return result
109  */
110 #define	NFSMAPID_INTERNAL	4
111 
112 /*
113  * Incorrect domain used
114  */
115 #define	NFSMAPID_BADDOMAIN	5
116 
117 /*
118  * Out of range uid/gid
119  */
120 #define	NFSMAPID_BADID		6
121 
122 /*
123  * User or group cannot be found in nameservice
124  */
125 #define	NFSMAPID_NOTFOUND	7
126 
127 /*
128  * Similar to the arguments, the result is variable length.
129  * The returner must ensure the string terminator is set.
130  */
131 struct mapid_res {
132 	uint_t	status;
133 	union {
134 		uid_t		uid;
135 		gid_t		gid;
136 		int		len;
137 	} u_res;
138 	char str[1];
139 };
140 typedef struct mapid_res mapid_res_t;
141 
142 /*
143  * The actual required size of the result, rounded up to a 64 bit boundary
144  */
145 #define	MAPID_RES_LEN(str_length)	\
146 	((offsetof(mapid_res_t, str[0]) + 1 + (str_length) + 7) & ~ 7)
147 
148 #ifdef	__cplusplus
149 }
150 #endif
151 
152 #endif /* _NFSID_MAP_H */
153