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.21 2006/02/28 16:02:26 deischen 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
49 #include <rpc/clnt_stat.h>
50 #include <sys/cdefs.h>
51 #include <sys/socket.h>
53 #define MAX_AUTH_BYTES 400
54 #define MAXNETNAMELEN 255 /* maximum length of network user's name */
57 * Client side authentication/security data
60 typedef struct sec_data
{
61 u_int secmod
; /* security mode number e.g. in nfssec.conf */
62 u_int rpcflavor
; /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
63 int flags
; /* AUTH_F_xxx flags */
64 caddr_t data
; /* opaque data per flavor */
67 #ifdef _SYSCALL32_IMPL
69 uint32_t secmod
; /* security mode number e.g. in nfssec.conf */
70 uint32_t rpcflavor
; /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
71 int32_t flags
; /* AUTH_F_xxx flags */
72 caddr32_t data
; /* opaque data per flavor */
74 #endif /* _SYSCALL32_IMPL */
77 * AUTH_DES flavor specific data from sec_data opaque data field.
78 * AUTH_KERB has the same structure.
80 typedef struct des_clnt_data
{
81 struct netbuf syncaddr
; /* time sync addr */
82 struct knetconfig
*knconf
; /* knetconfig info that associated */
83 /* with the syncaddr. */
84 char *netname
; /* server's netname */
85 int netnamelen
; /* server's netname len */
88 #ifdef _SYSCALL32_IMPL
89 struct des_clnt_data32
{
90 struct netbuf32 syncaddr
; /* time sync addr */
91 caddr32_t knconf
; /* knetconfig info that associated */
92 /* with the syncaddr. */
93 caddr32_t netname
; /* server's netname */
94 int32_t netnamelen
; /* server's netname len */
96 #endif /* _SYSCALL32_IMPL */
100 * flavor specific data to hold the data for AUTH_DES/AUTH_KERB(v4)
101 * in sec_data->data opaque field.
103 typedef struct krb4_svc_data
{
104 int window
; /* window option value */
107 typedef struct krb4_svc_data des_svcdata_t
;
108 #endif /* KERBEROS */
111 * authentication/security specific flags
113 #define AUTH_F_RPCTIMESYNC 0x001 /* use RPC to do time sync */
114 #define AUTH_F_TRYNONE 0x002 /* allow fall back to AUTH_NONE */
118 * Status returned from authentication check
123 * failed at remote end
125 AUTH_BADCRED
=1, /* bogus credentials (seal broken) */
126 AUTH_REJECTEDCRED
=2, /* client should begin new session */
127 AUTH_BADVERF
=3, /* bogus verifier (seal broken) */
128 AUTH_REJECTEDVERF
=4, /* verifier expired or was replayed */
129 AUTH_TOOWEAK
=5, /* rejected due to security reasons */
133 AUTH_INVALIDRESP
=6, /* bogus response verifier */
134 AUTH_FAILED
=7 /* some unknown reason */
140 AUTH_KERB_GENERIC
= 8, /* kerberos generic error */
141 AUTH_TIMEEXPIRE
= 9, /* time of credential expired */
142 AUTH_TKT_FILE
= 10, /* something wrong with ticket file */
143 AUTH_DECODE
= 11, /* can't decode authenticator */
144 AUTH_NET_ADDR
= 12 /* wrong net address in ticket */
145 #endif /* KERBEROS */
155 typedef union des_block des_block
;
157 bool_t
xdr_des_block(XDR
*, des_block
*);
161 * Authentication info. Opaque to client.
164 enum_t oa_flavor
; /* flavor of auth */
165 caddr_t oa_base
; /* address of more auth stuff */
166 u_int oa_length
; /* not to exceed MAX_AUTH_BYTES */
171 * Auth handle, interface to client side authenticators.
173 typedef struct __auth
{
174 struct opaque_auth ah_cred
;
175 struct opaque_auth ah_verf
;
176 union des_block ah_key
;
178 void (*ah_nextverf
) (struct __auth
*);
179 /* nextverf & serialize */
180 int (*ah_marshal
) (struct __auth
*, XDR
*);
181 /* validate verifier */
182 int (*ah_validate
) (struct __auth
*,
183 struct opaque_auth
*);
184 /* refresh credentials */
185 int (*ah_refresh
) (struct __auth
*, void *);
186 /* destroy this structure */
187 void (*ah_destroy
) (struct __auth
*);
194 * Authentication ops.
195 * The ops and the auth handle provide the interface to the authenticators.
199 * struct opaque_auth verf;
201 #define AUTH_NEXTVERF(auth) \
202 ((*((auth)->ah_ops->ah_nextverf))(auth))
203 #define auth_nextverf(auth) \
204 ((*((auth)->ah_ops->ah_nextverf))(auth))
206 #define AUTH_MARSHALL(auth, xdrs) \
207 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
208 #define auth_marshall(auth, xdrs) \
209 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
211 #define AUTH_VALIDATE(auth, verfp) \
212 ((*((auth)->ah_ops->ah_validate))((auth), verfp))
213 #define auth_validate(auth, verfp) \
214 ((*((auth)->ah_ops->ah_validate))((auth), verfp))
216 #define AUTH_REFRESH(auth, msg) \
217 ((*((auth)->ah_ops->ah_refresh))(auth, msg))
218 #define auth_refresh(auth, msg) \
219 ((*((auth)->ah_ops->ah_refresh))(auth, msg))
221 #define AUTH_DESTROY(auth) \
222 ((*((auth)->ah_ops->ah_destroy))(auth))
223 #define auth_destroy(auth) \
224 ((*((auth)->ah_ops->ah_destroy))(auth))
228 extern struct opaque_auth _null_auth
;
232 * These are the various implementations of client side authenticators.
236 * System style authentication
237 * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
245 AUTH
*authunix_create(char *, int, int, int, int *);
246 AUTH
*authunix_create_default(void);
247 AUTH
*authnone_create(void);
250 * DES style authentication
251 * AUTH *authsecdes_create(servername, window, timehost, ckey)
252 * char *servername; - network name of server
253 * u_int window; - time to live
254 * const char *timehost; - optional hostname to sync with
255 * des_block *ckey; - optional conversation key to use
258 AUTH
*authdes_create(char *, u_int
, struct sockaddr
*, des_block
*);
259 AUTH
*authdes_seccreate(const char *, const u_int
, const char *,
264 bool_t
xdr_opaque_auth(XDR
*, struct opaque_auth
*);
267 #define authsys_create(c,i1,i2,i3,ip) authunix_create((c),(i1),(i2),(i3),(ip))
268 #define authsys_create_default() authunix_create_default()
271 * Netname manipulation routines.
274 int getnetname(char *);
275 int host2netname(char *, const char *, const char *);
276 int user2netname(char *, const uid_t
, const char *);
277 int netname2user(char *, uid_t
*, gid_t
*, int *, gid_t
*);
278 int netname2host(char *, char *, const int);
279 void passwd2des(char *, char *);
284 * These routines interface to the keyserv daemon
288 int key_decryptsession(const char *, des_block
*);
289 int key_encryptsession(const char *, des_block
*);
290 int key_gendes(des_block
*);
291 int key_setsecret(const char *);
292 int key_secretkey_is_set(void);
296 * Publickey routines.
299 int getpublickey(const char *, char *);
300 int getpublicandprivatekey(const char *, char *);
301 int getsecretkey(char *, char *, char *);
306 * Kerberos style authentication
307 * AUTH *authkerb_seccreate(service, srv_inst, realm, window, timehost, status)
308 * const char *service; - service name
309 * const char *srv_inst; - server instance
310 * const char *realm; - server realm
311 * const u_int window; - time to live
312 * const char *timehost; - optional hostname to sync with
313 * int *status; - kerberos status returned
316 AUTH
*authkerb_seccreate(const char *, const char *, const char *,
317 const u_int
, const char *, int *);
321 * Map a kerberos credential into a unix cred.
323 * authkerb_getucred(rqst, uid, gid, grouplen, groups)
324 * const struct svc_req *rqst; - request pointer
332 int authkerb_getucred(/* struct svc_req *, uid_t *, gid_t *,
335 #endif /* KERBEROS */
340 enum auth_stat
_svcauth_null (struct svc_req
*, struct rpc_msg
*);
341 enum auth_stat
_svcauth_short (struct svc_req
*, struct rpc_msg
*);
342 enum auth_stat
_svcauth_unix (struct svc_req
*, struct rpc_msg
*);
345 #define AUTH_NONE 0 /* no authentication */
346 #define AUTH_NULL 0 /* backward compatibility */
347 #define AUTH_SYS 1 /* unix style (uid, gids) */
348 #define AUTH_UNIX AUTH_SYS
349 #define AUTH_SHORT 2 /* short hand unix style */
350 #define AUTH_DH 3 /* for Diffie-Hellman mechanism */
351 #define AUTH_DES AUTH_DH /* for backward compatibility */
352 #define AUTH_KERB 4 /* kerberos style */
354 #endif /* !_RPC_AUTH_H */