xref: /titanic_50/usr/src/uts/common/rpc/auth.h (revision 19174f18ff621e2acd8b3e8f6a9504a68e5fd8f7)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
26 /* All Rights Reserved */
27 /*
28  * Portions of this source code were derived from Berkeley
29  * 4.3 BSD under license from the Regents of the University of
30  * California.
31  */
32 
33 /*
34  * auth.h, Authentication interface.
35  *
36  * The data structures are completely opaque to the client. The client
37  * is required to pass a AUTH * to routines that create rpc
38  * "sessions".
39  */
40 
41 #ifndef	_RPC_AUTH_H
42 #define	_RPC_AUTH_H
43 
44 #pragma ident	"%Z%%M%	%I%	%E% SMI"
45 
46 #include <rpc/xdr.h>
47 #include <rpc/clnt_stat.h>
48 #include <sys/cred.h>
49 #include <sys/tiuser.h>
50 #ifdef _KERNEL
51 #include <sys/zone.h>
52 #endif
53 
54 #ifdef	__cplusplus
55 extern "C" {
56 #endif
57 
58 #define	MAX_AUTH_BYTES	400
59 #define	MAXNETNAMELEN	255	/* maximum length of network user's name */
60 
61 /*
62  *  Client side authentication/security data
63  */
64 typedef struct sec_data {
65 	uint_t	secmod;		/* security mode number e.g. in nfssec.conf */
66 	uint_t	rpcflavor;	/* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
67 	int	flags;		/* AUTH_F_xxx flags */
68 	uid_t	uid;		/* uid of caller for all sec flavors (NFSv4)  */
69 	caddr_t	data;		/* opaque data per flavor */
70 } sec_data_t;
71 
72 #ifdef _SYSCALL32_IMPL
73 struct sec_data32 {
74 	uint32_t	secmod;	/* security mode number e.g. in nfssec.conf */
75 	uint32_t	rpcflavor; /* AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
76 	int32_t		flags;	/* AUTH_F_xxx flags */
77 	uid_t		uid;	/* uid of caller for all sec flavors (NFSv4) */
78 	caddr32_t	data;	/* opaque data per flavor */
79 };
80 #endif /* _SYSCALL32_IMPL */
81 
82 /*
83  * AUTH_DES flavor specific data from sec_data opaque data field.
84  * AUTH_KERB has the same structure.
85  */
86 typedef struct des_clnt_data {
87 	struct netbuf	syncaddr;	/* time sync addr */
88 	struct knetconfig *knconf;	/* knetconfig info that associated */
89 					/* with the syncaddr. */
90 	char		*netname;	/* server's netname */
91 	int		netnamelen;	/* server's netname len */
92 } dh_k4_clntdata_t;
93 
94 #ifdef _SYSCALL32_IMPL
95 struct des_clnt_data32 {
96 	struct netbuf32 syncaddr;	/* time sync addr */
97 	caddr32_t knconf;		/* knetconfig info that associated */
98 					/* with the syncaddr. */
99 	caddr32_t netname;		/* server's netname */
100 	int32_t	netnamelen;		/* server's netname len */
101 };
102 #endif /* _SYSCALL32_IMPL */
103 
104 /*
105  * flavor specific data to hold the data for AUTH_DES/AUTH_KERB(v4)
106  * in sec_data->data opaque field.
107  */
108 typedef struct krb4_svc_data {
109 	int		window;		/* window option value */
110 } krb4_svcdata_t;
111 
112 typedef struct krb4_svc_data	des_svcdata_t;
113 
114 /*
115  * authentication/security specific flags
116  */
117 #define	AUTH_F_RPCTIMESYNC	0x001	/* use RPC to do time sync */
118 #define	AUTH_F_TRYNONE		0x002	/* allow fall back to AUTH_NONE */
119 
120 
121 /*
122  * Status returned from authentication check
123  */
124 enum auth_stat {
125 	AUTH_OK = 0,
126 	/*
127 	 * failed at remote end
128 	 */
129 	AUTH_BADCRED = 1,		/* bogus credentials (seal broken) */
130 	AUTH_REJECTEDCRED = 2,		/* client should begin new session */
131 	AUTH_BADVERF = 3,		/* bogus verifier (seal broken) */
132 	AUTH_REJECTEDVERF = 4,		/* verifier expired or was replayed */
133 	AUTH_TOOWEAK = 5,		/* rejected due to security reasons */
134 	/*
135 	 * failed locally
136 	 */
137 	AUTH_INVALIDRESP = 6,		/* bogus response verifier */
138 	AUTH_FAILED = 7,			/* some unknown reason */
139 	/*
140 	 * kerberos errors
141 	 */
142 	AUTH_KERB_GENERIC = 8,		/* kerberos generic error */
143 	AUTH_TIMEEXPIRE = 9,		/* time of credential expired */
144 	AUTH_TKT_FILE = 10,		/* something wrong with ticket file */
145 	AUTH_DECODE = 11,		/* can't decode authenticator */
146 	AUTH_NET_ADDR = 12,		/* wrong net address in ticket */
147 	/*
148 	 * GSS related errors
149 	 */
150 	RPCSEC_GSS_NOCRED = 13,		/* no credentials for user */
151 	RPCSEC_GSS_FAILED = 14		/* GSS failure, credentials deleted */
152 };
153 typedef enum auth_stat AUTH_STAT;
154 
155 union des_block {
156 	struct	{
157 		uint32_t high;
158 		uint32_t low;
159 	} key;
160 	char c[8];
161 };
162 typedef union des_block des_block;
163 
164 #ifdef __STDC__
165 extern bool_t xdr_des_block(XDR *, des_block *);
166 #else
167 extern bool_t xdr_des_block();
168 #endif
169 
170 
171 /*
172  * Authentication info. Opaque to client.
173  */
174 struct opaque_auth {
175 	enum_t	oa_flavor;		/* flavor of auth */
176 	caddr_t	oa_base;		/* address of more auth stuff */
177 	uint_t	oa_length;		/* not to exceed MAX_AUTH_BYTES */
178 };
179 
180 
181 /*
182  * Auth handle, interface to client side authenticators.
183  */
184 typedef struct __auth {
185 	struct	opaque_auth	ah_cred;
186 	struct	opaque_auth	ah_verf;
187 	union	des_block	ah_key;
188 	struct auth_ops {
189 #ifdef __STDC__
190 		void	(*ah_nextverf)(struct __auth *);
191 #ifdef _KERNEL
192 		int	(*ah_marshal)(struct __auth *, XDR *, struct cred *);
193 #else
194 		int	(*ah_marshal)(struct __auth *, XDR *);
195 #endif
196 		/* nextverf & serialize */
197 		int	(*ah_validate)(struct __auth *,
198 		    struct opaque_auth *);
199 		/* validate varifier */
200 #ifdef _KERNEL
201 		int	(*ah_refresh)(struct __auth *, struct rpc_msg *,
202 		    cred_t *);
203 #else
204 		int	(*ah_refresh)(struct __auth *, void *);
205 		/* refresh credentials */
206 #endif
207 		void	(*ah_destroy)(struct __auth *);
208 		/* destroy this structure */
209 
210 #ifdef _KERNEL
211 		int	(*ah_wrap)(struct __auth *, caddr_t, uint_t,
212 		    XDR *, xdrproc_t, caddr_t);
213 		int	(*ah_unwrap)(struct __auth *, XDR *, xdrproc_t,
214 		    caddr_t);
215 #endif
216 #else
217 		void	(*ah_nextverf)();
218 		int	(*ah_marshal)();	/* nextverf & serialize */
219 		int	(*ah_validate)();	/* validate verifier */
220 		int	(*ah_refresh)();	/* refresh credentials */
221 		void	(*ah_destroy)();	/* destroy this structure */
222 #ifdef _KERNEL
223 		int	(*ah_wrap)();		/* encode XDR data */
224 		int	(*ah_unwrap)();		/* decode XDR data */
225 #endif
226 
227 #endif
228 	} *ah_ops;
229 	caddr_t ah_private;
230 } AUTH;
231 
232 
233 /*
234  * Authentication ops.
235  * The ops and the auth handle provide the interface to the authenticators.
236  *
237  * AUTH	*auth;
238  * XDR	*xdrs;
239  * struct opaque_auth verf;
240  */
241 #define	AUTH_NEXTVERF(auth)		\
242 		((*((auth)->ah_ops->ah_nextverf))(auth))
243 #define	auth_nextverf(auth)		\
244 		((*((auth)->ah_ops->ah_nextverf))(auth))
245 
246 
247 #ifdef _KERNEL
248 #define	AUTH_MARSHALL(auth, xdrs, cred)	\
249 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs, cred))
250 #define	auth_marshall(auth, xdrs, cred)	\
251 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs, cred))
252 #else
253 #define	AUTH_MARSHALL(auth, xdrs)	\
254 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
255 #define	auth_marshall(auth, xdrs)	\
256 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
257 #endif
258 
259 
260 #define	AUTH_VALIDATE(auth, verfp)	\
261 		((*((auth)->ah_ops->ah_validate))((auth), verfp))
262 #define	auth_validate(auth, verfp)	\
263 		((*((auth)->ah_ops->ah_validate))((auth), verfp))
264 
265 #ifdef _KERNEL
266 #define	AUTH_REFRESH(auth, msg, cr)		\
267 		((*((auth)->ah_ops->ah_refresh))(auth, msg, cr))
268 #define	auth_refresh(auth, msg, cr)		\
269 		((*((auth)->ah_ops->ah_refresh))(auth, msg, cr))
270 #else
271 #define	AUTH_REFRESH(auth, msg)		\
272 		((*((auth)->ah_ops->ah_refresh))(auth, msg))
273 #define	auth_refresh(auth, msg)		\
274 		((*((auth)->ah_ops->ah_refresh))(auth, msg))
275 #endif
276 
277 #define	AUTH_DESTROY(auth)		\
278 		((*((auth)->ah_ops->ah_destroy))(auth))
279 #define	auth_destroy(auth)		\
280 		((*((auth)->ah_ops->ah_destroy))(auth))
281 
282 /*
283  * Auth flavors can now apply a transformation in addition to simple XDR
284  * on the body of a call/response in ways that depend on the flavor being
285  * used.  These interfaces provide a generic interface between the
286  * internal RPC frame and the auth flavor specific code to allow the
287  * auth flavor to encode (WRAP) or decode (UNWRAP) the body.
288  */
289 #ifdef _KERNEL
290 #define	AUTH_WRAP(auth, buf, buflen, xdrs, xfunc, xwhere)	\
291 		((*((auth)->ah_ops->ah_wrap))(auth, buf, buflen, \
292 				xdrs, xfunc, xwhere))
293 #define	auth_wrap(auth, buf, buflen, xdrs, xfunc, xwhere)	\
294 		((*((auth)->ah_ops->ah_wrap))(auth, buf, buflen, \
295 				xdrs, xfunc, xwhere))
296 
297 #define	AUTH_UNWRAP(auth, xdrs, xfunc, xwhere)	\
298 		((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, xfunc, xwhere))
299 #define	auth_unwrap(auth, xdrs)	\
300 		((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, xfunc, xwhere))
301 #endif
302 
303 extern struct opaque_auth _null_auth;
304 
305 /*
306  * These are the various implementations of client side authenticators.
307  */
308 
309 /*
310  * System style authentication
311  * AUTH *authsys_create(machname, uid, gid, len, aup_gids)
312  *	const char *machname;
313  *	const uid_t uid;
314  *	const gid_t gid;
315  *	const int len;
316  *	const gid_t *aup_gids;
317  */
318 #ifdef _KERNEL
319 extern AUTH *authkern_create(void);		/* takes no parameters */
320 extern int authkern_init(void *, void *, int);
321 extern struct kmem_cache *authkern_cache;
322 extern AUTH *authloopback_create(void);		/* takes no parameters */
323 extern int authloopback_init(void *, void *, int);
324 extern struct kmem_cache *authloopback_cache;
325 #else /* _KERNEL */
326 #ifdef __STDC__
327 extern AUTH *authsys_create(const char *, const uid_t, const gid_t, const int,
328     const gid_t *);
329 extern AUTH *authsys_create_default(void);	/* takes no parameters */
330 extern AUTH *authnone_create(void);		/* takes no parameters */
331 #else /* __STDC__ */
332 extern AUTH *authsys_create();
333 extern AUTH *authsys_create_default();	/* takes no parameters */
334 extern AUTH *authnone_create();	/* takes no parameters */
335 #endif /* __STDC__ */
336 /* Will get obsolete in near future */
337 #define	authunix_create		authsys_create
338 #define	authunix_create_default authsys_create_default
339 #endif /* _KERNEL */
340 
341 /*
342  * DES style authentication
343  * AUTH *authdes_seccreate(servername, window, timehost, ckey)
344  *	const char *servername;		- network name of server
345  *	const uint_t window;			- time to live
346  *	const char *timehost;			- optional hostname to sync with
347  *	const des_block *ckey;		- optional conversation key to use
348  */
349 /* Will get obsolete in near future */
350 #ifdef _KERNEL
351 extern int authdes_create(char *, uint_t, struct netbuf *, struct knetconfig *,
352     des_block *, int, AUTH **retauth);
353 #else /* _KERNEL */
354 #ifdef __STDC__
355 extern AUTH *authdes_seccreate(const char *, const uint_t, const  char *,
356     const des_block *);
357 #else
358 extern AUTH *authdes_seccreate();
359 #endif /* __STDC__ */
360 #endif /* _KERNEL */
361 
362 /*
363  *  Netname manipulating functions
364  */
365 
366 #ifdef	_KERNEL
367 extern enum clnt_stat netname2user(char *, uid_t *, gid_t *, int *, gid_t *);
368 #endif
369 #ifdef __STDC__
370 extern int getnetname(char *);
371 extern int host2netname(char *, const char *, const char *);
372 extern int user2netname(char *, const uid_t, const char *);
373 #ifndef	_KERNEL
374 extern int netname2user(const char *, uid_t *, gid_t *, int *, gid_t *);
375 #endif
376 extern int netname2host(const char *, char *, const int);
377 #else
378 extern int getnetname();
379 extern int host2netname();
380 extern int user2netname();
381 extern int netname2host();
382 #endif
383 
384 /*
385  * These routines interface to the keyserv daemon
386  */
387 
388 #ifdef _KERNEL
389 extern enum clnt_stat key_decryptsession();
390 extern enum clnt_stat key_encryptsession();
391 extern enum clnt_stat key_gendes();
392 extern enum clnt_stat key_getnetname();
393 #endif
394 
395 #ifndef _KERNEL
396 #ifdef	__STDC__
397 extern int key_decryptsession(const char *, des_block *);
398 extern int key_encryptsession(const char *, des_block *);
399 extern int key_gendes(des_block *);
400 extern int key_setsecret(const char *);
401 extern int key_secretkey_is_set(void);
402 /*
403  * The following routines are private.
404  */
405 extern int key_setnet_ruid();
406 extern int key_setnet_g_ruid();
407 extern int key_removesecret_g_ruid();
408 extern int key_secretkey_is_set_g_ruid();
409 extern AUTH *authsys_create_ruid();
410 #else
411 extern int key_decryptsession();
412 extern int key_encryptsession();
413 extern int key_gendes();
414 extern int key_setsecret();
415 extern int key_secretkey_is_set();
416 #endif
417 #endif
418 
419 
420 /*
421  * Kerberos style authentication
422  * AUTH *authkerb_seccreate(service, srv_inst, realm, window, timehost, status)
423  *	const char *service;			- service name
424  *	const char *srv_inst;			- server instance
425  *	const char *realm;			- server realm
426  *	const uint_t window;			- time to live
427  *	const char *timehost;			- optional hostname to sync with
428  *	int *status;			- kerberos status returned
429  */
430 #ifdef _KERNEL
431 extern int    authkerb_create(char *, char *, char *, uint_t,
432     struct netbuf *, int *, struct knetconfig *, int, AUTH **);
433 #else
434 #ifdef __STDC__
435 extern AUTH *authkerb_seccreate(const char *, const char *, const  char *,
436     const uint_t, const char *, int *);
437 #else
438 extern AUTH *authkerb_seccreate();
439 #endif
440 #endif /* _KERNEL */
441 
442 /*
443  * Map a kerberos credential into a unix cred.
444  *
445  *  authkerb_getucred(rqst, uid, gid, grouplen, groups)
446  *	const struct svc_req *rqst;		- request pointer
447  *	uid_t *uid;
448  *	gid_t *gid;
449  *	short *grouplen;
450  *	int   *groups;
451  *
452  */
453 #ifdef __STDC__
454 struct svc_req;
455 extern int authkerb_getucred(struct svc_req *, uid_t *, gid_t *,
456     short *, int *);
457 #else
458 extern int authkerb_getucred();
459 #endif
460 
461 #ifdef _KERNEL
462 /*
463  * XDR an opaque authentication struct.  See auth.h.
464  */
465 extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
466 #endif
467 
468 #ifdef _KERNEL
469 extern int authany_wrap(AUTH *, caddr_t, uint_t, XDR *, xdrproc_t, caddr_t);
470 extern int authany_unwrap(AUTH *, XDR *, xdrproc_t, caddr_t);
471 #endif
472 
473 #define	AUTH_NONE	0		/* no authentication */
474 #define	AUTH_NULL	0		/* backward compatibility */
475 #define	AUTH_SYS	1		/* unix style (uid, gids) */
476 #define	AUTH_UNIX	AUTH_SYS
477 #define	AUTH_SHORT	2		/* short hand unix style */
478 #define	AUTH_DH		3		/* for Diffie-Hellman mechanism */
479 #define	AUTH_DES	AUTH_DH		/* for backward compatibility */
480 #define	AUTH_KERB	4		/* kerberos style */
481 #define	RPCSEC_GSS	6		/* GSS-API style */
482 
483 #define	AUTH_LOOPBACK	21982		/* unix style w/ expanded groups */
484 					/* for use over the local transport */
485 
486 #ifdef _KERNEL
487 extern char	loopback_name[];
488 
489 extern zone_key_t	auth_zone_key;
490 extern void *		auth_zone_init(zoneid_t);
491 extern void		auth_zone_fini(zoneid_t, void *);
492 #endif
493 
494 #ifdef	__cplusplus
495 }
496 #endif
497 
498 #endif	/* !_RPC_AUTH_H */
499