xref: /titanic_52/usr/src/uts/common/rpc/auth.h (revision 88447a05f537aabe9a1bc3d5313f22581ec992a7)
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 2009 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 #include <rpc/xdr.h>
45 #include <rpc/clnt_stat.h>
46 #include <sys/cred.h>
47 #include <sys/tiuser.h>
48 #ifdef _KERNEL
49 #include <sys/zone.h>
50 #endif
51 
52 #ifdef	__cplusplus
53 extern "C" {
54 #endif
55 
56 #define	MAX_AUTH_BYTES	400
57 #define	MAXNETNAMELEN	255	/* maximum length of network user's name */
58 
59 /*
60  *  Client side authentication/security data
61  */
62 typedef struct sec_data {
63 	uint_t	secmod;		/* security mode number e.g. in nfssec.conf */
64 	uint_t	rpcflavor;	/* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
65 	int	flags;		/* AUTH_F_xxx flags */
66 	uid_t	uid;		/* uid of caller for all sec flavors (NFSv4)  */
67 	caddr_t	data;		/* opaque data per flavor */
68 } sec_data_t;
69 
70 #ifdef _SYSCALL32_IMPL
71 struct sec_data32 {
72 	uint32_t	secmod;	/* security mode number e.g. in nfssec.conf */
73 	uint32_t	rpcflavor; /* AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
74 	int32_t		flags;	/* AUTH_F_xxx flags */
75 	uid_t		uid;	/* uid of caller for all sec flavors (NFSv4) */
76 	caddr32_t	data;	/* opaque data per flavor */
77 };
78 #endif /* _SYSCALL32_IMPL */
79 
80 /*
81  * AUTH_DES flavor specific data from sec_data opaque data field.
82  * AUTH_KERB has the same structure.
83  */
84 typedef struct des_clnt_data {
85 	struct netbuf	syncaddr;	/* time sync addr */
86 	struct knetconfig *knconf;	/* knetconfig info that associated */
87 					/* with the syncaddr. */
88 	char		*netname;	/* server's netname */
89 	int		netnamelen;	/* server's netname len */
90 } dh_k4_clntdata_t;
91 
92 #ifdef _SYSCALL32_IMPL
93 struct des_clnt_data32 {
94 	struct netbuf32 syncaddr;	/* time sync addr */
95 	caddr32_t knconf;		/* knetconfig info that associated */
96 					/* with the syncaddr. */
97 	caddr32_t netname;		/* server's netname */
98 	int32_t	netnamelen;		/* server's netname len */
99 };
100 #endif /* _SYSCALL32_IMPL */
101 
102 /*
103  * flavor specific data to hold the data for AUTH_DES/AUTH_KERB(v4)
104  * in sec_data->data opaque field.
105  */
106 typedef struct krb4_svc_data {
107 	int		window;		/* window option value */
108 } krb4_svcdata_t;
109 
110 typedef struct krb4_svc_data	des_svcdata_t;
111 
112 /*
113  * authentication/security specific flags
114  */
115 #define	AUTH_F_RPCTIMESYNC	0x001	/* use RPC to do time sync */
116 #define	AUTH_F_TRYNONE		0x002	/* allow fall back to AUTH_NONE */
117 
118 
119 /*
120  * Status returned from authentication check
121  */
122 enum auth_stat {
123 	AUTH_OK = 0,
124 	/*
125 	 * failed at remote end
126 	 */
127 	AUTH_BADCRED = 1,		/* bogus credentials (seal broken) */
128 	AUTH_REJECTEDCRED = 2,		/* client should begin new session */
129 	AUTH_BADVERF = 3,		/* bogus verifier (seal broken) */
130 	AUTH_REJECTEDVERF = 4,		/* verifier expired or was replayed */
131 	AUTH_TOOWEAK = 5,		/* rejected due to security reasons */
132 	/*
133 	 * failed locally
134 	 */
135 	AUTH_INVALIDRESP = 6,		/* bogus response verifier */
136 	AUTH_FAILED = 7,			/* some unknown reason */
137 	/*
138 	 * kerberos errors
139 	 */
140 	AUTH_KERB_GENERIC = 8,		/* kerberos generic error */
141 	AUTH_TIMEEXPIRE = 9,		/* time of credential expired */
142 	AUTH_TKT_FILE = 10,		/* something wrong with ticket file */
143 	AUTH_DECODE = 11,		/* can't decode authenticator */
144 	AUTH_NET_ADDR = 12,		/* wrong net address in ticket */
145 	/*
146 	 * GSS related errors
147 	 */
148 	RPCSEC_GSS_NOCRED = 13,		/* no credentials for user */
149 	RPCSEC_GSS_FAILED = 14		/* GSS failure, credentials deleted */
150 };
151 typedef enum auth_stat AUTH_STAT;
152 
153 union des_block {
154 	struct	{
155 		uint32_t high;
156 		uint32_t low;
157 	} key;
158 	char c[8];
159 };
160 typedef union des_block des_block;
161 
162 #ifdef __STDC__
163 extern bool_t xdr_des_block(XDR *, des_block *);
164 #else
165 extern bool_t xdr_des_block();
166 #endif
167 
168 
169 /*
170  * Authentication info. Opaque to client.
171  */
172 struct opaque_auth {
173 	enum_t	oa_flavor;		/* flavor of auth */
174 	caddr_t	oa_base;		/* address of more auth stuff */
175 	uint_t	oa_length;		/* not to exceed MAX_AUTH_BYTES */
176 };
177 
178 
179 /*
180  * Auth handle, interface to client side authenticators.
181  */
182 typedef struct __auth {
183 	struct	opaque_auth	ah_cred;
184 	struct	opaque_auth	ah_verf;
185 	union	des_block	ah_key;
186 	struct auth_ops {
187 #ifdef __STDC__
188 		void	(*ah_nextverf)(struct __auth *);
189 #ifdef _KERNEL
190 		int	(*ah_marshal)(struct __auth *, XDR *, struct cred *);
191 #else
192 		int	(*ah_marshal)(struct __auth *, XDR *);
193 #endif
194 		/* nextverf & serialize */
195 		int	(*ah_validate)(struct __auth *,
196 		    struct opaque_auth *);
197 		/* validate varifier */
198 #ifdef _KERNEL
199 		int	(*ah_refresh)(struct __auth *, struct rpc_msg *,
200 		    cred_t *);
201 #else
202 		int	(*ah_refresh)(struct __auth *, void *);
203 		/* refresh credentials */
204 #endif
205 		void	(*ah_destroy)(struct __auth *);
206 		/* destroy this structure */
207 
208 #ifdef _KERNEL
209 		int	(*ah_wrap)(struct __auth *, caddr_t, uint_t,
210 		    XDR *, xdrproc_t, caddr_t);
211 		int	(*ah_unwrap)(struct __auth *, XDR *, xdrproc_t,
212 		    caddr_t);
213 #endif
214 #else
215 		void	(*ah_nextverf)();
216 		int	(*ah_marshal)();	/* nextverf & serialize */
217 		int	(*ah_validate)();	/* validate verifier */
218 		int	(*ah_refresh)();	/* refresh credentials */
219 		void	(*ah_destroy)();	/* destroy this structure */
220 #ifdef _KERNEL
221 		int	(*ah_wrap)();		/* encode XDR data */
222 		int	(*ah_unwrap)();		/* decode XDR data */
223 #endif
224 
225 #endif
226 	} *ah_ops;
227 	caddr_t ah_private;
228 } AUTH;
229 
230 
231 /*
232  * Authentication ops.
233  * The ops and the auth handle provide the interface to the authenticators.
234  *
235  * AUTH	*auth;
236  * XDR	*xdrs;
237  * struct opaque_auth verf;
238  */
239 #define	AUTH_NEXTVERF(auth)		\
240 		((*((auth)->ah_ops->ah_nextverf))(auth))
241 #define	auth_nextverf(auth)		\
242 		((*((auth)->ah_ops->ah_nextverf))(auth))
243 
244 
245 #ifdef _KERNEL
246 #define	AUTH_MARSHALL(auth, xdrs, cred)	\
247 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs, cred))
248 #define	auth_marshall(auth, xdrs, cred)	\
249 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs, cred))
250 #else
251 #define	AUTH_MARSHALL(auth, xdrs)	\
252 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
253 #define	auth_marshall(auth, xdrs)	\
254 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
255 #endif
256 
257 
258 #define	AUTH_VALIDATE(auth, verfp)	\
259 		((*((auth)->ah_ops->ah_validate))((auth), verfp))
260 #define	auth_validate(auth, verfp)	\
261 		((*((auth)->ah_ops->ah_validate))((auth), verfp))
262 
263 #ifdef _KERNEL
264 #define	AUTH_REFRESH(auth, msg, cr)		\
265 		((*((auth)->ah_ops->ah_refresh))(auth, msg, cr))
266 #define	auth_refresh(auth, msg, cr)		\
267 		((*((auth)->ah_ops->ah_refresh))(auth, msg, cr))
268 #else
269 #define	AUTH_REFRESH(auth, msg)		\
270 		((*((auth)->ah_ops->ah_refresh))(auth, msg))
271 #define	auth_refresh(auth, msg)		\
272 		((*((auth)->ah_ops->ah_refresh))(auth, msg))
273 #endif
274 
275 #define	AUTH_DESTROY(auth)		\
276 		((*((auth)->ah_ops->ah_destroy))(auth))
277 #define	auth_destroy(auth)		\
278 		((*((auth)->ah_ops->ah_destroy))(auth))
279 
280 /*
281  * Auth flavors can now apply a transformation in addition to simple XDR
282  * on the body of a call/response in ways that depend on the flavor being
283  * used.  These interfaces provide a generic interface between the
284  * internal RPC frame and the auth flavor specific code to allow the
285  * auth flavor to encode (WRAP) or decode (UNWRAP) the body.
286  */
287 #ifdef _KERNEL
288 #define	AUTH_WRAP(auth, buf, buflen, xdrs, xfunc, xwhere)	\
289 		((*((auth)->ah_ops->ah_wrap))(auth, buf, buflen, \
290 				xdrs, xfunc, xwhere))
291 #define	auth_wrap(auth, buf, buflen, xdrs, xfunc, xwhere)	\
292 		((*((auth)->ah_ops->ah_wrap))(auth, buf, buflen, \
293 				xdrs, xfunc, xwhere))
294 
295 #define	AUTH_UNWRAP(auth, xdrs, xfunc, xwhere)	\
296 		((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, xfunc, xwhere))
297 #define	auth_unwrap(auth, xdrs)	\
298 		((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, xfunc, xwhere))
299 #endif
300 
301 extern struct opaque_auth _null_auth;
302 
303 /*
304  * These are the various implementations of client side authenticators.
305  */
306 
307 /*
308  * System style authentication
309  * AUTH *authsys_create(machname, uid, gid, len, aup_gids)
310  *	const char *machname;
311  *	const uid_t uid;
312  *	const gid_t gid;
313  *	const int len;
314  *	const gid_t *aup_gids;
315  */
316 #ifdef _KERNEL
317 extern AUTH *authkern_create(void);		/* takes no parameters */
318 extern int authkern_init(void *, void *, int);
319 extern struct kmem_cache *authkern_cache;
320 extern AUTH *authnone_create(void);		/* takes no parameters */
321 extern int authnone_init(void *, void *, int);
322 extern struct kmem_cache *authnone_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 *, gid_t *);
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