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