auth.h revision 331722
1/*	$NetBSD: auth.h,v 1.15 2000/06/02 22:57:55 fvdl Exp $	*/
2
3/*-
4 * Copyright (c) 2009, Sun Microsystems, Inc.
5 * All rights reserved.
6 *
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.
17 *
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.
29 *
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: stable/11/include/rpc/auth.h 331722 2018-03-29 02:50:57Z eadler $
34 */
35
36/*
37 * auth.h, Authentication interface.
38 *
39 * Copyright (C) 1984, Sun Microsystems, Inc.
40 *
41 * The data structures are completely opaque to the client.  The client
42 * is required to pass an AUTH * to routines that create rpc
43 * "sessions".
44 */
45
46#ifndef _RPC_AUTH_H
47#define _RPC_AUTH_H
48#include <rpc/xdr.h>
49#include <rpc/clnt_stat.h>
50#include <sys/cdefs.h>
51#include <sys/socket.h>
52
53#define MAX_AUTH_BYTES	400
54#define MAXNETNAMELEN	255	/* maximum length of network user's name */
55
56/*
57 *  Client side authentication/security data
58 */
59
60typedef 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 */
65} sec_data_t;
66
67#ifdef _SYSCALL32_IMPL
68struct sec_data32 {
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 */
73};
74#endif /* _SYSCALL32_IMPL */
75
76/*
77 * AUTH_DES flavor specific data from sec_data opaque data field.
78 * AUTH_KERB has the same structure.
79 */
80typedef 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 */
86} dh_k4_clntdata_t;
87
88#ifdef _SYSCALL32_IMPL
89struct 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 */
95};
96#endif /* _SYSCALL32_IMPL */
97
98#ifdef KERBEROS
99/*
100 * flavor specific data to hold the data for AUTH_DES/AUTH_KERB(v4)
101 * in sec_data->data opaque field.
102 */
103typedef struct krb4_svc_data {
104	int		window;		/* window option value */
105} krb4_svcdata_t;
106
107typedef struct krb4_svc_data	des_svcdata_t;
108#endif /* KERBEROS */
109
110/*
111 * authentication/security specific flags
112 */
113#define AUTH_F_RPCTIMESYNC	0x001	/* use RPC to do time sync */
114#define AUTH_F_TRYNONE		0x002	/* allow fall back to AUTH_NONE */
115
116
117/*
118 * Status returned from authentication check
119 */
120enum auth_stat {
121	AUTH_OK=0,
122	/*
123	 * failed at remote end
124	 */
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 */
130	/*
131	 * failed locally
132	*/
133	AUTH_INVALIDRESP=6,		/* bogus response verifier */
134	AUTH_FAILED=7,			/* some unknown reason */
135#ifdef KERBEROS
136	/*
137	 * kerberos errors
138	 */
139	,
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 */
146	/*
147	 * RPCSEC_GSS errors
148	 */
149	RPCSEC_GSS_CREDPROBLEM = 13,
150	RPCSEC_GSS_CTXPROBLEM = 14,
151	RPCSEC_GSS_NODISPATCH = 0x8000000
152};
153
154union des_block {
155	struct {
156		uint32_t high;
157		uint32_t low;
158	} key;
159	char c[8];
160};
161typedef union des_block des_block;
162__BEGIN_DECLS
163extern bool_t xdr_des_block(XDR *, des_block *);
164__END_DECLS
165
166/*
167 * Authentication info.  Opaque to client.
168 */
169struct opaque_auth {
170	enum_t	oa_flavor;		/* flavor of auth */
171	caddr_t	oa_base;		/* address of more auth stuff */
172	u_int	oa_length;		/* not to exceed MAX_AUTH_BYTES */
173};
174
175
176/*
177 * Auth handle, interface to client side authenticators.
178 */
179typedef struct __auth {
180	struct	opaque_auth	ah_cred;
181	struct	opaque_auth	ah_verf;
182	union	des_block	ah_key;
183	struct auth_ops {
184		void	(*ah_nextverf) (struct __auth *);
185		/* nextverf & serialize */
186		int	(*ah_marshal) (struct __auth *, XDR *);
187		/* validate verifier */
188		int	(*ah_validate) (struct __auth *,
189			    struct opaque_auth *);
190		/* refresh credentials */
191		int	(*ah_refresh) (struct __auth *, void *);
192		/* destroy this structure */
193		void	(*ah_destroy) (struct __auth *);
194	} *ah_ops;
195	void *ah_private;
196} AUTH;
197
198
199/*
200 * Authentication ops.
201 * The ops and the auth handle provide the interface to the authenticators.
202 *
203 * AUTH	*auth;
204 * XDR	*xdrs;
205 * struct opaque_auth verf;
206 */
207#define AUTH_NEXTVERF(auth)		\
208		((*((auth)->ah_ops->ah_nextverf))(auth))
209#define auth_nextverf(auth)		\
210		((*((auth)->ah_ops->ah_nextverf))(auth))
211
212#define AUTH_MARSHALL(auth, xdrs)	\
213		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
214#define auth_marshall(auth, xdrs)	\
215		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
216
217#define AUTH_VALIDATE(auth, verfp)	\
218		((*((auth)->ah_ops->ah_validate))((auth), verfp))
219#define auth_validate(auth, verfp)	\
220		((*((auth)->ah_ops->ah_validate))((auth), verfp))
221
222#define AUTH_REFRESH(auth, msg)		\
223		((*((auth)->ah_ops->ah_refresh))(auth, msg))
224#define auth_refresh(auth, msg)		\
225		((*((auth)->ah_ops->ah_refresh))(auth, msg))
226
227#define AUTH_DESTROY(auth)		\
228		((*((auth)->ah_ops->ah_destroy))(auth))
229#define auth_destroy(auth)		\
230		((*((auth)->ah_ops->ah_destroy))(auth))
231
232
233__BEGIN_DECLS
234extern struct opaque_auth _null_auth;
235__END_DECLS
236
237/*
238 * These are the various implementations of client side authenticators.
239 */
240
241/*
242 * System style authentication
243 * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
244 *	char *machname;
245 *	u_int uid;
246 *	u_int gid;
247 *	int len;
248 *	u_int *aup_gids;
249 */
250__BEGIN_DECLS
251extern AUTH *authunix_create(char *, u_int, u_int, int, u_int *);
252extern AUTH *authunix_create_default(void);	/* takes no parameters */
253extern AUTH *authnone_create(void);		/* takes no parameters */
254__END_DECLS
255/*
256 * DES style authentication
257 * AUTH *authsecdes_create(servername, window, timehost, ckey)
258 * 	char *servername;		- network name of server
259 *	u_int window;			- time to live
260 * 	const char *timehost;			- optional hostname to sync with
261 * 	des_block *ckey;		- optional conversation key to use
262 */
263__BEGIN_DECLS
264extern AUTH *authdes_create (char *, u_int, struct sockaddr *, des_block *);
265extern AUTH *authdes_seccreate (const char *, const u_int, const  char *,
266    const  des_block *);
267__END_DECLS
268
269__BEGIN_DECLS
270extern bool_t xdr_opaque_auth		(XDR *, struct opaque_auth *);
271__END_DECLS
272
273#define authsys_create(c,i1,i2,i3,ip) authunix_create((c),(i1),(i2),(i3),(ip))
274#define authsys_create_default() authunix_create_default()
275
276/*
277 * Netname manipulation routines.
278 */
279__BEGIN_DECLS
280extern int getnetname(char *);
281extern int host2netname(char *, const char *, const char *);
282extern int user2netname(char *, const uid_t, const char *);
283extern int netname2user(char *, uid_t *, gid_t *, int *, gid_t *);
284extern int netname2host(char *, char *, const int);
285extern void passwd2des ( char *, char * );
286__END_DECLS
287
288/*
289 *
290 * These routines interface to the keyserv daemon
291 *
292 */
293__BEGIN_DECLS
294extern int key_decryptsession(const char *, des_block *);
295extern int key_encryptsession(const char *, des_block *);
296extern int key_gendes(des_block *);
297extern int key_setsecret(const char *);
298extern int key_secretkey_is_set(void);
299__END_DECLS
300
301/*
302 * Publickey routines.
303 */
304__BEGIN_DECLS
305extern int getpublickey (const char *, char *);
306extern int getpublicandprivatekey (const char *, char *);
307extern int getsecretkey (char *, char *, char *);
308__END_DECLS
309
310#ifdef KERBEROS
311/*
312 * Kerberos style authentication
313 * AUTH *authkerb_seccreate(service, srv_inst, realm, window, timehost, status)
314 *	const char *service;			- service name
315 *	const char *srv_inst;			- server instance
316 *	const char *realm;			- server realm
317 *	const u_int window;			- time to live
318 *	const char *timehost;			- optional hostname to sync with
319 *	int *status;				- kerberos status returned
320 */
321__BEGIN_DECLS
322extern AUTH	*authkerb_seccreate(const char *, const char *, const  char *,
323		    const u_int, const char *, int *);
324__END_DECLS
325
326/*
327 * Map a kerberos credential into a unix cred.
328 *
329 *	authkerb_getucred(rqst, uid, gid, grouplen, groups)
330 *	const struct svc_req *rqst;		- request pointer
331 *	uid_t *uid;
332 *	gid_t *gid;
333 *	short *grouplen;
334 *	int *groups;
335 *
336 */
337__BEGIN_DECLS
338extern int	authkerb_getucred(/* struct svc_req *, uid_t *, gid_t *,
339		    short *, int * */);
340__END_DECLS
341#endif /* KERBEROS */
342
343__BEGIN_DECLS
344struct svc_req;
345struct rpc_msg;
346enum auth_stat _svcauth_null (struct svc_req *, struct rpc_msg *);
347enum auth_stat _svcauth_short (struct svc_req *, struct rpc_msg *);
348enum auth_stat _svcauth_unix (struct svc_req *, struct rpc_msg *);
349__END_DECLS
350
351#define AUTH_NONE	0		/* no authentication */
352#define	AUTH_NULL	0		/* backward compatibility */
353#define	AUTH_SYS	1		/* unix style (uid, gids) */
354#define AUTH_UNIX	AUTH_SYS
355#define	AUTH_SHORT	2		/* short hand unix style */
356#define AUTH_DH		3		/* for Diffie-Hellman mechanism */
357#define AUTH_DES	AUTH_DH		/* for backward compatibility */
358#define AUTH_KERB	4		/* kerberos style */
359#define RPCSEC_GSS	6		/* RPCSEC_GSS */
360
361/*
362 * Pseudo auth flavors for RPCSEC_GSS.
363 */
364#define	RPCSEC_GSS_KRB5		390003
365#define	RPCSEC_GSS_KRB5I	390004
366#define	RPCSEC_GSS_KRB5P	390005
367
368#endif /* !_RPC_AUTH_H */
369