1 /*  $Id$ */
2 /*	$OpenBSD: auth.h,v 1.2 1997/09/21 10:46:09 niklas Exp $	*/
3 /*	$NetBSD: auth.h,v 1.7 1995/04/29 05:27:55 cgd Exp $	*/
4 
5 /*
6  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
7  * unrestricted use provided that this legend is included on all tape
8  * media and as a part of the software program in whole or part.  Users
9  * may copy or modify Sun RPC without charge, but are not authorized
10  * to license or distribute it to anyone else except as part of a product or
11  * program developed by the user.
12  *
13  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
14  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
15  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
16  *
17  * Sun RPC is provided with no support and without any obligation on the
18  * part of Sun Microsystems, Inc. to assist in its use, correction,
19  * modification or enhancement.
20  *
21  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
22  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
23  * OR ANY PART THEREOF.
24  *
25  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
26  * or profits or other special, indirect and consequential damages, even if
27  * Sun has been advised of the possibility of such damages.
28  *
29  * Sun Microsystems, Inc.
30  * 2550 Garcia Avenue
31  * Mountain View, California  94043
32  *
33  *	from: @(#)auth.h 1.17 88/02/08 SMI
34  *	@(#)auth.h	2.3 88/08/07 4.0 RPCSRC
35  */
36 
37 /*
38  * auth.h, Authentication interface.
39  *
40  * Copyright (C) 1984, Sun Microsystems, Inc.
41  *
42  * The data structures are completely opaque to the client.  The client
43  * is required to pass a AUTH * to routines that create rpc
44  * "sessions".
45  */
46 
47 #ifndef _RPC_AUTH_H
48 #define _RPC_AUTH_H
49 #ifndef WIN32
50 	#include <sys/cdefs.h>
51 #endif
52 
53 #define MAX_AUTH_BYTES	400
54 #define MAXNETNAMELEN	255	/* maximum length of network user's name */
55 
56 /*
57  * Status returned from authentication check
58  */
59 enum auth_stat {
60 	AUTH_OK=0,
61 	/*
62 	 * failed at remote end
63 	 */
64 	AUTH_BADCRED=1,			/* bogus credentials (seal broken) */
65 	AUTH_REJECTEDCRED=2,		/* client should begin new session */
66 	AUTH_BADVERF=3,			/* bogus verifier (seal broken) */
67 	AUTH_REJECTEDVERF=4,		/* verifier expired or was replayed */
68 	AUTH_TOOWEAK=5,			/* rejected due to security reasons */
69 	/*
70 	 * failed locally
71 	*/
72 	AUTH_INVALIDRESP=6,		/* bogus response verifier */
73 	AUTH_FAILED=7			/* some unknown reason */
74 };
75 
76 #ifdef WIN32
77     /* This is now located in <stdint.h> */
78 	/*typedef unsigned int u_int32;*/	/* 32-bit unsigned integers */
79     #include <stdint.h>
80 #else
81 	/*typedef u_int32_t u_int32;*/	/* 32-bit unsigned integers */
82 #endif
83 
84 union des_block {
85 	struct {
86 		u_int32 high;
87 		u_int32 low;
88 	} key;
89 	char c[8];
90 };
91 typedef union des_block des_block;
92 __BEGIN_DECLS
93 extern bool_t xdr_des_block __P((XDR *, des_block *));
94 __END_DECLS
95 
96 /*
97  * Authentication info.  Opaque to client.
98  */
99 struct opaque_auth {
100 	enum_t	oa_flavor;		/* flavor of auth */
101 	caddr_t	oa_base;		/* address of more auth stuff */
102 	u_int	oa_length;		/* not to exceed MAX_AUTH_BYTES */
103 };
104 
105 
106 /*
107  * Auth handle, interface to client side authenticators.
108  */
109 typedef struct __rpc_auth {
110 	struct	opaque_auth	ah_cred;
111 	struct	opaque_auth	ah_verf;
112 	union	des_block	ah_key;
113 	struct auth_ops {
114 		void	(*ah_nextverf) __P((struct __rpc_auth *));
115 		/* nextverf & serialize */
116 		int	(*ah_marshal) __P((struct __rpc_auth *, XDR *));
117 		/* validate varifier */
118 		int	(*ah_validate) __P((struct __rpc_auth *,
119 			    struct opaque_auth *));
120 		/* refresh credentials */
121 		int	(*ah_refresh) __P((struct __rpc_auth *));
122 		/* destroy this structure */
123 		void	(*ah_destroy) __P((struct __rpc_auth *));
124 	} *ah_ops;
125 	caddr_t ah_private;
126 } AUTH;
127 
128 
129 /*
130  * Authentication ops.
131  * The ops and the auth handle provide the interface to the authenticators.
132  *
133  * AUTH	*auth;
134  * XDR	*xdrs;
135  * struct opaque_auth verf;
136  */
137 #define AUTH_NEXTVERF(auth)		\
138 		((*((auth)->ah_ops->ah_nextverf))(auth))
139 #define auth_nextverf(auth)		\
140 		((*((auth)->ah_ops->ah_nextverf))(auth))
141 
142 #define AUTH_MARSHALL(auth, xdrs)	\
143 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
144 #define auth_marshall(auth, xdrs)	\
145 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
146 
147 #define AUTH_VALIDATE(auth, verfp)	\
148 		((*((auth)->ah_ops->ah_validate))((auth), verfp))
149 #define auth_validate(auth, verfp)	\
150 		((*((auth)->ah_ops->ah_validate))((auth), verfp))
151 
152 #define AUTH_REFRESH(auth)		\
153 		((*((auth)->ah_ops->ah_refresh))(auth))
154 #define auth_refresh(auth)		\
155 		((*((auth)->ah_ops->ah_refresh))(auth))
156 
157 #define AUTH_DESTROY(auth)		\
158 		((*((auth)->ah_ops->ah_destroy))(auth))
159 #define auth_destroy(auth)		\
160 		((*((auth)->ah_ops->ah_destroy))(auth))
161 
162 
163 extern struct opaque_auth _null_auth;
164 
165 
166 /*
167  * These are the various implementations of client side authenticators.
168  */
169 
170 /*
171  * Unix style authentication
172  * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
173  *	char *machname;
174  *	int uid;
175  *	int gid;
176  *	int len;
177  *	int *aup_gids;
178  */
179 __BEGIN_DECLS
180 struct sockaddr_in;
181 extern AUTH *authunix_create		__P((char *, int, int, int, int *));
182 extern AUTH *authunix_create_default	__P((void));
183 extern AUTH *authnone_create		__P((void));
184 extern AUTH *authdes_create		__P((char *, u_int,
185 					    struct sockaddr_in *, des_block *));
186 __END_DECLS
187 
188 #define AUTH_NONE	0		/* no authentication */
189 #define	AUTH_NULL	0		/* backward compatibility */
190 #define	AUTH_UNIX	1		/* unix style (uid, gids) */
191 #define	AUTH_SHORT	2		/* short hand unix style */
192 #define AUTH_DES	3		/* des style (encrypted timestamps) */
193 
194 #endif /* !_RPC_AUTH_H */
195