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