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);
212 return __sync_add_and_fetch(&auth->ah_refcnt, 1);
218 return __sync_sub_and_fetch(&auth->ah_refcnt, 1);
224 * Authentication ops.
225 * The ops and the auth handle provide the interface to the authenticators.
229 * struct opaque_auth verf;
231 #define AUTH_NEXTVERF(auth) \
232 ((*((auth)->ah_ops->ah_nextverf))(auth))
233 #define auth_nextverf(auth) \
234 ((*((auth)->ah_ops->ah_nextverf))(auth))
236 #define AUTH_MARSHALL(auth, xdrs) \
237 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
238 #define auth_marshall(auth, xdrs) \
239 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
241 #define AUTH_VALIDATE(auth, verfp) \
242 ((*((auth)->ah_ops->ah_validate))((auth), verfp))
243 #define auth_validate(auth, verfp) \
244 ((*((auth)->ah_ops->ah_validate))((auth), verfp))
246 #define AUTH_REFRESH(auth, msg) \
247 ((*((auth)->ah_ops->ah_refresh))(auth, msg))
248 #define auth_refresh(auth, msg) \
249 ((*((auth)->ah_ops->ah_refresh))(auth, msg))
251 #define AUTH_DESTROY(auth) \
254 if ((refs = auth_put((auth))) == 0) \
255 ((*((auth)->ah_ops->ah_destroy))(auth));\
258 #define auth_destroy(auth) \
261 if ((refs = auth_put((auth))) == 0) \
262 ((*((auth)->ah_ops->ah_destroy))(auth));\
265 #define AUTH_WRAP(auth, xdrs, xfunc, xwhere) \
266 ((*((auth)->ah_ops->ah_wrap))(auth, xdrs, \
268 #define auth_wrap(auth, xdrs, xfunc, xwhere) \
269 ((*((auth)->ah_ops->ah_wrap))(auth, xdrs, \
272 #define AUTH_UNWRAP(auth, xdrs, xfunc, xwhere) \
273 ((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, \
275 #define auth_unwrap(auth, xdrs, xfunc, xwhere) \
276 ((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, \
281 extern struct opaque_auth _null_auth;
285 * Any style authentication. These routines can be used by any
286 * authentication style that does not use the wrap/unwrap functions.
288 int authany_wrap(void), authany_unwrap(void);
291 * These are the various implementations of client side authenticators.
295 * System style authentication
296 * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
304 extern AUTH *authunix_create(char *, uid_t, uid_t, int, uid_t *);
305 extern AUTH *authunix_create_default(void); /* takes no parameters */
306 extern AUTH *authnone_create(void); /* takes no parameters */
309 * DES style authentication
310 * AUTH *authsecdes_create(servername, window, timehost, ckey)
311 * char *servername; - network name of server
312 * u_int window; - time to live
313 * const char *timehost; - optional hostname to sync with
314 * des_block *ckey; - optional conversation key to use
317 extern AUTH *authdes_create (char *, u_int, struct sockaddr *, des_block *);
318 extern AUTH *authdes_seccreate (const char *, const u_int, const char *,
323 extern bool_t xdr_opaque_auth (XDR *, struct opaque_auth *);
326 #define authsys_create(c,i1,i2,i3,ip) authunix_create((c),(i1),(i2),(i3),(ip))
327 #define authsys_create_default() authunix_create_default()
330 * Netname manipulation routines.
333 extern int getnetname(char *);
334 extern int host2netname(char *, const char *, const char *);
335 extern int user2netname(char *, const uid_t, const char *);
336 extern int netname2user(char *, uid_t *, gid_t *, int *, gid_t *);
337 extern int netname2host(char *, char *, const int);
338 extern void passwd2des ( char *, char * );
343 * These routines interface to the keyserv daemon
347 extern int key_decryptsession(const char *, des_block *);
348 extern int key_encryptsession(const char *, des_block *);
349 extern int key_gendes(des_block *);
350 extern int key_setsecret(const char *);
351 extern int key_secretkey_is_set(void);
355 * Publickey routines.
358 extern int getpublickey (const char *, char *);
359 extern int getpublicandprivatekey (char *, char *);
360 extern int getsecretkey (char *, char *, char *);
365 * Kerberos style authentication
366 * AUTH *authkerb_seccreate(service, srv_inst, realm, window, timehost, status)
367 * const char *service; - service name
368 * const char *srv_inst; - server instance
369 * const char *realm; - server realm
370 * const u_int window; - time to live
371 * const char *timehost; - optional hostname to sync with
372 * int *status; - kerberos status returned
375 extern AUTH *authkerb_seccreate(const char *, const char *, const char *,
376 const u_int, const char *, int *);
380 * Map a kerberos credential into a unix cred.
382 * authkerb_getucred(rqst, uid, gid, grouplen, groups)
383 * const struct svc_req *rqst; - request pointer
391 extern int authkerb_getucred(/* struct svc_req *, uid_t *, gid_t *,
394 #endif /* KERBEROS */
399 enum auth_stat _svcauth_none (struct svc_req *, struct rpc_msg *);
400 enum auth_stat _svcauth_short (struct svc_req *, struct rpc_msg *);
401 enum auth_stat _svcauth_unix (struct svc_req *, struct rpc_msg *);
402 enum auth_stat _svcauth_gss (struct svc_req *, struct rpc_msg *, bool_t *);
405 #define AUTH_NONE 0 /* no authentication */
406 #define AUTH_NULL 0 /* backward compatibility */
407 #define AUTH_SYS 1 /* unix style (uid, gids) */
408 #define AUTH_UNIX AUTH_SYS
409 #define AUTH_SHORT 2 /* short hand unix style */
410 #define AUTH_DH 3 /* for Diffie-Hellman mechanism */
411 #define AUTH_DES AUTH_DH /* for backward compatibility */
412 #define AUTH_KERB 4 /* kerberos style */
413 #define RPCSEC_GSS 6 /* RPCSEC_GSS */
415 #endif /* !_TIRPC_AUTH_H */