xref: /openbsd-src/include/rpc/auth.h (revision 8d4335cb9be89a0813640b54b89d23507be8c423)
1*8d4335cbSguenther /*	$OpenBSD: auth.h,v 1.9 2022/02/14 03:38:59 guenther Exp $	*/
2df930be7Sderaadt /*	$NetBSD: auth.h,v 1.7 1995/04/29 05:27:55 cgd Exp $	*/
3df930be7Sderaadt 
4df930be7Sderaadt /*
5cb7760d1Smillert  * Copyright (c) 2010, Oracle America, Inc.
6df930be7Sderaadt  *
7cb7760d1Smillert  * Redistribution and use in source and binary forms, with or without
8cb7760d1Smillert  * modification, are permitted provided that the following conditions are
9cb7760d1Smillert  * met:
10df930be7Sderaadt  *
11cb7760d1Smillert  *     * Redistributions of source code must retain the above copyright
12cb7760d1Smillert  *       notice, this list of conditions and the following disclaimer.
13cb7760d1Smillert  *     * Redistributions in binary form must reproduce the above
14cb7760d1Smillert  *       copyright notice, this list of conditions and the following
15cb7760d1Smillert  *       disclaimer in the documentation and/or other materials
16cb7760d1Smillert  *       provided with the distribution.
17cb7760d1Smillert  *     * Neither the name of the "Oracle America, Inc." nor the names of its
18cb7760d1Smillert  *       contributors may be used to endorse or promote products derived
19cb7760d1Smillert  *       from this software without specific prior written permission.
20df930be7Sderaadt  *
21cb7760d1Smillert  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22cb7760d1Smillert  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23cb7760d1Smillert  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24cb7760d1Smillert  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25cb7760d1Smillert  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
26cb7760d1Smillert  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27cb7760d1Smillert  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
28cb7760d1Smillert  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29cb7760d1Smillert  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30cb7760d1Smillert  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31cb7760d1Smillert  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32cb7760d1Smillert  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33df930be7Sderaadt  *
34df930be7Sderaadt  *	from: @(#)auth.h 1.17 88/02/08 SMI
35df930be7Sderaadt  *	@(#)auth.h	2.3 88/08/07 4.0 RPCSRC
36df930be7Sderaadt  */
37df930be7Sderaadt 
38df930be7Sderaadt /*
39df930be7Sderaadt  * auth.h, Authentication interface.
40df930be7Sderaadt  *
41df930be7Sderaadt  * The data structures are completely opaque to the client.  The client
42df930be7Sderaadt  * is required to pass a AUTH * to routines that create rpc
43df930be7Sderaadt  * "sessions".
44df930be7Sderaadt  */
45df930be7Sderaadt 
46df930be7Sderaadt #ifndef _RPC_AUTH_H
47df930be7Sderaadt #define _RPC_AUTH_H
48df930be7Sderaadt #include <sys/cdefs.h>
49df930be7Sderaadt 
50df930be7Sderaadt #define MAX_AUTH_BYTES	400
51df930be7Sderaadt #define MAXNETNAMELEN	255	/* maximum length of network user's name */
52df930be7Sderaadt 
53df930be7Sderaadt /*
54df930be7Sderaadt  * Status returned from authentication check
55df930be7Sderaadt  */
56df930be7Sderaadt enum auth_stat {
57df930be7Sderaadt 	AUTH_OK=0,
58df930be7Sderaadt 	/*
59df930be7Sderaadt 	 * failed at remote end
60df930be7Sderaadt 	 */
61df930be7Sderaadt 	AUTH_BADCRED=1,			/* bogus credentials (seal broken) */
62df930be7Sderaadt 	AUTH_REJECTEDCRED=2,		/* client should begin new session */
63df930be7Sderaadt 	AUTH_BADVERF=3,			/* bogus verifier (seal broken) */
64df930be7Sderaadt 	AUTH_REJECTEDVERF=4,		/* verifier expired or was replayed */
65df930be7Sderaadt 	AUTH_TOOWEAK=5,			/* rejected due to security reasons */
66df930be7Sderaadt 	/*
67df930be7Sderaadt 	 * failed locally
68df930be7Sderaadt 	*/
69df930be7Sderaadt 	AUTH_INVALIDRESP=6,		/* bogus response verifier */
70df930be7Sderaadt 	AUTH_FAILED=7			/* some unknown reason */
71df930be7Sderaadt };
72df930be7Sderaadt 
73df930be7Sderaadt typedef u_int32_t u_int32;	/* 32-bit unsigned integers */
74df930be7Sderaadt 
75df930be7Sderaadt union des_block {
76df930be7Sderaadt 	struct {
77df930be7Sderaadt 		u_int32 high;
78df930be7Sderaadt 		u_int32 low;
79df930be7Sderaadt 	} key;
80df930be7Sderaadt 	char c[8];
81df930be7Sderaadt };
82df930be7Sderaadt typedef union des_block des_block;
83df930be7Sderaadt __BEGIN_DECLS
84c72b5b24Smillert extern bool_t xdr_des_block(XDR *, des_block *);
85df930be7Sderaadt __END_DECLS
86df930be7Sderaadt 
87df930be7Sderaadt /*
88df930be7Sderaadt  * Authentication info.  Opaque to client.
89df930be7Sderaadt  */
90df930be7Sderaadt struct opaque_auth {
91df930be7Sderaadt 	enum_t		oa_flavor;	/* flavor of auth */
92df930be7Sderaadt 	caddr_t		oa_base;	/* address of more auth stuff */
93d1f942abSespie 	unsigned int	oa_length;	/* not to exceed MAX_AUTH_BYTES */
94df930be7Sderaadt };
95df930be7Sderaadt 
96df930be7Sderaadt 
97df930be7Sderaadt /*
98df930be7Sderaadt  * Auth handle, interface to client side authenticators.
99df930be7Sderaadt  */
100df930be7Sderaadt typedef struct __rpc_auth {
101df930be7Sderaadt 	struct	opaque_auth	ah_cred;
102df930be7Sderaadt 	struct	opaque_auth	ah_verf;
103df930be7Sderaadt 	union	des_block	ah_key;
104*8d4335cbSguenther 	const struct auth_ops {
105c72b5b24Smillert 		void	(*ah_nextverf)(struct __rpc_auth *);
106df930be7Sderaadt 		/* nextverf & serialize */
107c72b5b24Smillert 		int	(*ah_marshal)(struct __rpc_auth *, XDR *);
108df930be7Sderaadt 		/* validate varifier */
109f3c3a9c6Smillert 		int	(*ah_validate)(struct __rpc_auth *,
110f3c3a9c6Smillert 			    struct opaque_auth *);
111df930be7Sderaadt 		/* refresh credentials */
112c72b5b24Smillert 		int	(*ah_refresh)(struct __rpc_auth *);
113df930be7Sderaadt 		/* destroy this structure */
114c72b5b24Smillert 		void	(*ah_destroy)(struct __rpc_auth *);
115df930be7Sderaadt 	} *ah_ops;
116df930be7Sderaadt 	caddr_t ah_private;
117df930be7Sderaadt } AUTH;
118df930be7Sderaadt 
119df930be7Sderaadt 
120df930be7Sderaadt /*
121df930be7Sderaadt  * Authentication ops.
122df930be7Sderaadt  * The ops and the auth handle provide the interface to the authenticators.
123df930be7Sderaadt  *
124df930be7Sderaadt  * AUTH	*auth;
125df930be7Sderaadt  * XDR	*xdrs;
126df930be7Sderaadt  * struct opaque_auth verf;
127df930be7Sderaadt  */
128df930be7Sderaadt #define AUTH_NEXTVERF(auth)		\
129df930be7Sderaadt 		((*((auth)->ah_ops->ah_nextverf))(auth))
130df930be7Sderaadt #define auth_nextverf(auth)		\
131df930be7Sderaadt 		((*((auth)->ah_ops->ah_nextverf))(auth))
132df930be7Sderaadt 
133df930be7Sderaadt #define AUTH_MARSHALL(auth, xdrs)	\
134df930be7Sderaadt 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
135df930be7Sderaadt #define auth_marshall(auth, xdrs)	\
136df930be7Sderaadt 		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
137df930be7Sderaadt 
138df930be7Sderaadt #define AUTH_VALIDATE(auth, verfp)	\
139df930be7Sderaadt 		((*((auth)->ah_ops->ah_validate))((auth), verfp))
140df930be7Sderaadt #define auth_validate(auth, verfp)	\
141df930be7Sderaadt 		((*((auth)->ah_ops->ah_validate))((auth), verfp))
142df930be7Sderaadt 
143df930be7Sderaadt #define AUTH_REFRESH(auth)		\
144df930be7Sderaadt 		((*((auth)->ah_ops->ah_refresh))(auth))
145df930be7Sderaadt #define auth_refresh(auth)		\
146df930be7Sderaadt 		((*((auth)->ah_ops->ah_refresh))(auth))
147df930be7Sderaadt 
148df930be7Sderaadt #define AUTH_DESTROY(auth)		\
149df930be7Sderaadt 		((*((auth)->ah_ops->ah_destroy))(auth))
150df930be7Sderaadt #define auth_destroy(auth)		\
151df930be7Sderaadt 		((*((auth)->ah_ops->ah_destroy))(auth))
152df930be7Sderaadt 
153df930be7Sderaadt 
154df930be7Sderaadt extern struct opaque_auth _null_auth;
155df930be7Sderaadt 
156df930be7Sderaadt 
157df930be7Sderaadt /*
158df930be7Sderaadt  * These are the various implementations of client side authenticators.
159df930be7Sderaadt  */
160df930be7Sderaadt 
161df930be7Sderaadt /*
162df930be7Sderaadt  * Unix style authentication
163df930be7Sderaadt  * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
164df930be7Sderaadt  *	char *machname;
165df930be7Sderaadt  *	int uid;
166df930be7Sderaadt  *	int gid;
167df930be7Sderaadt  *	int len;
168df930be7Sderaadt  *	int *aup_gids;
169df930be7Sderaadt  */
170df930be7Sderaadt __BEGIN_DECLS
171df930be7Sderaadt struct sockaddr_in;
172c72b5b24Smillert extern AUTH *authunix_create(char *, int, int, int, int *);
173c72b5b24Smillert extern AUTH *authunix_create_default(void);
174c72b5b24Smillert extern AUTH *authnone_create(void);
1754de4e8caSgrunk extern void set_rpc_maxgrouplist(int);
176df930be7Sderaadt __END_DECLS
177df930be7Sderaadt 
178df930be7Sderaadt #define AUTH_NONE	0		/* no authentication */
179df930be7Sderaadt #define	AUTH_NULL	0		/* backward compatibility */
180df930be7Sderaadt #define	AUTH_UNIX	1		/* unix style (uid, gids) */
181df930be7Sderaadt #define	AUTH_SHORT	2		/* short hand unix style */
182df930be7Sderaadt #define AUTH_DES	3		/* des style (encrypted timestamps) */
183df930be7Sderaadt 
184df930be7Sderaadt #endif /* !_RPC_AUTH_H */
185