summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/rpc/auth.h
blob: bf4a97cfe9cc3d9dd0e5f49ef4b6273b4dc61935 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Copyright 2017 Joyent Inc
 * Use is subject to license terms.
 */
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
 * Portions of this source code were derived from Berkeley
 * 4.3 BSD under license from the Regents of the University of
 * California.
 */

/*
 * auth.h, Authentication interface.
 *
 * The data structures are completely opaque to the client. The client
 * is required to pass a AUTH * to routines that create rpc
 * "sessions".
 */

#ifndef	_RPC_AUTH_H
#define	_RPC_AUTH_H

#include <rpc/xdr.h>
#include <rpc/clnt_stat.h>
#include <sys/cred.h>
#include <sys/tiuser.h>
#ifdef _KERNEL
#include <sys/zone.h>
#endif

#ifdef	__cplusplus
extern "C" {
#endif

#define	MAX_AUTH_BYTES	400	/* maximum length of an auth type, from RFC */
#define	MAXNETNAMELEN	255	/* maximum length of network user's name */

/*
 * NOTE: this value *must* be kept larger than the maximum size of all the
 * structs that rq_clntcred is cast to in the different authentication types.
 * If changes are made to any of these *_area structs, double-check they all
 * still fit. If any new authentication mechanisms are added, add a note here.
 *
 * Currently these structs can be found in:
 *  - __svcauth_sys (svc_auth_sys.c)
 *  - __svcauth_des (svcauth_des.c)
 *  - __svcauth_loopback (svc_auth_loopb.c)
 */
#define	RQCRED_SIZE	700	/* size allocated for rq_clntcred */

/*
 *  Client side authentication/security data
 */
typedef struct sec_data {
	uint_t	secmod;		/* security mode number e.g. in nfssec.conf */
	uint_t	rpcflavor;	/* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
	int	flags;		/* AUTH_F_xxx flags */
	uid_t	uid;		/* uid of caller for all sec flavors (NFSv4)  */
	caddr_t	data;		/* opaque data per flavor */
} sec_data_t;

#ifdef _SYSCALL32_IMPL
struct sec_data32 {
	uint32_t	secmod;	/* security mode number e.g. in nfssec.conf */
	uint32_t	rpcflavor; /* AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
	int32_t		flags;	/* AUTH_F_xxx flags */
	uid_t		uid;	/* uid of caller for all sec flavors (NFSv4) */
	caddr32_t	data;	/* opaque data per flavor */
};
#endif /* _SYSCALL32_IMPL */

/*
 * AUTH_DES flavor specific data from sec_data opaque data field.
 * AUTH_KERB has the same structure.
 */
typedef struct des_clnt_data {
	struct netbuf	syncaddr;	/* time sync addr */
	struct knetconfig *knconf;	/* knetconfig info that associated */
					/* with the syncaddr. */
	char		*netname;	/* server's netname */
	int		netnamelen;	/* server's netname len */
} dh_k4_clntdata_t;

#ifdef _SYSCALL32_IMPL
struct des_clnt_data32 {
	struct netbuf32 syncaddr;	/* time sync addr */
	caddr32_t knconf;		/* knetconfig info that associated */
					/* with the syncaddr. */
	caddr32_t netname;		/* server's netname */
	int32_t	netnamelen;		/* server's netname len */
};
#endif /* _SYSCALL32_IMPL */

/*
 * flavor specific data to hold the data for AUTH_DES/AUTH_KERB(v4)
 * in sec_data->data opaque field.
 */
typedef struct krb4_svc_data {
	int		window;		/* window option value */
} krb4_svcdata_t;

typedef struct krb4_svc_data	des_svcdata_t;

/*
 * authentication/security specific flags
 */
#define	AUTH_F_RPCTIMESYNC	0x001	/* use RPC to do time sync */
#define	AUTH_F_TRYNONE		0x002	/* allow fall back to AUTH_NONE */


/*
 * Status returned from authentication check
 */
enum auth_stat {
	AUTH_OK = 0,
	/*
	 * failed at remote end
	 */
	AUTH_BADCRED = 1,		/* bogus credentials (seal broken) */
	AUTH_REJECTEDCRED = 2,		/* client should begin new session */
	AUTH_BADVERF = 3,		/* bogus verifier (seal broken) */
	AUTH_REJECTEDVERF = 4,		/* verifier expired or was replayed */
	AUTH_TOOWEAK = 5,		/* rejected due to security reasons */
	/*
	 * failed locally
	 */
	AUTH_INVALIDRESP = 6,		/* bogus response verifier */
	AUTH_FAILED = 7,			/* some unknown reason */
	/*
	 * kerberos errors
	 */
	AUTH_KERB_GENERIC = 8,		/* kerberos generic error */
	AUTH_TIMEEXPIRE = 9,		/* time of credential expired */
	AUTH_TKT_FILE = 10,		/* something wrong with ticket file */
	AUTH_DECODE = 11,		/* can't decode authenticator */
	AUTH_NET_ADDR = 12,		/* wrong net address in ticket */
	/*
	 * GSS related errors
	 */
	RPCSEC_GSS_NOCRED = 13,		/* no credentials for user */
	RPCSEC_GSS_FAILED = 14		/* GSS failure, credentials deleted */
};
typedef enum auth_stat AUTH_STAT;

union des_block {
	struct	{
		uint32_t high;
		uint32_t low;
	} key;
	char c[8];
};
typedef union des_block des_block;

#ifdef __STDC__
extern bool_t xdr_des_block(XDR *, des_block *);
#else
extern bool_t xdr_des_block();
#endif


/*
 * Authentication info. Opaque to client.
 */
struct opaque_auth {
	enum_t	oa_flavor;		/* flavor of auth */
	caddr_t	oa_base;		/* address of more auth stuff */
	uint_t	oa_length;		/* not to exceed MAX_AUTH_BYTES */
};


/*
 * Auth handle, interface to client side authenticators.
 */
typedef struct __auth {
	struct	opaque_auth	ah_cred;
	struct	opaque_auth	ah_verf;
	union	des_block	ah_key;
	struct auth_ops {
#ifdef __STDC__
		void	(*ah_nextverf)(struct __auth *);
#ifdef _KERNEL
		int	(*ah_marshal)(struct __auth *, XDR *, struct cred *);
#else
		int	(*ah_marshal)(struct __auth *, XDR *);
#endif
		/* nextverf & serialize */
		int	(*ah_validate)(struct __auth *,
		    struct opaque_auth *);
		/* validate varifier */
#ifdef _KERNEL
		int	(*ah_refresh)(struct __auth *, struct rpc_msg *,
		    cred_t *);
#else
		int	(*ah_refresh)(struct __auth *, void *);
		/* refresh credentials */
#endif
		void	(*ah_destroy)(struct __auth *);
		/* destroy this structure */

#ifdef _KERNEL
		int	(*ah_wrap)(struct __auth *, caddr_t, uint_t,
		    XDR *, xdrproc_t, caddr_t);
		int	(*ah_unwrap)(struct __auth *, XDR *, xdrproc_t,
		    caddr_t);
#endif
#else
		void	(*ah_nextverf)();
		int	(*ah_marshal)();	/* nextverf & serialize */
		int	(*ah_validate)();	/* validate verifier */
		int	(*ah_refresh)();	/* refresh credentials */
		void	(*ah_destroy)();	/* destroy this structure */
#ifdef _KERNEL
		int	(*ah_wrap)();		/* encode XDR data */
		int	(*ah_unwrap)();		/* decode XDR data */
#endif

#endif
	} *ah_ops;
	caddr_t ah_private;
} AUTH;


/*
 * Authentication ops.
 * The ops and the auth handle provide the interface to the authenticators.
 *
 * AUTH	*auth;
 * XDR	*xdrs;
 * struct opaque_auth verf;
 */
#define	AUTH_NEXTVERF(auth)		\
		((*((auth)->ah_ops->ah_nextverf))(auth))
#define	auth_nextverf(auth)		\
		((*((auth)->ah_ops->ah_nextverf))(auth))


#ifdef _KERNEL
#define	AUTH_MARSHALL(auth, xdrs, cred)	\
		((*((auth)->ah_ops->ah_marshal))(auth, xdrs, cred))
#define	auth_marshall(auth, xdrs, cred)	\
		((*((auth)->ah_ops->ah_marshal))(auth, xdrs, cred))
#else
#define	AUTH_MARSHALL(auth, xdrs)	\
		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
#define	auth_marshall(auth, xdrs)	\
		((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
#endif


#define	AUTH_VALIDATE(auth, verfp)	\
		((*((auth)->ah_ops->ah_validate))((auth), verfp))
#define	auth_validate(auth, verfp)	\
		((*((auth)->ah_ops->ah_validate))((auth), verfp))

#ifdef _KERNEL
#define	AUTH_REFRESH(auth, msg, cr)		\
		((*((auth)->ah_ops->ah_refresh))(auth, msg, cr))
#define	auth_refresh(auth, msg, cr)		\
		((*((auth)->ah_ops->ah_refresh))(auth, msg, cr))
#else
#define	AUTH_REFRESH(auth, msg)		\
		((*((auth)->ah_ops->ah_refresh))(auth, msg))
#define	auth_refresh(auth, msg)		\
		((*((auth)->ah_ops->ah_refresh))(auth, msg))
#endif

#define	AUTH_DESTROY(auth)		\
		((*((auth)->ah_ops->ah_destroy))(auth))
#define	auth_destroy(auth)		\
		((*((auth)->ah_ops->ah_destroy))(auth))

/*
 * Auth flavors can now apply a transformation in addition to simple XDR
 * on the body of a call/response in ways that depend on the flavor being
 * used.  These interfaces provide a generic interface between the
 * internal RPC frame and the auth flavor specific code to allow the
 * auth flavor to encode (WRAP) or decode (UNWRAP) the body.
 */
#ifdef _KERNEL
#define	AUTH_WRAP(auth, buf, buflen, xdrs, xfunc, xwhere)	\
		((*((auth)->ah_ops->ah_wrap))(auth, buf, buflen, \
				xdrs, xfunc, xwhere))
#define	auth_wrap(auth, buf, buflen, xdrs, xfunc, xwhere)	\
		((*((auth)->ah_ops->ah_wrap))(auth, buf, buflen, \
				xdrs, xfunc, xwhere))

#define	AUTH_UNWRAP(auth, xdrs, xfunc, xwhere)	\
		((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, xfunc, xwhere))
#define	auth_unwrap(auth, xdrs)	\
		((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, xfunc, xwhere))
#endif

extern struct opaque_auth _null_auth;

/*
 * These are the various implementations of client side authenticators.
 */

/*
 * System style authentication
 * AUTH *authsys_create(machname, uid, gid, len, aup_gids)
 *	const char *machname;
 *	const uid_t uid;
 *	const gid_t gid;
 *	const int len;
 *	const gid_t *aup_gids;
 */
#ifdef _KERNEL
extern AUTH *authkern_create(void);		/* takes no parameters */
extern int authkern_init(void *, void *, int);
extern struct kmem_cache *authkern_cache;
extern AUTH *authnone_create(void);		/* takes no parameters */
extern int authnone_init(void *, void *, int);
extern struct kmem_cache *authnone_cache;
extern AUTH *authloopback_create(void);		/* takes no parameters */
extern int authloopback_init(void *, void *, int);
extern struct kmem_cache *authloopback_cache;
#else /* _KERNEL */
#ifdef __STDC__
extern AUTH *authsys_create(const char *, const uid_t, const gid_t, const int,
    const gid_t *);
extern AUTH *authsys_create_default(void);	/* takes no parameters */
extern AUTH *authnone_create(void);		/* takes no parameters */
#else /* __STDC__ */
extern AUTH *authsys_create();
extern AUTH *authsys_create_default();	/* takes no parameters */
extern AUTH *authnone_create();	/* takes no parameters */
#endif /* __STDC__ */
/* Will get obsolete in near future */
#define	authunix_create		authsys_create
#define	authunix_create_default authsys_create_default
#endif /* _KERNEL */

/*
 * DES style authentication
 * AUTH *authdes_seccreate(servername, window, timehost, ckey)
 *	const char *servername;		- network name of server
 *	const uint_t window;			- time to live
 *	const char *timehost;			- optional hostname to sync with
 *	const des_block *ckey;		- optional conversation key to use
 */
/* Will get obsolete in near future */
#ifdef _KERNEL
extern int authdes_create(char *, uint_t, struct netbuf *, struct knetconfig *,
    des_block *, int, AUTH **retauth);
#else /* _KERNEL */
#ifdef __STDC__
extern AUTH *authdes_seccreate(const char *, const uint_t, const  char *,
    const des_block *);
#else
extern AUTH *authdes_seccreate();
#endif /* __STDC__ */
#endif /* _KERNEL */

/*
 *  Netname manipulating functions
 */

#ifdef	_KERNEL
extern enum clnt_stat netname2user(char *, uid_t *, gid_t *, int *, gid_t *);
#endif
#ifdef __STDC__
extern int getnetname(char *);
extern int host2netname(char *, const char *, const char *);
extern int user2netname(char *, const uid_t, const char *);
#ifndef	_KERNEL
extern int netname2user(const char *, uid_t *, gid_t *, int *, gid_t *);
#endif
extern int netname2host(const char *, char *, const int);
#else
extern int getnetname();
extern int host2netname();
extern int user2netname();
extern int netname2host();
#endif

/*
 * These routines interface to the keyserv daemon
 */

#ifdef _KERNEL
extern enum clnt_stat key_decryptsession();
extern enum clnt_stat key_encryptsession();
extern enum clnt_stat key_gendes();
extern enum clnt_stat key_getnetname();
#endif

#ifndef _KERNEL
#ifdef	__STDC__
extern int key_decryptsession(const char *, des_block *);
extern int key_encryptsession(const char *, des_block *);
extern int key_gendes(des_block *);
extern int key_setsecret(const char *);
extern int key_secretkey_is_set(void);
/*
 * The following routines are private.
 */
extern int key_setnet_ruid();
extern int key_setnet_g_ruid();
extern int key_removesecret_g_ruid();
extern int key_secretkey_is_set_g_ruid();
extern AUTH *authsys_create_ruid();
#else
extern int key_decryptsession();
extern int key_encryptsession();
extern int key_gendes();
extern int key_setsecret();
extern int key_secretkey_is_set();
#endif
#endif


/*
 * Kerberos style authentication
 * AUTH *authkerb_seccreate(service, srv_inst, realm, window, timehost, status)
 *	const char *service;			- service name
 *	const char *srv_inst;			- server instance
 *	const char *realm;			- server realm
 *	const uint_t window;			- time to live
 *	const char *timehost;			- optional hostname to sync with
 *	int *status;			- kerberos status returned
 */
#ifdef _KERNEL
extern int    authkerb_create(char *, char *, char *, uint_t,
    struct netbuf *, int *, struct knetconfig *, int, AUTH **);
#else
#ifdef __STDC__
extern AUTH *authkerb_seccreate(const char *, const char *, const  char *,
    const uint_t, const char *, int *);
#else
extern AUTH *authkerb_seccreate();
#endif
#endif /* _KERNEL */

/*
 * Map a kerberos credential into a unix cred.
 *
 *  authkerb_getucred(rqst, uid, gid, grouplen, groups)
 *	const struct svc_req *rqst;		- request pointer
 *	uid_t *uid;
 *	gid_t *gid;
 *	short *grouplen;
 *	int   *groups;
 *
 */
#ifdef __STDC__
struct svc_req;
extern int authkerb_getucred(struct svc_req *, uid_t *, gid_t *,
    short *, int *);
#else
extern int authkerb_getucred();
#endif

#ifdef _KERNEL
/*
 * XDR an opaque authentication struct.  See auth.h.
 */
extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
#endif

#ifdef _KERNEL
extern int authany_wrap(AUTH *, caddr_t, uint_t, XDR *, xdrproc_t, caddr_t);
extern int authany_unwrap(AUTH *, XDR *, xdrproc_t, caddr_t);
#endif

#define	AUTH_NONE	0		/* no authentication */
#define	AUTH_NULL	0		/* backward compatibility */
#define	AUTH_SYS	1		/* unix style (uid, gids) */
#define	AUTH_UNIX	AUTH_SYS
#define	AUTH_SHORT	2		/* short hand unix style */
#define	AUTH_DH		3		/* for Diffie-Hellman mechanism */
#define	AUTH_DES	AUTH_DH		/* for backward compatibility */
#define	AUTH_KERB	4		/* kerberos style */
#define	RPCSEC_GSS	6		/* GSS-API style */

#define	AUTH_LOOPBACK	21982		/* unix style w/ expanded groups */
					/* for use over the local transport */

#ifdef _KERNEL
extern char	loopback_name[];

extern zone_key_t	auth_zone_key;
extern void *		auth_zone_init(zoneid_t);
extern void		auth_zone_fini(zoneid_t, void *);
#endif

#ifdef	__cplusplus
}
#endif

#endif	/* !_RPC_AUTH_H */