Bring in a transport-independent RPC (TI-RPC).
[dragonfly.git] / include / rpc / auth.h
CommitLineData
984263bc
MD
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12 *
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
16 *
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
20 *
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
24 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California 94043
28 *
29 * from: @(#)auth.h 1.17 88/02/08 SMI
30 * from: @(#)auth.h 2.3 88/08/07 4.0 RPCSRC
ce0e08e2
PA
31 * from: @(#)auth.h 1.43 98/02/02 SMI
32 * $NetBSD: auth.h,v 1.15 2000/06/02 22:57:55 fvdl Exp $
33 * $FreeBSD: src/include/rpc/auth.h,v 1.21 2006/02/28 16:02:26 deischen Exp $
5baeefc7 34 * $DragonFly: src/include/rpc/auth.h,v 1.4 2004/02/26 13:58:26 joerg Exp $
984263bc
MD
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
ce0e08e2 43 * is required to pass an AUTH * to routines that create rpc
984263bc
MD
44 * "sessions".
45 */
46
47#ifndef _RPC_AUTH_H
48#define _RPC_AUTH_H
ce0e08e2
PA
49#include <rpc/xdr.h>
50#include <rpc/clnt_stat.h>
984263bc
MD
51#include <sys/cdefs.h>
52#include <sys/socket.h>
53
54#define MAX_AUTH_BYTES 400
55#define MAXNETNAMELEN 255 /* maximum length of network user's name */
56
ce0e08e2
PA
57/*
58 * Client side authentication/security data
59 */
60
61typedef struct sec_data {
62 u_int secmod; /* security mode number e.g. in nfssec.conf */
63 u_int rpcflavor; /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
64 int flags; /* AUTH_F_xxx flags */
65 caddr_t data; /* opaque data per flavor */
66} sec_data_t;
67
68#ifdef _SYSCALL32_IMPL
69struct sec_data32 {
70 uint32_t secmod; /* security mode number e.g. in nfssec.conf */
71 uint32_t rpcflavor; /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
72 int32_t flags; /* AUTH_F_xxx flags */
73 caddr32_t data; /* opaque data per flavor */
74};
75#endif /* _SYSCALL32_IMPL */
76
77/*
78 * AUTH_DES flavor specific data from sec_data opaque data field.
79 * AUTH_KERB has the same structure.
80 */
81typedef struct des_clnt_data {
82 struct netbuf syncaddr; /* time sync addr */
83 struct knetconfig *knconf; /* knetconfig info that associated */
84 /* with the syncaddr. */
85 char *netname; /* server's netname */
86 int netnamelen; /* server's netname len */
87} dh_k4_clntdata_t;
88
89#ifdef _SYSCALL32_IMPL
90struct des_clnt_data32 {
91 struct netbuf32 syncaddr; /* time sync addr */
92 caddr32_t knconf; /* knetconfig info that associated */
93 /* with the syncaddr. */
94 caddr32_t netname; /* server's netname */
95 int32_t netnamelen; /* server's netname len */
96};
97#endif /* _SYSCALL32_IMPL */
98
99#ifdef KERBEROS
100/*
101 * flavor specific data to hold the data for AUTH_DES/AUTH_KERB(v4)
102 * in sec_data->data opaque field.
103 */
104typedef struct krb4_svc_data {
105 int window; /* window option value */
106} krb4_svcdata_t;
107
108typedef struct krb4_svc_data des_svcdata_t;
109#endif /* KERBEROS */
110
111/*
112 * authentication/security specific flags
113 */
114#define AUTH_F_RPCTIMESYNC 0x001 /* use RPC to do time sync */
115#define AUTH_F_TRYNONE 0x002 /* allow fall back to AUTH_NONE */
116
117
984263bc
MD
118/*
119 * Status returned from authentication check
120 */
121enum auth_stat {
122 AUTH_OK=0,
123 /*
124 * failed at remote end
125 */
126 AUTH_BADCRED=1, /* bogus credentials (seal broken) */
127 AUTH_REJECTEDCRED=2, /* client should begin new session */
128 AUTH_BADVERF=3, /* bogus verifier (seal broken) */
129 AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */
130 AUTH_TOOWEAK=5, /* rejected due to security reasons */
131 /*
132 * failed locally
133 */
134 AUTH_INVALIDRESP=6, /* bogus response verifier */
135 AUTH_FAILED=7 /* some unknown reason */
ce0e08e2
PA
136#ifdef KERBEROS
137 /*
138 * kerberos errors
139 */
140 ,
141 AUTH_KERB_GENERIC = 8, /* kerberos generic error */
142 AUTH_TIMEEXPIRE = 9, /* time of credential expired */
143 AUTH_TKT_FILE = 10, /* something wrong with ticket file */
144 AUTH_DECODE = 11, /* can't decode authenticator */
145 AUTH_NET_ADDR = 12 /* wrong net address in ticket */
146#endif /* KERBEROS */
984263bc
MD
147};
148
149union des_block {
150 struct {
ce0e08e2
PA
151 uint32_t high;
152 uint32_t low;
984263bc
MD
153 } key;
154 char c[8];
155};
156typedef union des_block des_block;
157__BEGIN_DECLS
5baeefc7 158bool_t xdr_des_block(XDR *, des_block *);
984263bc
MD
159__END_DECLS
160
161/*
162 * Authentication info. Opaque to client.
163 */
164struct opaque_auth {
165 enum_t oa_flavor; /* flavor of auth */
166 caddr_t oa_base; /* address of more auth stuff */
167 u_int oa_length; /* not to exceed MAX_AUTH_BYTES */
168};
984263bc
MD
169
170
171/*
172 * Auth handle, interface to client side authenticators.
173 */
ce0e08e2 174typedef struct __auth {
984263bc
MD
175 struct opaque_auth ah_cred;
176 struct opaque_auth ah_verf;
177 union des_block ah_key;
178 struct auth_ops {
ce0e08e2 179 void (*ah_nextverf) (struct __auth *);
984263bc 180 /* nextverf & serialize */
ce0e08e2 181 int (*ah_marshal) (struct __auth *, XDR *);
984263bc 182 /* validate verifier */
ce0e08e2 183 int (*ah_validate) (struct __auth *,
7c4af8e1 184 struct opaque_auth *);
984263bc 185 /* refresh credentials */
ce0e08e2 186 int (*ah_refresh) (struct __auth *, void *);
984263bc 187 /* destroy this structure */
ce0e08e2 188 void (*ah_destroy) (struct __auth *);
984263bc 189 } *ah_ops;
ce0e08e2 190 void *ah_private;
984263bc
MD
191} AUTH;
192
193
194/*
195 * Authentication ops.
196 * The ops and the auth handle provide the interface to the authenticators.
197 *
198 * AUTH *auth;
199 * XDR *xdrs;
200 * struct opaque_auth verf;
201 */
202#define AUTH_NEXTVERF(auth) \
203 ((*((auth)->ah_ops->ah_nextverf))(auth))
204#define auth_nextverf(auth) \
205 ((*((auth)->ah_ops->ah_nextverf))(auth))
206
207#define AUTH_MARSHALL(auth, xdrs) \
208 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
209#define auth_marshall(auth, xdrs) \
210 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
211
212#define AUTH_VALIDATE(auth, verfp) \
213 ((*((auth)->ah_ops->ah_validate))((auth), verfp))
214#define auth_validate(auth, verfp) \
215 ((*((auth)->ah_ops->ah_validate))((auth), verfp))
216
ce0e08e2
PA
217#define AUTH_REFRESH(auth, msg) \
218 ((*((auth)->ah_ops->ah_refresh))(auth, msg))
219#define auth_refresh(auth, msg) \
220 ((*((auth)->ah_ops->ah_refresh))(auth, msg))
984263bc
MD
221
222#define AUTH_DESTROY(auth) \
223 ((*((auth)->ah_ops->ah_destroy))(auth))
224#define auth_destroy(auth) \
225 ((*((auth)->ah_ops->ah_destroy))(auth))
226
227
ce0e08e2 228__BEGIN_DECLS
984263bc 229extern struct opaque_auth _null_auth;
ce0e08e2 230__END_DECLS
984263bc
MD
231
232/*
233 * These are the various implementations of client side authenticators.
234 */
235
236/*
ce0e08e2 237 * System style authentication
984263bc
MD
238 * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
239 * char *machname;
240 * int uid;
241 * int gid;
242 * int len;
243 * int *aup_gids;
244 */
245__BEGIN_DECLS
5baeefc7
JS
246AUTH *authunix_create(char *, int, int, int, int *);
247AUTH *authunix_create_default(void);
248AUTH *authnone_create(void);
984263bc 249__END_DECLS
984263bc
MD
250/*
251 * DES style authentication
ce0e08e2 252 * AUTH *authsecdes_create(servername, window, timehost, ckey)
984263bc
MD
253 * char *servername; - network name of server
254 * u_int window; - time to live
ce0e08e2 255 * const char *timehost; - optional hostname to sync with
984263bc
MD
256 * des_block *ckey; - optional conversation key to use
257 */
258__BEGIN_DECLS
5baeefc7 259AUTH *authdes_create(char *, u_int, struct sockaddr *, des_block *);
ce0e08e2
PA
260AUTH *authdes_seccreate(const char *, const u_int, const char *,
261 const des_block *);
984263bc
MD
262__END_DECLS
263
ce0e08e2
PA
264__BEGIN_DECLS
265bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
266__END_DECLS
267
268#define authsys_create(c,i1,i2,i3,ip) authunix_create((c),(i1),(i2),(i3),(ip))
269#define authsys_create_default() authunix_create_default()
270
984263bc
MD
271/*
272 * Netname manipulation routines.
273 */
274__BEGIN_DECLS
5baeefc7 275int getnetname(char *);
ce0e08e2
PA
276int host2netname(char *, const char *, const char *);
277int user2netname(char *, const uid_t, const char *);
278int netname2user(char *, uid_t *, gid_t *, int *, gid_t *);
279int netname2host(char *, char *, const int);
5baeefc7 280void passwd2des(char *, char *);
984263bc
MD
281__END_DECLS
282
283/*
ce0e08e2
PA
284 *
285 * These routines interface to the keyserv daemon
286 *
984263bc 287 */
984263bc 288__BEGIN_DECLS
5baeefc7 289int key_decryptsession(const char *, des_block *);
5baeefc7 290int key_encryptsession(const char *, des_block *);
5baeefc7
JS
291int key_gendes(des_block *);
292int key_setsecret(const char *);
293int key_secretkey_is_set(void);
984263bc
MD
294__END_DECLS
295
296/*
297 * Publickey routines.
298 */
299__BEGIN_DECLS
ce0e08e2
PA
300int getpublickey(const char *, char *);
301int getpublicandprivatekey(const char *, char *);
5baeefc7 302int getsecretkey(char *, char *, char *);
984263bc
MD
303__END_DECLS
304
ce0e08e2
PA
305#ifdef KERBEROS
306/*
307 * Kerberos style authentication
308 * AUTH *authkerb_seccreate(service, srv_inst, realm, window, timehost, status)
309 * const char *service; - service name
310 * const char *srv_inst; - server instance
311 * const char *realm; - server realm
312 * const u_int window; - time to live
313 * const char *timehost; - optional hostname to sync with
314 * int *status; - kerberos status returned
315 */
316__BEGIN_DECLS
317AUTH *authkerb_seccreate(const char *, const char *, const char *,
318 const u_int, const char *, int *);
319__END_DECLS
320
321/*
322 * Map a kerberos credential into a unix cred.
323 *
324 * authkerb_getucred(rqst, uid, gid, grouplen, groups)
325 * const struct svc_req *rqst; - request pointer
326 * uid_t *uid;
327 * gid_t *gid;
328 * short *grouplen;
329 * int *groups;
330 *
331 */
332__BEGIN_DECLS
333int authkerb_getucred(/* struct svc_req *, uid_t *, gid_t *,
334 short *, int * */);
335__END_DECLS
336#endif /* KERBEROS */
337
338__BEGIN_DECLS
339struct svc_req;
340struct rpc_msg;
341enum auth_stat _svcauth_null (struct svc_req *, struct rpc_msg *);
342enum auth_stat _svcauth_short (struct svc_req *, struct rpc_msg *);
343enum auth_stat _svcauth_unix (struct svc_req *, struct rpc_msg *);
344__END_DECLS
984263bc
MD
345
346#define AUTH_NONE 0 /* no authentication */
347#define AUTH_NULL 0 /* backward compatibility */
ce0e08e2
PA
348#define AUTH_SYS 1 /* unix style (uid, gids) */
349#define AUTH_UNIX AUTH_SYS
984263bc 350#define AUTH_SHORT 2 /* short hand unix style */
ce0e08e2
PA
351#define AUTH_DH 3 /* for Diffie-Hellman mechanism */
352#define AUTH_DES AUTH_DH /* for backward compatibility */
353#define AUTH_KERB 4 /* kerberos style */
984263bc
MD
354
355#endif /* !_RPC_AUTH_H */