xref: /freebsd/crypto/krb5/src/include/gssrpc/auth.h (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* @(#)auth.h	2.3 88/08/07 4.0 RPCSRC; from 1.17 88/02/08 SMI */
2*7f2fe78bSCy Schubert /*
3*7f2fe78bSCy Schubert  * Copyright (c) 2010, Oracle America, Inc.
4*7f2fe78bSCy Schubert  *
5*7f2fe78bSCy Schubert  * All rights reserved.
6*7f2fe78bSCy Schubert  *
7*7f2fe78bSCy Schubert  * Redistribution and use in source and binary forms, with or without
8*7f2fe78bSCy Schubert  * modification, are permitted provided that the following conditions are met:
9*7f2fe78bSCy Schubert  *
10*7f2fe78bSCy Schubert  *     * Redistributions of source code must retain the above copyright
11*7f2fe78bSCy Schubert  *       notice, this list of conditions and the following disclaimer.
12*7f2fe78bSCy Schubert  *
13*7f2fe78bSCy Schubert  *     * Redistributions in binary form must reproduce the above copyright
14*7f2fe78bSCy Schubert  *       notice, this list of conditions and the following disclaimer in
15*7f2fe78bSCy Schubert  *       the documentation and/or other materials provided with the
16*7f2fe78bSCy Schubert  *       distribution.
17*7f2fe78bSCy Schubert  *
18*7f2fe78bSCy Schubert  *     * Neither the name of the "Oracle America, Inc." nor the names of
19*7f2fe78bSCy Schubert  *       its contributors may be used to endorse or promote products
20*7f2fe78bSCy Schubert  *       derived from this software without specific prior written permission.
21*7f2fe78bSCy Schubert  *
22*7f2fe78bSCy Schubert  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23*7f2fe78bSCy Schubert  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24*7f2fe78bSCy Schubert  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25*7f2fe78bSCy Schubert  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26*7f2fe78bSCy Schubert  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27*7f2fe78bSCy Schubert  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28*7f2fe78bSCy Schubert  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29*7f2fe78bSCy Schubert  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30*7f2fe78bSCy Schubert  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31*7f2fe78bSCy Schubert  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32*7f2fe78bSCy Schubert  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33*7f2fe78bSCy Schubert  */
34*7f2fe78bSCy Schubert 
35*7f2fe78bSCy Schubert /*
36*7f2fe78bSCy Schubert  * auth.h, Authentication interface.
37*7f2fe78bSCy Schubert  *
38*7f2fe78bSCy Schubert  * The data structures are completely opaque to the client.  The client
39*7f2fe78bSCy Schubert  * is required to pass a AUTH * to routines that create rpc
40*7f2fe78bSCy Schubert  * "sessions".
41*7f2fe78bSCy Schubert  */
42*7f2fe78bSCy Schubert #ifndef GSSRPC_AUTH_H
43*7f2fe78bSCy Schubert #define GSSRPC_AUTH_H
44*7f2fe78bSCy Schubert 
45*7f2fe78bSCy Schubert #include <gssrpc/xdr.h>
46*7f2fe78bSCy Schubert 
47*7f2fe78bSCy Schubert GSSRPC__BEGIN_DECLS
48*7f2fe78bSCy Schubert 
49*7f2fe78bSCy Schubert #define MAX_AUTH_BYTES	400
50*7f2fe78bSCy Schubert #define MAXNETNAMELEN	255	/* maximum length of network user's name */
51*7f2fe78bSCy Schubert 
52*7f2fe78bSCy Schubert /*
53*7f2fe78bSCy Schubert  * Status returned from authentication check
54*7f2fe78bSCy Schubert  */
55*7f2fe78bSCy Schubert enum auth_stat {
56*7f2fe78bSCy Schubert 	AUTH_OK=0,
57*7f2fe78bSCy Schubert 	/*
58*7f2fe78bSCy Schubert 	 * failed at remote end
59*7f2fe78bSCy Schubert 	 */
60*7f2fe78bSCy Schubert 	AUTH_BADCRED=1,			/* bogus credentials (seal broken) */
61*7f2fe78bSCy Schubert 	AUTH_REJECTEDCRED=2,		/* client should begin new session */
62*7f2fe78bSCy Schubert 	AUTH_BADVERF=3,			/* bogus verifier (seal broken) */
63*7f2fe78bSCy Schubert 	AUTH_REJECTEDVERF=4,		/* verifier expired or was replayed */
64*7f2fe78bSCy Schubert 	AUTH_TOOWEAK=5,			/* rejected due to security reasons */
65*7f2fe78bSCy Schubert 	/*
66*7f2fe78bSCy Schubert 	 * failed locally
67*7f2fe78bSCy Schubert 	*/
68*7f2fe78bSCy Schubert 	AUTH_INVALIDRESP=6,		/* bogus response verifier */
69*7f2fe78bSCy Schubert 	AUTH_FAILED=7,			/* some unknown reason */
70*7f2fe78bSCy Schubert 	/*
71*7f2fe78bSCy Schubert 	 * RPCSEC_GSS errors
72*7f2fe78bSCy Schubert 	 */
73*7f2fe78bSCy Schubert 	RPCSEC_GSS_CREDPROBLEM = 13,
74*7f2fe78bSCy Schubert 	RPCSEC_GSS_CTXPROBLEM = 14
75*7f2fe78bSCy Schubert };
76*7f2fe78bSCy Schubert 
77*7f2fe78bSCy Schubert union des_block {
78*7f2fe78bSCy Schubert 	char c[8];
79*7f2fe78bSCy Schubert };
80*7f2fe78bSCy Schubert typedef union des_block des_block;
81*7f2fe78bSCy Schubert extern bool_t	xdr_des_block(XDR *, des_block *);
82*7f2fe78bSCy Schubert 
83*7f2fe78bSCy Schubert /*
84*7f2fe78bSCy Schubert  * Authentication info.  Opaque to client.
85*7f2fe78bSCy Schubert  */
86*7f2fe78bSCy Schubert struct opaque_auth {
87*7f2fe78bSCy Schubert 	enum_t	oa_flavor;		/* flavor of auth */
88*7f2fe78bSCy Schubert 	caddr_t	oa_base;		/* address of more auth stuff */
89*7f2fe78bSCy Schubert 	u_int	oa_length;		/* not to exceed MAX_AUTH_BYTES */
90*7f2fe78bSCy Schubert };
91*7f2fe78bSCy Schubert 
92*7f2fe78bSCy Schubert 
93*7f2fe78bSCy Schubert /*
94*7f2fe78bSCy Schubert  * Auth handle, interface to client side authenticators.
95*7f2fe78bSCy Schubert  */
96*7f2fe78bSCy Schubert struct rpc_msg;
97*7f2fe78bSCy Schubert 
98*7f2fe78bSCy Schubert typedef struct AUTH {
99*7f2fe78bSCy Schubert 	struct	opaque_auth	ah_cred;
100*7f2fe78bSCy Schubert 	struct	opaque_auth	ah_verf;
101*7f2fe78bSCy Schubert 	union	des_block	ah_key;
102*7f2fe78bSCy Schubert 	struct auth_ops {
103*7f2fe78bSCy Schubert 		void	(*ah_nextverf)(struct AUTH *);
104*7f2fe78bSCy Schubert 	        /* nextverf & serialize */
105*7f2fe78bSCy Schubert 		int	(*ah_marshal)(struct AUTH *, XDR *);
106*7f2fe78bSCy Schubert 	        /* validate varifier */
107*7f2fe78bSCy Schubert 		int	(*ah_validate)(struct AUTH *,
108*7f2fe78bSCy Schubert 				       struct opaque_auth *);
109*7f2fe78bSCy Schubert 	        /* refresh credentials */
110*7f2fe78bSCy Schubert 		int	(*ah_refresh)(struct AUTH *, struct rpc_msg *);
111*7f2fe78bSCy Schubert 	        /* destroy this structure */
112*7f2fe78bSCy Schubert 		void	(*ah_destroy)(struct AUTH *);
113*7f2fe78bSCy Schubert 		/* encode data for wire */
114*7f2fe78bSCy Schubert 		int     (*ah_wrap)(struct AUTH *, XDR *,
115*7f2fe78bSCy Schubert 				   xdrproc_t, caddr_t);
116*7f2fe78bSCy Schubert 	        /* decode data from wire */
117*7f2fe78bSCy Schubert   	        int	(*ah_unwrap)(struct AUTH *, XDR *,
118*7f2fe78bSCy Schubert 				     xdrproc_t, caddr_t);
119*7f2fe78bSCy Schubert 	} *ah_ops;
120*7f2fe78bSCy Schubert 	void *ah_private;
121*7f2fe78bSCy Schubert } AUTH;
122*7f2fe78bSCy Schubert 
123*7f2fe78bSCy Schubert 
124*7f2fe78bSCy Schubert /*
125*7f2fe78bSCy Schubert  * Authentication ops.
126*7f2fe78bSCy Schubert  * The ops and the auth handle provide the interface to the authenticators.
127*7f2fe78bSCy Schubert  *
128*7f2fe78bSCy Schubert  * AUTH	*auth;
129*7f2fe78bSCy Schubert  * XDR	*xdrs;
130*7f2fe78bSCy Schubert  * struct opaque_auth verf;
131*7f2fe78bSCy Schubert  */
132*7f2fe78bSCy Schubert #define AUTH_NEXTVERF(auth)		\
133*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_nextverf))(auth))
134*7f2fe78bSCy Schubert #define auth_nextverf(auth)		\
135*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_nextverf))(auth))
136*7f2fe78bSCy Schubert 
137*7f2fe78bSCy Schubert #define AUTH_MARSHALL(auth, xdrs)	\
138*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
139*7f2fe78bSCy Schubert #define auth_marshall(auth, xdrs)	\
140*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
141*7f2fe78bSCy Schubert 
142*7f2fe78bSCy Schubert #define AUTH_VALIDATE(auth, verfp)	\
143*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_validate))((auth), verfp))
144*7f2fe78bSCy Schubert #define auth_validate(auth, verfp)	\
145*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_validate))((auth), verfp))
146*7f2fe78bSCy Schubert 
147*7f2fe78bSCy Schubert #define AUTH_REFRESH(auth, msg)		\
148*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_refresh))(auth, msg))
149*7f2fe78bSCy Schubert #define auth_refresh(auth, msg)		\
150*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_refresh))(auth, msg))
151*7f2fe78bSCy Schubert 
152*7f2fe78bSCy Schubert #define AUTH_WRAP(auth, xdrs, xfunc, xwhere)		\
153*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_wrap))(auth, xdrs, \
154*7f2fe78bSCy Schubert 					      xfunc, xwhere))
155*7f2fe78bSCy Schubert #define auth_wrap(auth, xdrs, xfunc, xwhere)		\
156*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_wrap))(auth, xdrs, \
157*7f2fe78bSCy Schubert 					      xfunc, xwhere))
158*7f2fe78bSCy Schubert #define AUTH_UNWRAP(auth, xdrs, xfunc, xwhere)		\
159*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, \
160*7f2fe78bSCy Schubert 					      xfunc, xwhere))
161*7f2fe78bSCy Schubert #define auth_unwrap(auth, xdrs, xfunc, xwhere)		\
162*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, \
163*7f2fe78bSCy Schubert 					      xfunc, xwhere))
164*7f2fe78bSCy Schubert 
165*7f2fe78bSCy Schubert #define AUTH_DESTROY(auth)		\
166*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_destroy))(auth))
167*7f2fe78bSCy Schubert #define auth_destroy(auth)		\
168*7f2fe78bSCy Schubert 		((*((auth)->ah_ops->ah_destroy))(auth))
169*7f2fe78bSCy Schubert 
170*7f2fe78bSCy Schubert 
171*7f2fe78bSCy Schubert #ifdef GSSRPC__IMPL
172*7f2fe78bSCy Schubert /* RENAMED: should be _null_auth if we can use reserved namespace. */
173*7f2fe78bSCy Schubert extern struct opaque_auth gssrpc__null_auth;
174*7f2fe78bSCy Schubert #endif
175*7f2fe78bSCy Schubert 
176*7f2fe78bSCy Schubert /*
177*7f2fe78bSCy Schubert  * These are the various implementations of client side authenticators.
178*7f2fe78bSCy Schubert  */
179*7f2fe78bSCy Schubert 
180*7f2fe78bSCy Schubert /*
181*7f2fe78bSCy Schubert  * Unix style authentication
182*7f2fe78bSCy Schubert  * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
183*7f2fe78bSCy Schubert  *	char *machname;
184*7f2fe78bSCy Schubert  *	int uid;
185*7f2fe78bSCy Schubert  *	int gid;
186*7f2fe78bSCy Schubert  *	int len;
187*7f2fe78bSCy Schubert  *	int *aup_gids;
188*7f2fe78bSCy Schubert  */
189*7f2fe78bSCy Schubert extern AUTH *authunix_create(char *machname, int uid, int gid, int len,
190*7f2fe78bSCy Schubert 			     int *aup_gids);
191*7f2fe78bSCy Schubert extern AUTH *authunix_create_default(void);	/* takes no parameters */
192*7f2fe78bSCy Schubert extern AUTH *authnone_create(void);		/* takes no parameters */
193*7f2fe78bSCy Schubert extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
194*7f2fe78bSCy Schubert 
195*7f2fe78bSCy Schubert #define AUTH_NONE	0		/* no authentication */
196*7f2fe78bSCy Schubert #define	AUTH_NULL	0		/* backward compatibility */
197*7f2fe78bSCy Schubert #define	AUTH_UNIX	1		/* unix style (uid, gids) */
198*7f2fe78bSCy Schubert #define	AUTH_SHORT	2		/* short hand unix style */
199*7f2fe78bSCy Schubert #define AUTH_DES	3		/* des style (encrypted timestamps) */
200*7f2fe78bSCy Schubert #define AUTH_GSSAPI	300001		/* GSS-API style */
201*7f2fe78bSCy Schubert #define RPCSEC_GSS	6		/* RPCSEC_GSS */
202*7f2fe78bSCy Schubert 
203*7f2fe78bSCy Schubert GSSRPC__END_DECLS
204*7f2fe78bSCy Schubert 
205*7f2fe78bSCy Schubert #endif /* !defined(GSSRPC_AUTH_H) */
206