1 /* $NetBSD: auth.h,v 1.15 2000/06/02 22:57:55 fvdl Exp $ */
4 * Copyright (c) 2009, Sun Microsystems, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * - Neither the name of Sun Microsystems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * from: @(#)auth.h 1.17 88/02/08 SMI
31 * from: @(#)auth.h 2.3 88/08/07 4.0 RPCSRC
32 * from: @(#)auth.h 1.43 98/02/02 SMI
33 * $FreeBSD: src/include/rpc/auth.h,v 1.20 2003/01/01 18:48:42 schweikh Exp $
37 * auth.h, Authentication interface.
39 * Copyright (C) 1984, Sun Microsystems, Inc.
41 * The data structures are completely opaque to the client. The client
42 * is required to pass an AUTH * to routines that create rpc
50 #include <rpc/clnt_stat.h>
51 #include <sys/cdefs.h>
52 #include <sys/socket.h>
53 #include <sys/types.h>
56 #define MAX_AUTH_BYTES 400
57 #define MAXNETNAMELEN 255 /* maximum length of network user's name */
60 * Client side authentication/security data
63 typedef struct sec_data {
64 u_int secmod; /* security mode number e.g. in nfssec.conf */
65 u_int rpcflavor; /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
66 int flags; /* AUTH_F_xxx flags */
67 caddr_t data; /* opaque data per flavor */
70 #ifdef _SYSCALL32_IMPL
72 uint32_t secmod; /* security mode number e.g. in nfssec.conf */
73 uint32_t rpcflavor; /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
74 int32_t flags; /* AUTH_F_xxx flags */
75 caddr32_t data; /* opaque data per flavor */
77 #endif /* _SYSCALL32_IMPL */
80 * AUTH_DES flavor specific data from sec_data opaque data field.
81 * AUTH_KERB has the same structure.
83 typedef struct des_clnt_data {
84 struct netbuf syncaddr; /* time sync addr */
85 struct knetconfig *knconf; /* knetconfig info that associated */
86 /* with the syncaddr. */
87 char *netname; /* server's netname */
88 int netnamelen; /* server's netname len */
91 #ifdef _SYSCALL32_IMPL
92 struct des_clnt_data32 {
93 struct netbuf32 syncaddr; /* time sync addr */
94 caddr32_t knconf; /* knetconfig info that associated */
95 /* with the syncaddr. */
96 caddr32_t netname; /* server's netname */
97 int32_t netnamelen; /* server's netname len */
99 #endif /* _SYSCALL32_IMPL */
103 * flavor specific data to hold the data for AUTH_DES/AUTH_KERB(v4)
104 * in sec_data->data opaque field.
106 typedef struct krb4_svc_data {
107 int window; /* window option value */
110 typedef struct krb4_svc_data des_svcdata_t;
111 #endif /* KERBEROS */
114 * authentication/security specific flags
116 #define AUTH_F_RPCTIMESYNC 0x001 /* use RPC to do time sync */
117 #define AUTH_F_TRYNONE 0x002 /* allow fall back to AUTH_NONE */
121 * Status returned from authentication check
126 * failed at remote end
128 AUTH_BADCRED=1, /* bogus credentials (seal broken) */
129 AUTH_REJECTEDCRED=2, /* client should begin new session */
130 AUTH_BADVERF=3, /* bogus verifier (seal broken) */
131 AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */
132 AUTH_TOOWEAK=5, /* rejected due to security reasons */
136 AUTH_INVALIDRESP=6, /* bogus response verifier */
137 AUTH_FAILED=7, /* some unknown reason */
142 AUTH_KERB_GENERIC = 8, /* kerberos generic error */
143 AUTH_TIMEEXPIRE = 9, /* time of credential expired */
144 AUTH_TKT_FILE = 10, /* something wrong with ticket file */
145 AUTH_DECODE = 11, /* can't decode authenticator */
146 AUTH_NET_ADDR = 12, /* wrong net address in ticket */
147 #endif /* KERBEROS */
152 RPCSEC_GSS_CREDPROBLEM = 13,
153 RPCSEC_GSS_CTXPROBLEM = 14
157 typedef u_int32_t u_int32; /* 32-bit unsigned integers */
166 typedef union des_block des_block;
168 extern bool_t xdr_des_block(XDR *, des_block *);
172 * Authentication info. Opaque to client.
175 enum_t oa_flavor; /* flavor of auth */
176 caddr_t oa_base; /* address of more auth stuff */
177 u_int oa_length; /* not to exceed MAX_AUTH_BYTES */
182 * Auth handle, interface to client side authenticators.
184 typedef struct __auth {
185 struct opaque_auth ah_cred;
186 struct opaque_auth ah_verf;
187 union des_block ah_key;
189 void (*ah_nextverf) (struct __auth *);
190 /* nextverf & serialize */
191 int (*ah_marshal) (struct __auth *, XDR *);
192 /* validate verifier */
193 int (*ah_validate) (struct __auth *,
194 struct opaque_auth *);
195 /* refresh credentials */
196 int (*ah_refresh) (struct __auth *, void *);
197 /* destroy this structure */
198 void (*ah_destroy) (struct __auth *);
199 /* encode data for wire */
200 int (*ah_wrap) (struct __auth *, XDR *, xdrproc_t, caddr_t);
201 /* decode data for wire */
202 int (*ah_unwrap) (struct __auth *, XDR *, xdrproc_t, caddr_t);
210 * Authentication ops.
211 * The ops and the auth handle provide the interface to the authenticators.
215 * struct opaque_auth verf;
217 #define AUTH_NEXTVERF(auth) \
218 ((*((auth)->ah_ops->ah_nextverf))(auth))
219 #define auth_nextverf(auth) \
220 ((*((auth)->ah_ops->ah_nextverf))(auth))
222 #define AUTH_MARSHALL(auth, xdrs) \
223 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
224 #define auth_marshall(auth, xdrs) \
225 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
227 #define AUTH_VALIDATE(auth, verfp) \
228 ((*((auth)->ah_ops->ah_validate))((auth), verfp))
229 #define auth_validate(auth, verfp) \
230 ((*((auth)->ah_ops->ah_validate))((auth), verfp))
232 #define AUTH_REFRESH(auth, msg) \
233 ((*((auth)->ah_ops->ah_refresh))(auth, msg))
234 #define auth_refresh(auth, msg) \
235 ((*((auth)->ah_ops->ah_refresh))(auth, msg))
237 #define AUTH_DESTROY(auth) \
238 ((*((auth)->ah_ops->ah_destroy))(auth))
239 #define auth_destroy(auth) \
240 ((*((auth)->ah_ops->ah_destroy))(auth))
242 #define AUTH_WRAP(auth, xdrs, xfunc, xwhere) \
243 ((*((auth)->ah_ops->ah_wrap))(auth, xdrs, \
245 #define auth_wrap(auth, xdrs, xfunc, xwhere) \
246 ((*((auth)->ah_ops->ah_wrap))(auth, xdrs, \
249 #define AUTH_UNWRAP(auth, xdrs, xfunc, xwhere) \
250 ((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, \
252 #define auth_unwrap(auth, xdrs, xfunc, xwhere) \
253 ((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, \
258 extern struct opaque_auth _null_auth;
262 * Any style authentication. These routines can be used by any
263 * authentication style that does not use the wrap/unwrap functions.
265 int authany_wrap(void), authany_unwrap(void);
268 * These are the various implementations of client side authenticators.
272 * System style authentication
273 * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
281 extern AUTH *authunix_create(char *, uid_t, uid_t, int, uid_t *);
282 extern AUTH *authunix_create_default(void); /* takes no parameters */
283 extern AUTH *authnone_create(void); /* takes no parameters */
286 * DES style authentication
287 * AUTH *authsecdes_create(servername, window, timehost, ckey)
288 * char *servername; - network name of server
289 * u_int window; - time to live
290 * const char *timehost; - optional hostname to sync with
291 * des_block *ckey; - optional conversation key to use
294 extern AUTH *authdes_create (char *, u_int, struct sockaddr *, des_block *);
295 extern AUTH *authdes_seccreate (const char *, const u_int, const char *,
300 extern bool_t xdr_opaque_auth (XDR *, struct opaque_auth *);
303 #define authsys_create(c,i1,i2,i3,ip) authunix_create((c),(i1),(i2),(i3),(ip))
304 #define authsys_create_default() authunix_create_default()
307 * Netname manipulation routines.
310 extern int getnetname(char *);
311 extern int host2netname(char *, const char *, const char *);
312 extern int user2netname(char *, const uid_t, const char *);
313 extern int netname2user(char *, uid_t *, gid_t *, int *, gid_t *);
314 extern int netname2host(char *, char *, const int);
315 extern void passwd2des ( char *, char * );
320 * These routines interface to the keyserv daemon
324 extern int key_decryptsession(const char *, des_block *);
325 extern int key_encryptsession(const char *, des_block *);
326 extern int key_gendes(des_block *);
327 extern int key_setsecret(const char *);
328 extern int key_secretkey_is_set(void);
332 * Publickey routines.
335 extern int getpublickey (const char *, char *);
336 extern int getpublicandprivatekey (char *, char *);
337 extern int getsecretkey (char *, char *, char *);
342 * Kerberos style authentication
343 * AUTH *authkerb_seccreate(service, srv_inst, realm, window, timehost, status)
344 * const char *service; - service name
345 * const char *srv_inst; - server instance
346 * const char *realm; - server realm
347 * const u_int window; - time to live
348 * const char *timehost; - optional hostname to sync with
349 * int *status; - kerberos status returned
352 extern AUTH *authkerb_seccreate(const char *, const char *, const char *,
353 const u_int, const char *, int *);
357 * Map a kerberos credential into a unix cred.
359 * authkerb_getucred(rqst, uid, gid, grouplen, groups)
360 * const struct svc_req *rqst; - request pointer
368 extern int authkerb_getucred(/* struct svc_req *, uid_t *, gid_t *,
371 #endif /* KERBEROS */
376 enum auth_stat _svcauth_null (struct svc_req *, struct rpc_msg *);
377 enum auth_stat _svcauth_short (struct svc_req *, struct rpc_msg *);
378 enum auth_stat _svcauth_unix (struct svc_req *, struct rpc_msg *);
381 #define AUTH_NONE 0 /* no authentication */
382 #define AUTH_NULL 0 /* backward compatibility */
383 #define AUTH_SYS 1 /* unix style (uid, gids) */
384 #define AUTH_UNIX AUTH_SYS
385 #define AUTH_SHORT 2 /* short hand unix style */
386 #define AUTH_DH 3 /* for Diffie-Hellman mechanism */
387 #define AUTH_DES AUTH_DH /* for backward compatibility */
388 #define AUTH_KERB 4 /* kerberos style */
389 #define RPCSEC_GSS 6 /* RPCSEC_GSS */
391 #endif /* !_TIRPC_AUTH_H */