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