1 /* $NetBSD: auth.h,v 1.15 2000/06/02 22:57:55 fvdl Exp $ */
4 * SPDX-License-Identifier: BSD-3-Clause
6 * Copyright (c) 2009, Sun Microsystems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * - Neither the name of Sun Microsystems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * auth.h, Authentication interface.
36 * Copyright (C) 1984, Sun Microsystems, Inc.
38 * The data structures are completely opaque to the client. The client
39 * is required to pass an AUTH * to routines that create rpc
46 #include <rpc/clnt_stat.h>
47 #include <sys/cdefs.h>
48 #include <sys/socket.h>
50 #define MAX_AUTH_BYTES 400
51 #define MAXNETNAMELEN 255 /* maximum length of network user's name */
54 * Client side authentication/security data
57 typedef struct sec_data {
58 u_int secmod; /* security mode number e.g. in nfssec.conf */
59 u_int rpcflavor; /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
60 int flags; /* AUTH_F_xxx flags */
61 caddr_t data; /* opaque data per flavor */
64 #ifdef _SYSCALL32_IMPL
66 uint32_t secmod; /* security mode number e.g. in nfssec.conf */
67 uint32_t rpcflavor; /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
68 int32_t flags; /* AUTH_F_xxx flags */
69 caddr32_t data; /* opaque data per flavor */
71 #endif /* _SYSCALL32_IMPL */
74 * AUTH_DES flavor specific data from sec_data opaque data field.
75 * AUTH_KERB has the same structure.
77 typedef struct des_clnt_data {
78 struct netbuf syncaddr; /* time sync addr */
79 struct knetconfig *knconf; /* knetconfig info that associated */
80 /* with the syncaddr. */
81 char *netname; /* server's netname */
82 int netnamelen; /* server's netname len */
85 #ifdef _SYSCALL32_IMPL
86 struct des_clnt_data32 {
87 struct netbuf32 syncaddr; /* time sync addr */
88 caddr32_t knconf; /* knetconfig info that associated */
89 /* with the syncaddr. */
90 caddr32_t netname; /* server's netname */
91 int32_t netnamelen; /* server's netname len */
93 #endif /* _SYSCALL32_IMPL */
97 * flavor specific data to hold the data for AUTH_DES/AUTH_KERB(v4)
98 * in sec_data->data opaque field.
100 typedef struct krb4_svc_data {
101 int window; /* window option value */
104 typedef struct krb4_svc_data des_svcdata_t;
105 #endif /* KERBEROS */
108 * authentication/security specific flags
110 #define AUTH_F_RPCTIMESYNC 0x001 /* use RPC to do time sync */
111 #define AUTH_F_TRYNONE 0x002 /* allow fall back to AUTH_NONE */
115 * Status returned from authentication check
120 * failed at remote end
122 AUTH_BADCRED=1, /* bogus credentials (seal broken) */
123 AUTH_REJECTEDCRED=2, /* client should begin new session */
124 AUTH_BADVERF=3, /* bogus verifier (seal broken) */
125 AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */
126 AUTH_TOOWEAK=5, /* rejected due to security reasons */
130 AUTH_INVALIDRESP=6, /* bogus response verifier */
131 AUTH_FAILED=7, /* some unknown reason */
136 AUTH_KERB_GENERIC = 8, /* kerberos generic error */
137 AUTH_TIMEEXPIRE = 9, /* time of credential expired */
138 AUTH_TKT_FILE = 10, /* something wrong with ticket file */
139 AUTH_DECODE = 11, /* can't decode authenticator */
140 AUTH_NET_ADDR = 12, /* wrong net address in ticket */
141 #endif /* KERBEROS */
145 RPCSEC_GSS_CREDPROBLEM = 13,
146 RPCSEC_GSS_CTXPROBLEM = 14,
147 /* Also used by RPCSEC_TLS for the same purpose */
148 RPCSEC_GSS_NODISPATCH = 0x8000000
158 typedef union des_block des_block;
160 extern bool_t xdr_des_block(XDR *, des_block *);
164 * Authentication info. Opaque to client.
167 enum_t oa_flavor; /* flavor of auth */
168 caddr_t oa_base; /* address of more auth stuff */
169 u_int oa_length; /* not to exceed MAX_AUTH_BYTES */
174 * Auth handle, interface to client side authenticators.
177 typedef struct __auth {
178 struct opaque_auth ah_cred;
179 struct opaque_auth ah_verf;
180 union des_block ah_key;
181 const struct auth_ops {
182 void (*ah_nextverf) (struct __auth *);
183 /* nextverf & serialize */
184 int (*ah_marshal) (struct __auth *, uint32_t, XDR *,
186 /* validate verifier */
187 int (*ah_validate) (struct __auth *, uint32_t,
188 struct opaque_auth *, struct mbuf **);
189 /* refresh credentials */
190 int (*ah_refresh) (struct __auth *, void *);
191 /* destroy this structure */
192 void (*ah_destroy) (struct __auth *);
199 * Authentication ops.
200 * The ops and the auth handle provide the interface to the authenticators.
204 * struct opaque_auth verf;
206 #define AUTH_NEXTVERF(auth) \
207 ((*((auth)->ah_ops->ah_nextverf))(auth))
209 #define AUTH_MARSHALL(auth, xid, xdrs, args) \
210 ((*((auth)->ah_ops->ah_marshal))(auth, xid, xdrs, args))
212 #define AUTH_VALIDATE(auth, xid, verfp, resultsp) \
213 ((*((auth)->ah_ops->ah_validate))((auth), xid, verfp, resultsp))
215 #define AUTH_REFRESH(auth, msg) \
216 ((*((auth)->ah_ops->ah_refresh))(auth, msg))
218 #define AUTH_DESTROY(auth) \
219 ((*((auth)->ah_ops->ah_destroy))(auth))
222 extern struct opaque_auth _null_auth;
226 * These are the various implementations of client side authenticators.
230 * System style authentication
231 * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
241 extern AUTH *authunix_create(struct ucred *);
243 extern AUTH *authunix_create(char *, u_int, u_int, int, u_int *);
244 extern AUTH *authunix_create_default(void); /* takes no parameters */
246 extern AUTH *authnone_create(void); /* takes no parameters */
247 extern AUTH *authtls_create(void); /* takes no parameters */
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 extern AUTH *authdes_create (char *, u_int, struct sockaddr *, des_block *);
259 extern AUTH *authdes_seccreate (const char *, const u_int, const char *,
264 extern 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 extern int getnetname(char *);
275 extern int host2netname(char *, const char *, const char *);
276 extern int user2netname(char *, const uid_t, const char *);
277 extern int netname2user(char *, uid_t *, gid_t *, int *, gid_t *);
278 extern int netname2host(char *, char *, const int);
279 extern void passwd2des ( char *, char * );
284 * These routines interface to the keyserv daemon
288 extern int key_decryptsession(const char *, des_block *);
289 extern int key_encryptsession(const char *, des_block *);
290 extern int key_gendes(des_block *);
291 extern int key_setsecret(const char *);
292 extern int key_secretkey_is_set(void);
296 * Publickey routines.
299 extern int getpublickey (const char *, char *);
300 extern int getpublicandprivatekey (const char *, char *);
301 extern 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 extern 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 extern 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 *);
343 enum auth_stat _svcauth_rpcsec_tls (struct svc_req *, struct rpc_msg *);
346 #define AUTH_NONE 0 /* no authentication */
347 #define AUTH_NULL 0 /* backward compatibility */
348 #define AUTH_SYS 1 /* unix style (uid, gids) */
349 #define AUTH_UNIX AUTH_SYS
350 #define AUTH_SHORT 2 /* short hand unix style */
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 */
354 #define RPCSEC_GSS 6 /* RPCSEC_GSS */
355 #define AUTH_TLS 7 /* Initiate RPC-over-TLS */
358 * Pseudo auth flavors for RPCSEC_GSS.
360 #define RPCSEC_GSS_KRB5 390003
361 #define RPCSEC_GSS_KRB5I 390004
362 #define RPCSEC_GSS_KRB5P 390005
364 #endif /* !_RPC_AUTH_H */