xref: /freebsd/include/rpc/auth.h (revision 8aac90f18aef7c9eea906c3ff9a001ca7b94f375)
1 /*	$NetBSD: auth.h,v 1.15 2000/06/02 22:57:55 fvdl Exp $	*/
2 
3 /*-
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  * Copyright (c) 2009, Sun Microsystems, Inc.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * - Redistributions of source code must retain the above copyright notice,
12  *   this list of conditions and the following disclaimer.
13  * - Redistributions in binary form must reproduce the above copyright notice,
14  *   this list of conditions and the following disclaimer in the documentation
15  *   and/or other materials provided with the distribution.
16  * - Neither the name of Sun Microsystems, Inc. nor the names of its
17  *   contributors may be used to endorse or promote products derived
18  *   from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*
34  * auth.h, Authentication interface.
35  *
36  * Copyright (C) 1984, Sun Microsystems, Inc.
37  *
38  * The data structures are completely opaque to the client.  The client
39  * is required to pass an AUTH * to routines that create rpc
40  * "sessions".
41  */
42 
43 #ifndef _RPC_AUTH_H
44 #define _RPC_AUTH_H
45 #include <rpc/xdr.h>
46 #include <rpc/clnt_stat.h>
47 #include <sys/cdefs.h>
48 #include <sys/socket.h>
49 
50 #define MAX_AUTH_BYTES	400
51 #define MAXNETNAMELEN	255	/* maximum length of network user's name */
52 
53 /*
54  *  Client side authentication/security data
55  */
56 
57 typedef struct sec_data {
58 	u_int	secmod;		/* security mode number e.g. in nfssec.conf */
59 	u_int	rpcflavor;	/* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
60 	int	flags;		/* AUTH_F_xxx flags */
61 	caddr_t data;		/* opaque data per flavor */
62 } sec_data_t;
63 
64 #ifdef _SYSCALL32_IMPL
65 struct sec_data32 {
66 	uint32_t secmod;	/* security mode number e.g. in nfssec.conf */
67 	uint32_t rpcflavor;	/* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
68 	int32_t flags;		/* AUTH_F_xxx flags */
69 	caddr32_t data;		/* opaque data per flavor */
70 };
71 #endif /* _SYSCALL32_IMPL */
72 
73 /*
74  * AUTH_DES flavor specific data from sec_data opaque data field.
75  * AUTH_KERB has the same structure.
76  */
77 typedef struct des_clnt_data {
78 	struct netbuf	syncaddr;	/* time sync addr */
79 	struct knetconfig *knconf;	/* knetconfig info that associated */
80 					/* with the syncaddr. */
81 	char		*netname;	/* server's netname */
82 	int		netnamelen;	/* server's netname len */
83 } dh_k4_clntdata_t;
84 
85 #ifdef _SYSCALL32_IMPL
86 struct des_clnt_data32 {
87 	struct netbuf32 syncaddr;	/* time sync addr */
88 	caddr32_t knconf;		/* knetconfig info that associated */
89 					/* with the syncaddr. */
90 	caddr32_t netname;		/* server's netname */
91 	int32_t netnamelen;		/* server's netname len */
92 };
93 #endif /* _SYSCALL32_IMPL */
94 
95 #ifdef KERBEROS
96 /*
97  * flavor specific data to hold the data for AUTH_DES/AUTH_KERB(v4)
98  * in sec_data->data opaque field.
99  */
100 typedef struct krb4_svc_data {
101 	int		window;		/* window option value */
102 } krb4_svcdata_t;
103 
104 typedef struct krb4_svc_data	des_svcdata_t;
105 #endif /* KERBEROS */
106 
107 /*
108  * authentication/security specific flags
109  */
110 #define AUTH_F_RPCTIMESYNC	0x001	/* use RPC to do time sync */
111 #define AUTH_F_TRYNONE		0x002	/* allow fall back to AUTH_NONE */
112 
113 
114 /*
115  * Status returned from authentication check
116  */
117 enum auth_stat {
118 	AUTH_OK=0,
119 	/*
120 	 * failed at remote end
121 	 */
122 	AUTH_BADCRED=1,			/* bogus credentials (seal broken) */
123 	AUTH_REJECTEDCRED=2,		/* client should begin new session */
124 	AUTH_BADVERF=3,			/* bogus verifier (seal broken) */
125 	AUTH_REJECTEDVERF=4,		/* verifier expired or was replayed */
126 	AUTH_TOOWEAK=5,			/* rejected due to security reasons */
127 	/*
128 	 * failed locally
129 	*/
130 	AUTH_INVALIDRESP=6,		/* bogus response verifier */
131 	AUTH_FAILED=7,			/* some unknown reason */
132 #ifdef KERBEROS
133 	/*
134 	 * kerberos errors
135 	 */
136 	,
137 	AUTH_KERB_GENERIC = 8,		/* kerberos generic error */
138 	AUTH_TIMEEXPIRE = 9,		/* time of credential expired */
139 	AUTH_TKT_FILE = 10,		/* something wrong with ticket file */
140 	AUTH_DECODE = 11,			/* can't decode authenticator */
141 	AUTH_NET_ADDR = 12,		/* wrong net address in ticket */
142 #endif /* KERBEROS */
143 	/*
144 	 * RPCSEC_GSS errors
145 	 */
146 	RPCSEC_GSS_CREDPROBLEM = 13,
147 	RPCSEC_GSS_CTXPROBLEM = 14,
148 	RPCSEC_GSS_NODISPATCH = 0x8000000
149 };
150 
151 union des_block {
152 	struct {
153 		uint32_t high;
154 		uint32_t low;
155 	} key;
156 	char c[8];
157 };
158 typedef union des_block des_block;
159 __BEGIN_DECLS
160 extern bool_t xdr_des_block(XDR *, des_block *);
161 __END_DECLS
162 
163 /*
164  * Authentication info.  Opaque to client.
165  */
166 struct opaque_auth {
167 	enum_t	oa_flavor;		/* flavor of auth */
168 	caddr_t	oa_base;		/* address of more auth stuff */
169 	u_int	oa_length;		/* not to exceed MAX_AUTH_BYTES */
170 };
171 
172 
173 /*
174  * Auth handle, interface to client side authenticators.
175  */
176 typedef struct __auth {
177 	struct	opaque_auth	ah_cred;
178 	struct	opaque_auth	ah_verf;
179 	union	des_block	ah_key;
180 	struct auth_ops {
181 		void	(*ah_nextverf) (struct __auth *);
182 		/* nextverf & serialize */
183 		int	(*ah_marshal) (struct __auth *, XDR *);
184 		/* validate verifier */
185 		int	(*ah_validate) (struct __auth *,
186 			    struct opaque_auth *);
187 		/* refresh credentials */
188 		int	(*ah_refresh) (struct __auth *, void *);
189 		/* destroy this structure */
190 		void	(*ah_destroy) (struct __auth *);
191 	} *ah_ops;
192 	void *ah_private;
193 } AUTH;
194 
195 
196 /*
197  * Authentication ops.
198  * The ops and the auth handle provide the interface to the authenticators.
199  *
200  * AUTH	*auth;
201  * XDR	*xdrs;
202  * struct opaque_auth verf;
203  */
204 #define AUTH_NEXTVERF(auth)		\
205 		((*((auth)->ah_ops->ah_nextverf))(auth))
206 #define auth_nextverf(auth)		\
207 		((*((auth)->ah_ops->ah_nextverf))(auth))
208 
209 #define AUTH_MARSHALL(auth, xdrs)	\
210 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
211 #define auth_marshall(auth, xdrs)	\
212 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
213 
214 #define AUTH_VALIDATE(auth, verfp)	\
215 		((*((auth)->ah_ops->ah_validate))((auth), verfp))
216 #define auth_validate(auth, verfp)	\
217 		((*((auth)->ah_ops->ah_validate))((auth), verfp))
218 
219 #define AUTH_REFRESH(auth, msg)		\
220 		((*((auth)->ah_ops->ah_refresh))(auth, msg))
221 #define auth_refresh(auth, msg)		\
222 		((*((auth)->ah_ops->ah_refresh))(auth, msg))
223 
224 #define AUTH_DESTROY(auth)		\
225 		((*((auth)->ah_ops->ah_destroy))(auth))
226 #define auth_destroy(auth)		\
227 		((*((auth)->ah_ops->ah_destroy))(auth))
228 
229 
230 __BEGIN_DECLS
231 extern struct opaque_auth _null_auth;
232 __END_DECLS
233 
234 /*
235  * These are the various implementations of client side authenticators.
236  */
237 
238 /*
239  * System style authentication
240  * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
241  *	char *machname;
242  *	u_int uid;
243  *	u_int gid;
244  *	int len;
245  *	u_int *aup_gids;
246  */
247 __BEGIN_DECLS
248 extern AUTH *authunix_create(char *, u_int, u_int, int, u_int *);
249 extern AUTH *authunix_create_default(void);	/* takes no parameters */
250 extern AUTH *authnone_create(void);		/* takes no parameters */
251 __END_DECLS
252 /*
253  * DES style authentication
254  * AUTH *authsecdes_create(servername, window, timehost, ckey)
255  * 	char *servername;		- network name of server
256  *	u_int window;			- time to live
257  * 	const char *timehost;			- optional hostname to sync with
258  * 	des_block *ckey;		- optional conversation key to use
259  */
260 __BEGIN_DECLS
261 extern AUTH *authdes_create (char *, u_int, struct sockaddr *, des_block *);
262 extern AUTH *authdes_seccreate (const char *, const u_int, const  char *,
263     const  des_block *);
264 __END_DECLS
265 
266 __BEGIN_DECLS
267 extern bool_t xdr_opaque_auth		(XDR *, struct opaque_auth *);
268 __END_DECLS
269 
270 #define authsys_create(c,i1,i2,i3,ip) authunix_create((c),(i1),(i2),(i3),(ip))
271 #define authsys_create_default() authunix_create_default()
272 
273 /*
274  * Netname manipulation routines.
275  */
276 __BEGIN_DECLS
277 extern int getnetname(char [MAXNETNAMELEN + 1]);
278 extern int host2netname(char [MAXNETNAMELEN + 1], const char *, const char *);
279 extern int user2netname(char [MAXNETNAMELEN + 1], const uid_t, const char *);
280 extern int netname2user(char [MAXNETNAMELEN + 1], uid_t *, gid_t *, int *,
281     gid_t *);
282 extern int netname2host(char [MAXNETNAMELEN + 1], char *, const int);
283 extern void passwd2des ( char *, char * );
284 __END_DECLS
285 
286 /*
287  *
288  * These routines interface to the keyserv daemon
289  *
290  */
291 __BEGIN_DECLS
292 extern int key_decryptsession(const char *, des_block *);
293 extern int key_encryptsession(const char *, des_block *);
294 extern int key_gendes(des_block *);
295 extern int key_setsecret(const char *);
296 extern int key_secretkey_is_set(void);
297 __END_DECLS
298 
299 /*
300  * Publickey routines.
301  */
302 __BEGIN_DECLS
303 extern int getpublickey (const char *, char *);
304 extern int getpublicandprivatekey (const char *, char *);
305 extern int getsecretkey (char *, char *, char *);
306 __END_DECLS
307 
308 #ifdef KERBEROS
309 /*
310  * Kerberos style authentication
311  * AUTH *authkerb_seccreate(service, srv_inst, realm, window, timehost, status)
312  *	const char *service;			- service name
313  *	const char *srv_inst;			- server instance
314  *	const char *realm;			- server realm
315  *	const u_int window;			- time to live
316  *	const char *timehost;			- optional hostname to sync with
317  *	int *status;				- kerberos status returned
318  */
319 __BEGIN_DECLS
320 extern AUTH	*authkerb_seccreate(const char *, const char *, const  char *,
321 		    const u_int, const char *, int *);
322 __END_DECLS
323 
324 /*
325  * Map a kerberos credential into a unix cred.
326  *
327  *	authkerb_getucred(rqst, uid, gid, grouplen, groups)
328  *	const struct svc_req *rqst;		- request pointer
329  *	uid_t *uid;
330  *	gid_t *gid;
331  *	short *grouplen;
332  *	int *groups;
333  *
334  */
335 __BEGIN_DECLS
336 extern int	authkerb_getucred(/* struct svc_req *, uid_t *, gid_t *,
337 		    short *, int * */);
338 __END_DECLS
339 #endif /* KERBEROS */
340 
341 __BEGIN_DECLS
342 struct svc_req;
343 struct rpc_msg;
344 enum auth_stat _svcauth_null (struct svc_req *, struct rpc_msg *);
345 enum auth_stat _svcauth_short (struct svc_req *, struct rpc_msg *);
346 enum auth_stat _svcauth_unix (struct svc_req *, struct rpc_msg *);
347 __END_DECLS
348 
349 #define AUTH_NONE	0		/* no authentication */
350 #define	AUTH_NULL	0		/* backward compatibility */
351 #define	AUTH_SYS	1		/* unix style (uid, gids) */
352 #define AUTH_UNIX	AUTH_SYS
353 #define	AUTH_SHORT	2		/* short hand unix style */
354 #define AUTH_DH		3		/* for Diffie-Hellman mechanism */
355 #define AUTH_DES	AUTH_DH		/* for backward compatibility */
356 #define AUTH_KERB	4		/* kerberos style */
357 #define RPCSEC_GSS	6		/* RPCSEC_GSS */
358 
359 /*
360  * Pseudo auth flavors for RPCSEC_GSS.
361  */
362 #define	RPCSEC_GSS_KRB5		390003
363 #define	RPCSEC_GSS_KRB5I	390004
364 #define	RPCSEC_GSS_KRB5P	390005
365 
366 #endif /* !_RPC_AUTH_H */
367