xref: /onnv-gate/usr/src/lib/libsasl/include/saslplug.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
3*0Sstevel@tonic-gate  * Use is subject to license terms.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate 
6*0Sstevel@tonic-gate /* saslplug.h --  API for SASL plug-ins */
7*0Sstevel@tonic-gate 
8*0Sstevel@tonic-gate #ifndef	_SASL_SASLPLUG_H
9*0Sstevel@tonic-gate #define	_SASL_SASLPLUG_H
10*0Sstevel@tonic-gate 
11*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
12*0Sstevel@tonic-gate 
13*0Sstevel@tonic-gate #ifndef	_SASL_SASL_H
14*0Sstevel@tonic-gate #include <sasl/sasl.h>
15*0Sstevel@tonic-gate #endif
16*0Sstevel@tonic-gate 
17*0Sstevel@tonic-gate #ifndef _MD5_H
18*0Sstevel@tonic-gate #include <md5.h>
19*0Sstevel@tonic-gate #endif /* _MD5_H */
20*0Sstevel@tonic-gate 
21*0Sstevel@tonic-gate #ifdef	__cplusplus
22*0Sstevel@tonic-gate extern "C" {
23*0Sstevel@tonic-gate #endif
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate /* intermediate MD5 context */
26*0Sstevel@tonic-gate typedef struct HMAC_MD5_CTX_s {
27*0Sstevel@tonic-gate     MD5_CTX ictx, octx;
28*0Sstevel@tonic-gate } HMAC_MD5_CTX;
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate /*
31*0Sstevel@tonic-gate  * intermediate HMAC state
32*0Sstevel@tonic-gate  *  values stored in network byte order (Big Endian)
33*0Sstevel@tonic-gate  */
34*0Sstevel@tonic-gate typedef struct HMAC_MD5_STATE_s {
35*0Sstevel@tonic-gate     uint32_t istate[4];
36*0Sstevel@tonic-gate     uint32_t ostate[4];
37*0Sstevel@tonic-gate } HMAC_MD5_STATE;
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate /*
40*0Sstevel@tonic-gate  * callback to lookup a sasl_callback_t for a connection
41*0Sstevel@tonic-gate  * input:
42*0Sstevel@tonic-gate  *  conn        -- the connection to lookup a callback for
43*0Sstevel@tonic-gate  *  callbacknum -- the number of the callback
44*0Sstevel@tonic-gate  * output:
45*0Sstevel@tonic-gate  *  pproc       -- pointer to the callback function (set to NULL on failure)
46*0Sstevel@tonic-gate  *  pcontext    -- pointer to the callback context (set to NULL on failure)
47*0Sstevel@tonic-gate  * returns:
48*0Sstevel@tonic-gate  *  SASL_OK -- no error
49*0Sstevel@tonic-gate  *  SASL_FAIL -- unable to find a callback of the requested type
50*0Sstevel@tonic-gate  *  SASL_INTERACT -- caller must use interaction to get data
51*0Sstevel@tonic-gate  */
52*0Sstevel@tonic-gate typedef int sasl_getcallback_t(sasl_conn_t *conn,
53*0Sstevel@tonic-gate 				unsigned long callbackid,
54*0Sstevel@tonic-gate 				int (**pproc)(),
55*0Sstevel@tonic-gate 				void **pcontext);
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate /*
58*0Sstevel@tonic-gate  * The sasl_utils structure will remain backwards compatible unless
59*0Sstevel@tonic-gate  * the SASL_*_PLUG_VERSION is changed incompatibly
60*0Sstevel@tonic-gate  * higher SASL_UTILS_VERSION numbers indicate more functions are available
61*0Sstevel@tonic-gate  */
62*0Sstevel@tonic-gate #define	SASL_UTILS_VERSION 4
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate /* utility function set for plug-ins */
65*0Sstevel@tonic-gate typedef struct sasl_utils {
66*0Sstevel@tonic-gate     int version;
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate 	/* contexts */
69*0Sstevel@tonic-gate     sasl_conn_t *conn;
70*0Sstevel@tonic-gate     sasl_rand_t *rpool;
71*0Sstevel@tonic-gate     void *getopt_context;
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate 	/* option function */
74*0Sstevel@tonic-gate     sasl_getopt_t *getopt;
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate 	/* allocation functions: */
77*0Sstevel@tonic-gate     sasl_malloc_t *malloc;
78*0Sstevel@tonic-gate     sasl_calloc_t *calloc;
79*0Sstevel@tonic-gate     sasl_realloc_t *realloc;
80*0Sstevel@tonic-gate     sasl_free_t *free;
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate 	/* mutex functions: */
83*0Sstevel@tonic-gate     sasl_mutex_alloc_t *mutex_alloc;
84*0Sstevel@tonic-gate     sasl_mutex_lock_t *mutex_lock;
85*0Sstevel@tonic-gate     sasl_mutex_unlock_t *mutex_unlock;
86*0Sstevel@tonic-gate     sasl_mutex_free_t *mutex_free;
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate 	/* MD5 hash and HMAC functions */
89*0Sstevel@tonic-gate     void (*MD5Init)(MD5_CTX *);
90*0Sstevel@tonic-gate     void (*MD5Update)(MD5_CTX *, const unsigned char *text, unsigned int len);
91*0Sstevel@tonic-gate     void (*MD5Final)(unsigned char [16], MD5_CTX *);
92*0Sstevel@tonic-gate     void (*hmac_md5)(const unsigned char *text, int text_len,
93*0Sstevel@tonic-gate 			const unsigned char *key, int key_len,
94*0Sstevel@tonic-gate 			unsigned char [16]);
95*0Sstevel@tonic-gate     void (*hmac_md5_init)(HMAC_MD5_CTX *, const unsigned char *key, int len);
96*0Sstevel@tonic-gate 	/* hmac_md5_update() is just a call to MD5Update on inner context */
97*0Sstevel@tonic-gate     void (*hmac_md5_final)(unsigned char [16], HMAC_MD5_CTX *);
98*0Sstevel@tonic-gate     void (*hmac_md5_precalc)(HMAC_MD5_STATE *,
99*0Sstevel@tonic-gate 				const unsigned char *key, int len);
100*0Sstevel@tonic-gate     void (*hmac_md5_import)(HMAC_MD5_CTX *, HMAC_MD5_STATE *);
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 	/* mechanism utility functions (same as above): */
103*0Sstevel@tonic-gate     int (*mkchal)(sasl_conn_t *conn, char *buf, unsigned maxlen,
104*0Sstevel@tonic-gate 		unsigned hostflag);
105*0Sstevel@tonic-gate     int (*utf8verify)(const char *str, unsigned len);
106*0Sstevel@tonic-gate     void (*rand)(sasl_rand_t *rpool, char *buf, unsigned len);
107*0Sstevel@tonic-gate     void (*churn)(sasl_rand_t *rpool, const char *data, unsigned len);
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate 	/*
110*0Sstevel@tonic-gate 	 * This allows recursive calls to the sasl_checkpass() routine from
111*0Sstevel@tonic-gate 	 * within a SASL plug-in.  This MUST NOT be used in the PLAIN mechanism
112*0Sstevel@tonic-gate 	 * as sasl_checkpass MAY be a front-end for the PLAIN mechanism.
113*0Sstevel@tonic-gate 	 * This is intended for use by the non-standard LOGIN mechanism and
114*0Sstevel@tonic-gate 	 * potentially by a future mechanism which uses public-key technology
115*0Sstevel@tonic-gate 	 * to set up a lightweight encryption layer just for sending a
116*0Sstevel@tonic-gate 	 * password.
117*0Sstevel@tonic-gate 	 */
118*0Sstevel@tonic-gate     int (*checkpass)(sasl_conn_t *conn,
119*0Sstevel@tonic-gate 		    const char *user, unsigned userlen,
120*0Sstevel@tonic-gate 		    const char *pass, unsigned passlen);
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate 	/* Access to base64 encode/decode routines */
123*0Sstevel@tonic-gate     int (*decode64)(const char *in, unsigned inlen,
124*0Sstevel@tonic-gate 		    char *out, unsigned outmax, unsigned *outlen);
125*0Sstevel@tonic-gate     int (*encode64)(const char *in, unsigned inlen,
126*0Sstevel@tonic-gate 		    char *out, unsigned outmax, unsigned *outlen);
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate 	/* erase a buffer */
129*0Sstevel@tonic-gate     void (*erasebuffer)(char *buf, unsigned len);
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate 	/* callback to sasl_getprop() and sasl_setprop() */
132*0Sstevel@tonic-gate     int (*getprop)(sasl_conn_t *conn, int propnum, const void **pvalue);
133*0Sstevel@tonic-gate     int (*setprop)(sasl_conn_t *conn, int propnum, const void *value);
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate 	/* callback function */
136*0Sstevel@tonic-gate     sasl_getcallback_t *getcallback;
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate 	/*
139*0Sstevel@tonic-gate 	 * format a message and then pass it to the SASL_CB_LOG callback
140*0Sstevel@tonic-gate 	 *
141*0Sstevel@tonic-gate 	 * use syslog()-style formatting (printf with %m as most recent errno
142*0Sstevel@tonic-gate 	 * error).  The implementation may use a fixed size buffer not smaller
143*0Sstevel@tonic-gate 	 * than 512 octets if it securely truncates the message.
144*0Sstevel@tonic-gate 	 *
145*0Sstevel@tonic-gate 	 * level is a SASL_LOG_* level (see sasl.h)
146*0Sstevel@tonic-gate 	 */
147*0Sstevel@tonic-gate     void (*log)(sasl_conn_t *conn, int level, const char *fmt, ...);
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate 	/* callback to sasl_seterror() */
150*0Sstevel@tonic-gate     void (*seterror)(sasl_conn_t *conn, unsigned flags, const char *fmt, ...);
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate 	/* spare function pointer */
153*0Sstevel@tonic-gate     int *(*spare_fptr)();
154*0Sstevel@tonic-gate 
155*0Sstevel@tonic-gate 	/* auxiliary property utilities */
156*0Sstevel@tonic-gate     struct propctx *(*prop_new)(unsigned estimate);
157*0Sstevel@tonic-gate     int (*prop_dup)(struct propctx *src_ctx, struct propctx **dst_ctx);
158*0Sstevel@tonic-gate     int (*prop_request)(struct propctx *ctx, const char **names);
159*0Sstevel@tonic-gate     const struct propval *(*prop_get)(struct propctx *ctx);
160*0Sstevel@tonic-gate     int (*prop_getnames)(struct propctx *ctx, const char **names,
161*0Sstevel@tonic-gate 			struct propval *vals);
162*0Sstevel@tonic-gate     void (*prop_clear)(struct propctx *ctx, int requests);
163*0Sstevel@tonic-gate     void (*prop_dispose)(struct propctx **ctx);
164*0Sstevel@tonic-gate     int (*prop_format)(struct propctx *ctx, const char *sep, int seplen,
165*0Sstevel@tonic-gate 		    char *outbuf, unsigned outmax, unsigned *outlen);
166*0Sstevel@tonic-gate     int (*prop_set)(struct propctx *ctx, const char *name,
167*0Sstevel@tonic-gate 		    const char *value, int vallen);
168*0Sstevel@tonic-gate     int (*prop_setvals)(struct propctx *ctx, const char *name,
169*0Sstevel@tonic-gate 			const char **values);
170*0Sstevel@tonic-gate     void (*prop_erase)(struct propctx *ctx, const char *name);
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate 	/* for additions which don't require a version upgrade; set to 0 */
173*0Sstevel@tonic-gate     int (*spare_fptr1)();
174*0Sstevel@tonic-gate     int (*spare_fptr2)();
175*0Sstevel@tonic-gate     int (*spare_fptr3)();
176*0Sstevel@tonic-gate } sasl_utils_t;
177*0Sstevel@tonic-gate 
178*0Sstevel@tonic-gate /*
179*0Sstevel@tonic-gate  * output parameters from SASL API
180*0Sstevel@tonic-gate  *
181*0Sstevel@tonic-gate  * created / destroyed by the glue code, though probably filled in
182*0Sstevel@tonic-gate  * by a combination of the plugin, the glue code, and the canon_user callback.
183*0Sstevel@tonic-gate  *
184*0Sstevel@tonic-gate  */
185*0Sstevel@tonic-gate typedef struct sasl_out_params {
186*0Sstevel@tonic-gate     unsigned doneflag;		/* exchange complete */
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate     const char *user;		/* canonicalized user name */
189*0Sstevel@tonic-gate     const char *authid;		/* canonicalized authentication id */
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate     unsigned ulen;		/* length of canonicalized user name */
192*0Sstevel@tonic-gate     unsigned alen;		/* length of canonicalized authid */
193*0Sstevel@tonic-gate 
194*0Sstevel@tonic-gate 	/* security layer information */
195*0Sstevel@tonic-gate     unsigned maxoutbuf;
196*0Sstevel@tonic-gate     sasl_ssf_t mech_ssf;    /* Should be set non-zero if negotiation of a */
197*0Sstevel@tonic-gate 			    /* security layer was *attempted*, even if */
198*0Sstevel@tonic-gate 			    /* the negotiation failed */
199*0Sstevel@tonic-gate     void *encode_context;
200*0Sstevel@tonic-gate     int (*encode)(void *context, const struct iovec *invec, unsigned numiov,
201*0Sstevel@tonic-gate 		const char **output, unsigned *outputlen);
202*0Sstevel@tonic-gate     void *decode_context;
203*0Sstevel@tonic-gate     int (*decode)(void *context, const char *input, unsigned inputlen,
204*0Sstevel@tonic-gate 		const char **output, unsigned *outputlen);
205*0Sstevel@tonic-gate 
206*0Sstevel@tonic-gate 	/* for additions which don't require a version upgrade; set to 0 */
207*0Sstevel@tonic-gate     void *spare_ptr1;
208*0Sstevel@tonic-gate     void *spare_ptr2;
209*0Sstevel@tonic-gate     void *spare_ptr3;
210*0Sstevel@tonic-gate     void *spare_ptr4;
211*0Sstevel@tonic-gate     int (*spare_fptr1)();
212*0Sstevel@tonic-gate     int (*spare_fptr2)();
213*0Sstevel@tonic-gate     int spare_int1;
214*0Sstevel@tonic-gate     int spare_int2;
215*0Sstevel@tonic-gate     int spare_int3;
216*0Sstevel@tonic-gate     int spare_int4;
217*0Sstevel@tonic-gate 
218*0Sstevel@tonic-gate 	/*
219*0Sstevel@tonic-gate 	 * set to 0 initially, this allows a plugin with extended parameters
220*0Sstevel@tonic-gate 	 * to work with an older framework by updating version as parameters
221*0Sstevel@tonic-gate 	 * are added.
222*0Sstevel@tonic-gate 	 */
223*0Sstevel@tonic-gate     int param_version;
224*0Sstevel@tonic-gate } sasl_out_params_t;
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate /*
227*0Sstevel@tonic-gate  * Client Mechanism Functions
228*0Sstevel@tonic-gate  */
229*0Sstevel@tonic-gate 
230*0Sstevel@tonic-gate /*
231*0Sstevel@tonic-gate  * input parameters to client SASL plugin
232*0Sstevel@tonic-gate  *
233*0Sstevel@tonic-gate  * created / destroyed by the glue code
234*0Sstevel@tonic-gate  *
235*0Sstevel@tonic-gate  */
236*0Sstevel@tonic-gate typedef struct sasl_client_params {
237*0Sstevel@tonic-gate     const char *service;	/* service name */
238*0Sstevel@tonic-gate     const char *serverFQDN;	/* server fully qualified domain name */
239*0Sstevel@tonic-gate     const char *clientFQDN;	/* client's fully qualified domain name */
240*0Sstevel@tonic-gate     const sasl_utils_t *utils;	/* SASL API utility routines -- */
241*0Sstevel@tonic-gate 				/* for a particular sasl_conn_t, */
242*0Sstevel@tonic-gate 				/* MUST remain valid until mech_free is */
243*0Sstevel@tonic-gate 				/* called */
244*0Sstevel@tonic-gate     const sasl_callback_t *prompt_supp; /* client callback list */
245*0Sstevel@tonic-gate     const char *iplocalport;	/* server IP domain literal & port */
246*0Sstevel@tonic-gate     const char *ipremoteport;	/* client IP domain literal & port */
247*0Sstevel@tonic-gate 
248*0Sstevel@tonic-gate     unsigned servicelen;	/* length of service */
249*0Sstevel@tonic-gate     unsigned slen;		/* length of serverFQDN */
250*0Sstevel@tonic-gate     unsigned clen;		/* length of clientFQDN */
251*0Sstevel@tonic-gate     unsigned iploclen;		/* length of iplocalport */
252*0Sstevel@tonic-gate     unsigned ipremlen;		/* length of ipremoteport */
253*0Sstevel@tonic-gate 
254*0Sstevel@tonic-gate 	/* application's security requirements & info */
255*0Sstevel@tonic-gate     sasl_security_properties_t props;
256*0Sstevel@tonic-gate     sasl_ssf_t external_ssf;	/* external SSF active */
257*0Sstevel@tonic-gate 
258*0Sstevel@tonic-gate 	/* for additions which don't require a version upgrade; set to 0 */
259*0Sstevel@tonic-gate     void *spare_ptr1;
260*0Sstevel@tonic-gate     void *spare_ptr2;
261*0Sstevel@tonic-gate     void *spare_ptr3;
262*0Sstevel@tonic-gate     void *spare_ptr4;
263*0Sstevel@tonic-gate 
264*0Sstevel@tonic-gate 	/*
265*0Sstevel@tonic-gate 	 * Canonicalize a user name from on-wire to internal format
266*0Sstevel@tonic-gate 	 *  added rjs3 2001-05-23
267*0Sstevel@tonic-gate 	 *  Must be called once user name aquired if canon_user is non-NULL.
268*0Sstevel@tonic-gate 	 *  conn    connection context
269*0Sstevel@tonic-gate 	 *  in	    user name from wire protocol (need not be NUL terminated)
270*0Sstevel@tonic-gate 	 *  len	    length of user name from wire protocol (0 = strlen(user))
271*0Sstevel@tonic-gate 	 *  flags   for SASL_CU_* flags
272*0Sstevel@tonic-gate 	 *  oparams the user, authid, ulen, alen, fields are
273*0Sstevel@tonic-gate 	 *	    set appropriately after canonicalization/copying and
274*0Sstevel@tonic-gate 	 *	    authorization of arguments
275*0Sstevel@tonic-gate 	 *
276*0Sstevel@tonic-gate 	 *  responsible for setting user, ulen, authid, and alen in the oparams
277*0Sstevel@tonic-gate 	 *  structure
278*0Sstevel@tonic-gate 	 *
279*0Sstevel@tonic-gate 	 *  default behavior is to strip leading and trailing whitespace, as
280*0Sstevel@tonic-gate 	 *  well as allocating space for and copying the parameters.
281*0Sstevel@tonic-gate 	 *
282*0Sstevel@tonic-gate 	 * results:
283*0Sstevel@tonic-gate 	 *  SASL_OK	  -- success
284*0Sstevel@tonic-gate 	 *  SASL_NOMEM    -- out of memory
285*0Sstevel@tonic-gate 	 *  SASL_BADPARAM -- invalid conn
286*0Sstevel@tonic-gate 	 *  SASL_BADPROT  -- invalid user/authid
287*0Sstevel@tonic-gate 	 */
288*0Sstevel@tonic-gate     int (*canon_user)(sasl_conn_t *conn,
289*0Sstevel@tonic-gate 		    const char *in, unsigned len,
290*0Sstevel@tonic-gate 		    unsigned flags,
291*0Sstevel@tonic-gate 		    sasl_out_params_t *oparams);
292*0Sstevel@tonic-gate 
293*0Sstevel@tonic-gate     int (*spare_fptr1)();
294*0Sstevel@tonic-gate 
295*0Sstevel@tonic-gate     int spare_int1;
296*0Sstevel@tonic-gate     int spare_int2;
297*0Sstevel@tonic-gate     int spare_int3;
298*0Sstevel@tonic-gate 
299*0Sstevel@tonic-gate 	/* flags field as passed to sasl_client_new */
300*0Sstevel@tonic-gate     unsigned flags;
301*0Sstevel@tonic-gate 
302*0Sstevel@tonic-gate 	/*
303*0Sstevel@tonic-gate 	 * set to 0 initially, this allows a plugin with extended parameters
304*0Sstevel@tonic-gate 	 * to work with an older framework by updating version as parameters
305*0Sstevel@tonic-gate 	 * are added.
306*0Sstevel@tonic-gate 	 */
307*0Sstevel@tonic-gate     int param_version;
308*0Sstevel@tonic-gate } sasl_client_params_t;
309*0Sstevel@tonic-gate 
310*0Sstevel@tonic-gate /* features shared between client and server */
311*0Sstevel@tonic-gate /* These allow the glue code to handle client-first and server-last issues */
312*0Sstevel@tonic-gate 
313*0Sstevel@tonic-gate /*
314*0Sstevel@tonic-gate  * This indicates that the mechanism prefers to do client-send-first
315*0Sstevel@tonic-gate  * if the protocol allows it.
316*0Sstevel@tonic-gate  */
317*0Sstevel@tonic-gate #define	SASL_FEAT_WANT_CLIENT_FIRST 0x0002
318*0Sstevel@tonic-gate 
319*0Sstevel@tonic-gate /*
320*0Sstevel@tonic-gate  * This feature is deprecated, instead, plugins should set *serverout to
321*0Sstevel@tonic-gate  * non-NULL and return SASL_OK intelligently to allow flexible use of
322*0Sstevel@tonic-gate  * server-last semantics
323*0Sstevel@tonic-gate  */
324*0Sstevel@tonic-gate /* #define	SASL_FEAT_WANT_SERVER_LAST 0x0004 */
325*0Sstevel@tonic-gate 
326*0Sstevel@tonic-gate /*
327*0Sstevel@tonic-gate  * This feature is deprecated, instead plugins should correctly set
328*0Sstevel@tonic-gate  * SASL_FEAT_SERVER_FIRST as needed
329*0Sstevel@tonic-gate  */
330*0Sstevel@tonic-gate /* #define	SASL_FEAT_INTERNAL_CLIENT_FIRST 0x0008 */
331*0Sstevel@tonic-gate 
332*0Sstevel@tonic-gate /*
333*0Sstevel@tonic-gate  * This indicates that the plugin is server-first only.
334*0Sstevel@tonic-gate  * Not defining either of SASL_FEAT_SERVER_FIRST or
335*0Sstevel@tonic-gate  * SASL_FEAT_WANT_CLIENT_FIRST indicates that the mechanism will take care
336*0Sstevel@tonic-gate  * of the client-first situation internally.
337*0Sstevel@tonic-gate  */
338*0Sstevel@tonic-gate #define	SASL_FEAT_SERVER_FIRST 0x0010
339*0Sstevel@tonic-gate 
340*0Sstevel@tonic-gate /* This plugin allows proxying */
341*0Sstevel@tonic-gate #define	SASL_FEAT_ALLOWS_PROXY 0x0020
342*0Sstevel@tonic-gate 
343*0Sstevel@tonic-gate /* client plug-in features */
344*0Sstevel@tonic-gate #define	SASL_FEAT_NEEDSERVERFQDN 0x0001
345*0Sstevel@tonic-gate 
346*0Sstevel@tonic-gate /* a C object for a client mechanism */
347*0Sstevel@tonic-gate typedef struct sasl_client_plug {
348*0Sstevel@tonic-gate 	/* mechanism name */
349*0Sstevel@tonic-gate     const char *mech_name;
350*0Sstevel@tonic-gate 
351*0Sstevel@tonic-gate 	/* best mech additional security layer strength factor */
352*0Sstevel@tonic-gate     sasl_ssf_t max_ssf;
353*0Sstevel@tonic-gate 
354*0Sstevel@tonic-gate 	/* best security flags, as defined in sasl_security_properties_t */
355*0Sstevel@tonic-gate     unsigned security_flags;
356*0Sstevel@tonic-gate 
357*0Sstevel@tonic-gate 	/* features of plugin */
358*0Sstevel@tonic-gate     unsigned features;
359*0Sstevel@tonic-gate 
360*0Sstevel@tonic-gate 	/* required prompt ids, NULL = user/pass only */
361*0Sstevel@tonic-gate     const unsigned long *required_prompts;
362*0Sstevel@tonic-gate 
363*0Sstevel@tonic-gate 	/* global state for mechanism */
364*0Sstevel@tonic-gate     void *glob_context;
365*0Sstevel@tonic-gate 
366*0Sstevel@tonic-gate 	/*
367*0Sstevel@tonic-gate 	 * create context for mechanism, using params supplied
368*0Sstevel@tonic-gate 	 *  glob_context   -- from above
369*0Sstevel@tonic-gate 	 *  params	   -- params from sasl_client_new
370*0Sstevel@tonic-gate 	 *  conn_context   -- context for one connection
371*0Sstevel@tonic-gate 	 * returns:
372*0Sstevel@tonic-gate 	 *  SASL_OK	   -- success
373*0Sstevel@tonic-gate 	 *  SASL_NOMEM	   -- not enough memory
374*0Sstevel@tonic-gate 	 *  SASL_WRONGMECH -- mech doesn't support security params
375*0Sstevel@tonic-gate 	 */
376*0Sstevel@tonic-gate     int (*mech_new)(void *glob_context,
377*0Sstevel@tonic-gate 		    sasl_client_params_t *cparams,
378*0Sstevel@tonic-gate 		    void **conn_context);
379*0Sstevel@tonic-gate 
380*0Sstevel@tonic-gate 	/*
381*0Sstevel@tonic-gate 	 * perform one step of exchange.  NULL is passed for serverin on
382*0Sstevel@tonic-gate 	 * first step.
383*0Sstevel@tonic-gate 	 * returns:
384*0Sstevel@tonic-gate 	 *  SASL_OK	   -- success
385*0Sstevel@tonic-gate 	 *  SASL_INTERACT  -- user interaction needed to fill in prompts
386*0Sstevel@tonic-gate 	 *  SASL_BADPROT   -- server protocol incorrect/cancelled
387*0Sstevel@tonic-gate 	 *  SASL_BADSERV   -- server failed mutual auth
388*0Sstevel@tonic-gate 	 */
389*0Sstevel@tonic-gate     int (*mech_step)(void *conn_context,
390*0Sstevel@tonic-gate 		    sasl_client_params_t *cparams,
391*0Sstevel@tonic-gate 		    const char *serverin,
392*0Sstevel@tonic-gate 		    unsigned serverinlen,
393*0Sstevel@tonic-gate 		    sasl_interact_t **prompt_need,
394*0Sstevel@tonic-gate 		    const char **clientout,
395*0Sstevel@tonic-gate 		    unsigned *clientoutlen,
396*0Sstevel@tonic-gate 		    sasl_out_params_t *oparams);
397*0Sstevel@tonic-gate 
398*0Sstevel@tonic-gate 	/* dispose of connection context from mech_new */
399*0Sstevel@tonic-gate     void (*mech_dispose)(void *conn_context, const sasl_utils_t *utils);
400*0Sstevel@tonic-gate 
401*0Sstevel@tonic-gate 	/*
402*0Sstevel@tonic-gate 	 * free all global space used by mechanism
403*0Sstevel@tonic-gate 	 *  mech_dispose must be called on all mechanisms first
404*0Sstevel@tonic-gate 	 */
405*0Sstevel@tonic-gate     void (*mech_free)(void *glob_context, const sasl_utils_t *utils);
406*0Sstevel@tonic-gate 
407*0Sstevel@tonic-gate 	/*
408*0Sstevel@tonic-gate 	 * perform precalculations during a network round-trip
409*0Sstevel@tonic-gate 	 *  or idle period.  conn_context may be NULL
410*0Sstevel@tonic-gate 	 *  returns 1 if action taken, 0 if no action taken
411*0Sstevel@tonic-gate 	 */
412*0Sstevel@tonic-gate     int (*idle)(void *glob_context,
413*0Sstevel@tonic-gate 		void *conn_context,
414*0Sstevel@tonic-gate 		sasl_client_params_t *cparams);
415*0Sstevel@tonic-gate 
416*0Sstevel@tonic-gate 	/* for additions which don't require a version upgrade; set to 0 */
417*0Sstevel@tonic-gate     int (*spare_fptr1)();
418*0Sstevel@tonic-gate     int (*spare_fptr2)();
419*0Sstevel@tonic-gate } sasl_client_plug_t;
420*0Sstevel@tonic-gate 
421*0Sstevel@tonic-gate #define	SASL_CLIENT_PLUG_VERSION	4
422*0Sstevel@tonic-gate 
423*0Sstevel@tonic-gate /*
424*0Sstevel@tonic-gate  * plug-in entry point:
425*0Sstevel@tonic-gate  *  utils       -- utility callback functions
426*0Sstevel@tonic-gate  *  max_version -- highest client plug version supported
427*0Sstevel@tonic-gate  * returns:
428*0Sstevel@tonic-gate  *  out_version -- client plug version of result
429*0Sstevel@tonic-gate  *  pluglist    -- list of mechanism plug-ins
430*0Sstevel@tonic-gate  *  plugcount   -- number of mechanism plug-ins
431*0Sstevel@tonic-gate  * results:
432*0Sstevel@tonic-gate  *  SASL_OK       -- success
433*0Sstevel@tonic-gate  *  SASL_NOMEM    -- failure
434*0Sstevel@tonic-gate  *  SASL_BADVERS  -- max_version too small
435*0Sstevel@tonic-gate  *  SASL_BADPARAM -- bad config string
436*0Sstevel@tonic-gate  *  ...
437*0Sstevel@tonic-gate  */
438*0Sstevel@tonic-gate typedef int sasl_client_plug_init_t(const sasl_utils_t *utils,
439*0Sstevel@tonic-gate 				    int max_version,
440*0Sstevel@tonic-gate 				    int *out_version,
441*0Sstevel@tonic-gate 				    sasl_client_plug_t **pluglist,
442*0Sstevel@tonic-gate 				    int *plugcount);
443*0Sstevel@tonic-gate 
444*0Sstevel@tonic-gate /* add a client plug-in */
445*0Sstevel@tonic-gate LIBSASL_API int sasl_client_add_plugin(const char *plugname,
446*0Sstevel@tonic-gate 				sasl_client_plug_init_t *cplugfunc);
447*0Sstevel@tonic-gate 
448*0Sstevel@tonic-gate /*
449*0Sstevel@tonic-gate  * Server Functions
450*0Sstevel@tonic-gate  */
451*0Sstevel@tonic-gate 
452*0Sstevel@tonic-gate /*
453*0Sstevel@tonic-gate  * input parameters to server SASL plugin
454*0Sstevel@tonic-gate  *
455*0Sstevel@tonic-gate  * created / destroyed by the glue code
456*0Sstevel@tonic-gate  *
457*0Sstevel@tonic-gate  */
458*0Sstevel@tonic-gate typedef struct sasl_server_params {
459*0Sstevel@tonic-gate     const char *service;	/* NULL = default service for user_exists */
460*0Sstevel@tonic-gate 				/* and setpass */
461*0Sstevel@tonic-gate     const char *appname;	/* name of calling application */
462*0Sstevel@tonic-gate     const char *serverFQDN;	/* server default fully qualified domain name */
463*0Sstevel@tonic-gate 				/* (e.g., gethostname) */
464*0Sstevel@tonic-gate     const char *user_realm;	/* realm for user (NULL = client supplied) */
465*0Sstevel@tonic-gate     const char *iplocalport;	/* server IP domain literal & port */
466*0Sstevel@tonic-gate     const char *ipremoteport;	/* client IP domain literal & port */
467*0Sstevel@tonic-gate 
468*0Sstevel@tonic-gate     unsigned servicelen;	/* length of service */
469*0Sstevel@tonic-gate     unsigned applen;		/* length of appname */
470*0Sstevel@tonic-gate     unsigned slen;		/* length of serverFQDN */
471*0Sstevel@tonic-gate     unsigned urlen;		/* length of user_realm */
472*0Sstevel@tonic-gate     unsigned iploclen;		/* length of iplocalport */
473*0Sstevel@tonic-gate     unsigned ipremlen;		/* length of ipremoteport */
474*0Sstevel@tonic-gate 
475*0Sstevel@tonic-gate 	/*
476*0Sstevel@tonic-gate 	 * This indicates the level of logging desired.  See SASL_LOG_*
477*0Sstevel@tonic-gate 	 * in sasl.h
478*0Sstevel@tonic-gate 	 *
479*0Sstevel@tonic-gate 	 * Plug-ins can ignore this and just pass their desired level to
480*0Sstevel@tonic-gate 	 * the log callback.  This is primarily used to eliminate logging which
481*0Sstevel@tonic-gate 	 * might be a performance problem (e.g., full protocol trace) and
482*0Sstevel@tonic-gate 	 * to select between SASL_LOG_TRACE and SASL_LOG_PASS alternatives
483*0Sstevel@tonic-gate 	 */
484*0Sstevel@tonic-gate     int log_level;
485*0Sstevel@tonic-gate 
486*0Sstevel@tonic-gate     const sasl_utils_t *utils;	/* SASL API utility routines -- */
487*0Sstevel@tonic-gate 				/* for a particular sasl_conn_t, */
488*0Sstevel@tonic-gate 				/* MUST remain valid until mech_free is */
489*0Sstevel@tonic-gate 				/* called */
490*0Sstevel@tonic-gate 
491*0Sstevel@tonic-gate     const sasl_callback_t *callbacks;	/* Callbacks from application */
492*0Sstevel@tonic-gate 
493*0Sstevel@tonic-gate 	/* application's security requirements */
494*0Sstevel@tonic-gate     sasl_security_properties_t props;
495*0Sstevel@tonic-gate     sasl_ssf_t external_ssf;	/* external SSF active */
496*0Sstevel@tonic-gate 
497*0Sstevel@tonic-gate 	/*
498*0Sstevel@tonic-gate 	 * server plug-in calls this when it first has access to the plaintext
499*0Sstevel@tonic-gate 	 *  passphrase.  This is used to transition users via setpass calls.
500*0Sstevel@tonic-gate 	 *  If passlen is 0, it defaults to strlen(pass).
501*0Sstevel@tonic-gate 	 *  returns 0 if no entry added, 1 if entry added
502*0Sstevel@tonic-gate 	 */
503*0Sstevel@tonic-gate     int (*transition)(sasl_conn_t *conn, const char *pass, unsigned passlen);
504*0Sstevel@tonic-gate 
505*0Sstevel@tonic-gate 	/*
506*0Sstevel@tonic-gate 	 * Canonicalize a user name from on-wire to internal format
507*0Sstevel@tonic-gate 	 *  added cjn 1999-09-21
508*0Sstevel@tonic-gate 	 *  Must be called once user name aquired if canon_user is non-NULL.
509*0Sstevel@tonic-gate 	 *  conn    connection context
510*0Sstevel@tonic-gate 	 *  user    user name from wire protocol (need not be NUL terminated)
511*0Sstevel@tonic-gate 	 *  ulen    length of user name from wire protocol (0 = strlen(user))
512*0Sstevel@tonic-gate 	 *  flags   for SASL_CU_* flags
513*0Sstevel@tonic-gate 	 *  oparams the user, authid, ulen, alen, fields are
514*0Sstevel@tonic-gate 	 *	    set appropriately after canonicalization/copying and
515*0Sstevel@tonic-gate 	 *	    authorization of arguments
516*0Sstevel@tonic-gate 	 *
517*0Sstevel@tonic-gate 	 *  responsible for setting user, ulen, authid, and alen in the oparams
518*0Sstevel@tonic-gate 	 *  structure
519*0Sstevel@tonic-gate 	 *
520*0Sstevel@tonic-gate 	 *  default behavior is to strip leading and trailing whitespace, as
521*0Sstevel@tonic-gate 	 *  well as allocating space for and copying the parameters.
522*0Sstevel@tonic-gate 	 *
523*0Sstevel@tonic-gate 	 * results:
524*0Sstevel@tonic-gate 	 *  SASL_OK	  -- success
525*0Sstevel@tonic-gate 	 *  SASL_NOMEM    -- out of memory
526*0Sstevel@tonic-gate 	 *  SASL_BADPARAM -- invalid conn
527*0Sstevel@tonic-gate 	 *  SASL_BADPROT  -- invalid user/authid
528*0Sstevel@tonic-gate 	 */
529*0Sstevel@tonic-gate     int (*canon_user)(sasl_conn_t *conn,
530*0Sstevel@tonic-gate 		    const char *user, unsigned ulen,
531*0Sstevel@tonic-gate 		    unsigned flags,
532*0Sstevel@tonic-gate 		    sasl_out_params_t *oparams);
533*0Sstevel@tonic-gate 
534*0Sstevel@tonic-gate 	/*
535*0Sstevel@tonic-gate 	 * auxiliary property context (see definitions in prop.h)
536*0Sstevel@tonic-gate 	 *  added cjn 2000-01-30
537*0Sstevel@tonic-gate 	 *
538*0Sstevel@tonic-gate 	 * NOTE: these properties are the ones associated with the
539*0Sstevel@tonic-gate 	 * canonicalized "user" (user to login as / authorization id), not
540*0Sstevel@tonic-gate 	 * the "authid" (user whose credentials are used / authentication id)
541*0Sstevel@tonic-gate 	 * Prefix the property name with a "*" if a property associated with
542*0Sstevel@tonic-gate 	 * the "authid" is interesting.
543*0Sstevel@tonic-gate 	 */
544*0Sstevel@tonic-gate     struct propctx *propctx;
545*0Sstevel@tonic-gate 
546*0Sstevel@tonic-gate 	/* for additions which don't require a version upgrade; set to 0 */
547*0Sstevel@tonic-gate     void *spare_ptr1;
548*0Sstevel@tonic-gate     void *spare_ptr2;
549*0Sstevel@tonic-gate     void *spare_ptr3;
550*0Sstevel@tonic-gate     void *spare_ptr4;
551*0Sstevel@tonic-gate     int (*spare_fptr1)();
552*0Sstevel@tonic-gate     int (*spare_fptr2)();
553*0Sstevel@tonic-gate     int spare_int1;
554*0Sstevel@tonic-gate     int spare_int2;
555*0Sstevel@tonic-gate     int spare_int3;
556*0Sstevel@tonic-gate 
557*0Sstevel@tonic-gate 	/* flags field as passed to sasl_server_new */
558*0Sstevel@tonic-gate     unsigned flags;
559*0Sstevel@tonic-gate 
560*0Sstevel@tonic-gate 	/*
561*0Sstevel@tonic-gate 	 * set to 0 initially, this allows a plugin with extended parameters
562*0Sstevel@tonic-gate 	 * to work with an older framework by updating version as parameters
563*0Sstevel@tonic-gate 	 * are added.
564*0Sstevel@tonic-gate 	 */
565*0Sstevel@tonic-gate     int param_version;
566*0Sstevel@tonic-gate } sasl_server_params_t;
567*0Sstevel@tonic-gate 
568*0Sstevel@tonic-gate /* features for server plug-in */
569*0Sstevel@tonic-gate #define	SASL_FEAT_SERVICE    0x0200 /* service-specific passwords supported */
570*0Sstevel@tonic-gate #define	SASL_FEAT_GETSECRET  0x0400 /* sasl_server_{get,put}secret_t */
571*0Sstevel@tonic-gate 				    /* callbacks required by plug-in */
572*0Sstevel@tonic-gate 
573*0Sstevel@tonic-gate /* a C object for a server mechanism */
574*0Sstevel@tonic-gate typedef struct sasl_server_plug {
575*0Sstevel@tonic-gate 	/* mechanism name */
576*0Sstevel@tonic-gate     const char *mech_name;
577*0Sstevel@tonic-gate 
578*0Sstevel@tonic-gate 	/* best mech additional security layer strength factor */
579*0Sstevel@tonic-gate     sasl_ssf_t max_ssf;
580*0Sstevel@tonic-gate 
581*0Sstevel@tonic-gate 	/* best security flags, as defined in sasl_security_properties_t */
582*0Sstevel@tonic-gate     unsigned security_flags;
583*0Sstevel@tonic-gate 
584*0Sstevel@tonic-gate 	/* features of plugin */
585*0Sstevel@tonic-gate     unsigned features;
586*0Sstevel@tonic-gate 
587*0Sstevel@tonic-gate 	/* global state for mechanism */
588*0Sstevel@tonic-gate     void *glob_context;
589*0Sstevel@tonic-gate 
590*0Sstevel@tonic-gate 	/*
591*0Sstevel@tonic-gate 	 * create a new mechanism handler
592*0Sstevel@tonic-gate 	 *  glob_context  -- global context
593*0Sstevel@tonic-gate 	 *  sparams	  -- server config params
594*0Sstevel@tonic-gate 	 *  challenge	  -- server challenge from previous instance or NULL
595*0Sstevel@tonic-gate 	 *  challen	  -- length of challenge from previous instance or 0
596*0Sstevel@tonic-gate 	 * out:
597*0Sstevel@tonic-gate 	 *  conn_context  -- connection context
598*0Sstevel@tonic-gate 	 *  errinfo	  -- error information
599*0Sstevel@tonic-gate 	 *
600*0Sstevel@tonic-gate 	 * returns:
601*0Sstevel@tonic-gate 	 *  SASL_OK	  -- successfully created mech instance
602*0Sstevel@tonic-gate 	 *  SASL_*	  -- any other server error code
603*0Sstevel@tonic-gate 	 */
604*0Sstevel@tonic-gate     int (*mech_new)(void *glob_context,
605*0Sstevel@tonic-gate 		    sasl_server_params_t *sparams,
606*0Sstevel@tonic-gate 		    const char *challenge,
607*0Sstevel@tonic-gate 		    unsigned challen,
608*0Sstevel@tonic-gate 		    void **conn_context);
609*0Sstevel@tonic-gate 
610*0Sstevel@tonic-gate 	/*
611*0Sstevel@tonic-gate 	 * perform one step in exchange
612*0Sstevel@tonic-gate 	 *
613*0Sstevel@tonic-gate 	 * returns:
614*0Sstevel@tonic-gate 	 *  SASL_OK	  -- success, all done
615*0Sstevel@tonic-gate 	 *  SASL_CONTINUE -- success, one more round trip
616*0Sstevel@tonic-gate 	 *  SASL_*	  -- any other server error code
617*0Sstevel@tonic-gate 	 */
618*0Sstevel@tonic-gate     int (*mech_step)(void *conn_context,
619*0Sstevel@tonic-gate 			sasl_server_params_t *sparams,
620*0Sstevel@tonic-gate 			const char *clientin,
621*0Sstevel@tonic-gate 			unsigned clientinlen,
622*0Sstevel@tonic-gate 			const char **serverout,
623*0Sstevel@tonic-gate 			unsigned *serveroutlen,
624*0Sstevel@tonic-gate 			sasl_out_params_t *oparams);
625*0Sstevel@tonic-gate 
626*0Sstevel@tonic-gate 	/* dispose of a connection state */
627*0Sstevel@tonic-gate     void (*mech_dispose)(void *conn_context, const sasl_utils_t *utils);
628*0Sstevel@tonic-gate 
629*0Sstevel@tonic-gate 	/*
630*0Sstevel@tonic-gate 	 * free global state for mechanism
631*0Sstevel@tonic-gate 	 *  mech_dispose must be called on all mechanisms first
632*0Sstevel@tonic-gate 	 */
633*0Sstevel@tonic-gate     void (*mech_free)(void *glob_context, const sasl_utils_t *utils);
634*0Sstevel@tonic-gate 
635*0Sstevel@tonic-gate 	/*
636*0Sstevel@tonic-gate 	 * set a password (optional)
637*0Sstevel@tonic-gate 	 *  glob_context  -- global context
638*0Sstevel@tonic-gate 	 *  sparams	  -- service, middleware utilities, etc. props ignored
639*0Sstevel@tonic-gate 	 *  user	  -- user name
640*0Sstevel@tonic-gate 	 *  pass	  -- password/passphrase (NULL = disable/remove/delete)
641*0Sstevel@tonic-gate 	 *  passlen	  -- length of password/passphrase
642*0Sstevel@tonic-gate 	 *  oldpass	  -- old password/passphrase (NULL = transition)
643*0Sstevel@tonic-gate 	 *  oldpasslen    -- length of password/passphrase
644*0Sstevel@tonic-gate 	 *  flags	  -- see above
645*0Sstevel@tonic-gate 	 *
646*0Sstevel@tonic-gate 	 * returns:
647*0Sstevel@tonic-gate 	 *  SASL_NOCHANGE -- no change was needed
648*0Sstevel@tonic-gate 	 *  SASL_NOUSER   -- no entry for user
649*0Sstevel@tonic-gate 	 *  SASL_NOVERIFY -- no mechanism compatible entry for user
650*0Sstevel@tonic-gate 	 *  SASL_PWLOCK   -- password locked
651*0Sstevel@tonic-gate 	 *  SASL_DIABLED  -- account disabled
652*0Sstevel@tonic-gate 	 *  etc.
653*0Sstevel@tonic-gate 	 */
654*0Sstevel@tonic-gate     int (*setpass)(void *glob_context,
655*0Sstevel@tonic-gate 		    sasl_server_params_t *sparams,
656*0Sstevel@tonic-gate 		    const char *user,
657*0Sstevel@tonic-gate 		    const char *pass, unsigned passlen,
658*0Sstevel@tonic-gate 		    const char *oldpass, unsigned oldpasslen,
659*0Sstevel@tonic-gate 		    unsigned flags);
660*0Sstevel@tonic-gate 
661*0Sstevel@tonic-gate 	/*
662*0Sstevel@tonic-gate 	 * query which mechanisms are available for user
663*0Sstevel@tonic-gate 	 *  glob_context  -- context
664*0Sstevel@tonic-gate 	 *  sparams	  -- service, middleware utilities, etc. props ignored
665*0Sstevel@tonic-gate 	 *  user	  -- NUL terminated user name
666*0Sstevel@tonic-gate 	 *  maxmech	  -- max number of strings in mechlist (0 = no output)
667*0Sstevel@tonic-gate 	 * output:
668*0Sstevel@tonic-gate 	 *  mechlist	  -- an array of C string pointers, filled in with
669*0Sstevel@tonic-gate 	 *		  mechanism names available to the user
670*0Sstevel@tonic-gate 	 *
671*0Sstevel@tonic-gate 	 * returns:
672*0Sstevel@tonic-gate 	 *  SASL_OK	  -- success
673*0Sstevel@tonic-gate 	 *  SASL_NOMEM    -- not enough memory
674*0Sstevel@tonic-gate 	 *  SASL_FAIL	  -- lower level failure
675*0Sstevel@tonic-gate 	 *  SASL_DISABLED -- account disabled
676*0Sstevel@tonic-gate 	 *  SASL_NOUSER   -- user not found
677*0Sstevel@tonic-gate 	 *  SASL_BUFOVER  -- maxmech is too small
678*0Sstevel@tonic-gate 	 *  SASL_NOVERIFY -- user found, but no mechanisms available
679*0Sstevel@tonic-gate 	 */
680*0Sstevel@tonic-gate     int (*user_query)(void *glob_context,
681*0Sstevel@tonic-gate 		    sasl_server_params_t *sparams,
682*0Sstevel@tonic-gate 		    const char *user,
683*0Sstevel@tonic-gate 		    int maxmech,
684*0Sstevel@tonic-gate 		    const char **mechlist);
685*0Sstevel@tonic-gate 
686*0Sstevel@tonic-gate 	/*
687*0Sstevel@tonic-gate 	 * perform precalculations during a network round-trip
688*0Sstevel@tonic-gate 	 *  or idle period.  conn_context may be NULL (optional)
689*0Sstevel@tonic-gate 	 *  returns 1 if action taken, 0 if no action taken
690*0Sstevel@tonic-gate 	 */
691*0Sstevel@tonic-gate     int (*idle)(void *glob_context,
692*0Sstevel@tonic-gate 		void *conn_context,
693*0Sstevel@tonic-gate 		sasl_server_params_t *sparams);
694*0Sstevel@tonic-gate 
695*0Sstevel@tonic-gate 	/*
696*0Sstevel@tonic-gate 	 * check if mechanism is available
697*0Sstevel@tonic-gate 	 * TODO - Is this correct?
698*0Sstevel@tonic-gate 	 *  optional--if NULL, mechanism is available based on ENABLE=
699*0Sstevel@tonic-gate 	 * in config
700*0Sstevel@tonic-gate 	 *
701*0Sstevel@tonic-gate 	 *  If this routine sets conn_context to a non-NULL value, then the call
702*0Sstevel@tonic-gate 	 *  to mech_new will be skipped.  This should not be done unless
703*0Sstevel@tonic-gate 	 *  there's a significant performance benefit, since it can cause
704*0Sstevel@tonic-gate 	 *  additional memory allocation in SASL core code to keep track of
705*0Sstevel@tonic-gate 	 *  contexts potentially for multiple mechanisms.
706*0Sstevel@tonic-gate 	 *
707*0Sstevel@tonic-gate 	 *  This is called by the first call to sasl_listmech() for a
708*0Sstevel@tonic-gate 	 *  given connection context, thus for a given protocol it may
709*0Sstevel@tonic-gate 	 *  never be called.  Note that if mech_avail returns SASL_NOMECH,
710*0Sstevel@tonic-gate 	 *  then that mechanism is considered disabled for the remainder
711*0Sstevel@tonic-gate 	 *  of the session.
712*0Sstevel@tonic-gate 	 *
713*0Sstevel@tonic-gate 	 *  returns SASL_OK on success,
714*0Sstevel@tonic-gate 	 *	    SASL_NOMECH if mech disabled
715*0Sstevel@tonic-gate 	 */
716*0Sstevel@tonic-gate     int (*mech_avail)(void *glob_context,
717*0Sstevel@tonic-gate 		    sasl_server_params_t *sparams,
718*0Sstevel@tonic-gate 		    void **conn_context);
719*0Sstevel@tonic-gate 
720*0Sstevel@tonic-gate 	/* for additions which don't require a version upgrade; set to 0 */
721*0Sstevel@tonic-gate     int (*spare_fptr2)();
722*0Sstevel@tonic-gate } sasl_server_plug_t;
723*0Sstevel@tonic-gate 
724*0Sstevel@tonic-gate #define	SASL_SERVER_PLUG_VERSION 4
725*0Sstevel@tonic-gate 
726*0Sstevel@tonic-gate /*
727*0Sstevel@tonic-gate  * plug-in entry point:
728*0Sstevel@tonic-gate  *  utils         -- utility callback functions
729*0Sstevel@tonic-gate  *  plugname      -- name of plug-in (may be NULL)
730*0Sstevel@tonic-gate  *  max_version   -- highest server plug version supported
731*0Sstevel@tonic-gate  * returns:
732*0Sstevel@tonic-gate  *  out_version   -- server plug-in version of result
733*0Sstevel@tonic-gate  *  pluglist      -- list of mechanism plug-ins
734*0Sstevel@tonic-gate  *  plugcount     -- number of mechanism plug-ins
735*0Sstevel@tonic-gate  * results:
736*0Sstevel@tonic-gate  *  SASL_OK       -- success
737*0Sstevel@tonic-gate  *  SASL_NOMEM    -- failure
738*0Sstevel@tonic-gate  *  SASL_BADVERS  -- max_version too small
739*0Sstevel@tonic-gate  *  SASL_BADPARAM -- bad config string
740*0Sstevel@tonic-gate  *  ...
741*0Sstevel@tonic-gate  */
742*0Sstevel@tonic-gate typedef int sasl_server_plug_init_t(const sasl_utils_t *utils,
743*0Sstevel@tonic-gate 				    int max_version,
744*0Sstevel@tonic-gate 				    int *out_version,
745*0Sstevel@tonic-gate 				    sasl_server_plug_t **pluglist,
746*0Sstevel@tonic-gate 				    int *plugcount);
747*0Sstevel@tonic-gate 
748*0Sstevel@tonic-gate /*
749*0Sstevel@tonic-gate  * add a server plug-in
750*0Sstevel@tonic-gate  */
751*0Sstevel@tonic-gate LIBSASL_API int sasl_server_add_plugin(const char *plugname,
752*0Sstevel@tonic-gate 				sasl_server_plug_init_t *splugfunc);
753*0Sstevel@tonic-gate 
754*0Sstevel@tonic-gate /*
755*0Sstevel@tonic-gate  * user canonicalization plug-in -- added cjn 1999-09-29
756*0Sstevel@tonic-gate  */
757*0Sstevel@tonic-gate 
758*0Sstevel@tonic-gate typedef struct sasl_canonuser {
759*0Sstevel@tonic-gate 	/* optional features of plugin (set to 0) */
760*0Sstevel@tonic-gate     int features;
761*0Sstevel@tonic-gate 
762*0Sstevel@tonic-gate 	/* spare integer (set to 0) */
763*0Sstevel@tonic-gate     int spare_int1;
764*0Sstevel@tonic-gate 
765*0Sstevel@tonic-gate 	/* global state for plugin */
766*0Sstevel@tonic-gate     void *glob_context;
767*0Sstevel@tonic-gate 
768*0Sstevel@tonic-gate 	/* name of plugin */
769*0Sstevel@tonic-gate     char *name;
770*0Sstevel@tonic-gate 
771*0Sstevel@tonic-gate 	/* free global state for plugin */
772*0Sstevel@tonic-gate     void (*canon_user_free)(void *glob_context, const sasl_utils_t *utils);
773*0Sstevel@tonic-gate 
774*0Sstevel@tonic-gate 	/*
775*0Sstevel@tonic-gate 	 * canonicalize a username
776*0Sstevel@tonic-gate 	 *  glob_context    -- global context from this structure
777*0Sstevel@tonic-gate 	 *  sparams	    -- server params, note user_realm&propctx elements
778*0Sstevel@tonic-gate 	 *  user	    -- user to login as (may not be NUL terminated)
779*0Sstevel@tonic-gate 	 *  len		    -- length of user name (0 = strlen(user))
780*0Sstevel@tonic-gate 	 *  flags	    -- for SASL_CU_* flags
781*0Sstevel@tonic-gate 	 *  out		    -- buffer to copy user name
782*0Sstevel@tonic-gate 	 *  out_max	    -- max length of user name
783*0Sstevel@tonic-gate 	 *  out_len	    -- set to length of user name
784*0Sstevel@tonic-gate 	 *
785*0Sstevel@tonic-gate 	 *  note that the output buffers MAY be the same as the input buffers.
786*0Sstevel@tonic-gate 	 *
787*0Sstevel@tonic-gate 	 * returns
788*0Sstevel@tonic-gate 	 *  SASL_OK	    on success
789*0Sstevel@tonic-gate 	 *  SASL_BADPROT    username contains invalid character
790*0Sstevel@tonic-gate 	 */
791*0Sstevel@tonic-gate     int (*canon_user_server)(void *glob_context,
792*0Sstevel@tonic-gate 			    sasl_server_params_t *sparams,
793*0Sstevel@tonic-gate 			    const char *user, unsigned len,
794*0Sstevel@tonic-gate 			    unsigned flags,
795*0Sstevel@tonic-gate 			    char *out,
796*0Sstevel@tonic-gate 			    unsigned out_umax, unsigned *out_ulen);
797*0Sstevel@tonic-gate 
798*0Sstevel@tonic-gate     int (*canon_user_client)(void *glob_context,
799*0Sstevel@tonic-gate 			    sasl_client_params_t *cparams,
800*0Sstevel@tonic-gate 			    const char *user, unsigned len,
801*0Sstevel@tonic-gate 			    unsigned flags,
802*0Sstevel@tonic-gate 			    char *out,
803*0Sstevel@tonic-gate 			    unsigned out_max, unsigned *out_len);
804*0Sstevel@tonic-gate 
805*0Sstevel@tonic-gate 	/* for additions which don't require a version upgrade; set to 0 */
806*0Sstevel@tonic-gate     int (*spare_fptr1)();
807*0Sstevel@tonic-gate     int (*spare_fptr2)();
808*0Sstevel@tonic-gate     int (*spare_fptr3)();
809*0Sstevel@tonic-gate } sasl_canonuser_plug_t;
810*0Sstevel@tonic-gate 
811*0Sstevel@tonic-gate #define	SASL_CANONUSER_PLUG_VERSION 5
812*0Sstevel@tonic-gate 
813*0Sstevel@tonic-gate /*
814*0Sstevel@tonic-gate  * default name for canonuser plug-in entry point is "sasl_canonuser_init"
815*0Sstevel@tonic-gate  *  similar to sasl_server_plug_init model, except only returns one
816*0Sstevel@tonic-gate  *  sasl_canonuser_plug_t structure;
817*0Sstevel@tonic-gate  */
818*0Sstevel@tonic-gate typedef int sasl_canonuser_init_t(const sasl_utils_t *utils,
819*0Sstevel@tonic-gate 				int max_version,
820*0Sstevel@tonic-gate 				int *out_version,
821*0Sstevel@tonic-gate 				sasl_canonuser_plug_t **plug,
822*0Sstevel@tonic-gate 				const char *plugname);
823*0Sstevel@tonic-gate 
824*0Sstevel@tonic-gate /* add a canonuser plugin */
825*0Sstevel@tonic-gate LIBSASL_API int sasl_canonuser_add_plugin(const char *plugname,
826*0Sstevel@tonic-gate 				sasl_canonuser_init_t *canonuserfunc);
827*0Sstevel@tonic-gate 
828*0Sstevel@tonic-gate /*
829*0Sstevel@tonic-gate  * auxiliary property plug-in -- added cjn 1999-09-29
830*0Sstevel@tonic-gate  */
831*0Sstevel@tonic-gate 
832*0Sstevel@tonic-gate typedef struct sasl_auxprop_plug {
833*0Sstevel@tonic-gate 	/* optional features of plugin (none defined yet, set to 0) */
834*0Sstevel@tonic-gate     int features;
835*0Sstevel@tonic-gate 
836*0Sstevel@tonic-gate 	/* spare integer, must be set to 0 */
837*0Sstevel@tonic-gate     int spare_int1;
838*0Sstevel@tonic-gate 
839*0Sstevel@tonic-gate 	/* global state for plugin */
840*0Sstevel@tonic-gate     void *glob_context;
841*0Sstevel@tonic-gate 
842*0Sstevel@tonic-gate 	/* free global state for plugin (OPTIONAL) */
843*0Sstevel@tonic-gate     void (*auxprop_free)(void *glob_context, const sasl_utils_t *utils);
844*0Sstevel@tonic-gate 
845*0Sstevel@tonic-gate 	/*
846*0Sstevel@tonic-gate 	 * fill in fields of an auxiliary property context
847*0Sstevel@tonic-gate 	 *  last element in array has id of SASL_AUX_END
848*0Sstevel@tonic-gate 	 *  elements with non-0 len should be ignored.
849*0Sstevel@tonic-gate 	 */
850*0Sstevel@tonic-gate     void (*auxprop_lookup)(void *glob_context,
851*0Sstevel@tonic-gate 			    sasl_server_params_t *sparams,
852*0Sstevel@tonic-gate 			    unsigned flags,
853*0Sstevel@tonic-gate 			    const char *user, unsigned ulen);
854*0Sstevel@tonic-gate 
855*0Sstevel@tonic-gate 	/* name of the auxprop plugin */
856*0Sstevel@tonic-gate     char *name;
857*0Sstevel@tonic-gate 
858*0Sstevel@tonic-gate 	/* for additions which don't require a version upgrade; set to 0 */
859*0Sstevel@tonic-gate     void (*spare_fptr1)();
860*0Sstevel@tonic-gate } sasl_auxprop_plug_t;
861*0Sstevel@tonic-gate 
862*0Sstevel@tonic-gate /* auxprop lookup flags */
863*0Sstevel@tonic-gate #define	SASL_AUXPROP_OVERRIDE 0x01  /* if clear, ignore auxiliary properties */
864*0Sstevel@tonic-gate 				    /* with non-zero len field.  If set, */
865*0Sstevel@tonic-gate 				    /* override value of those properties */
866*0Sstevel@tonic-gate #define	SASL_AUXPROP_AUTHZID  0x02  /* if clear, we are looking up the */
867*0Sstevel@tonic-gate 				    /* authid flags (prefixed with *), */
868*0Sstevel@tonic-gate 				    /* otherwise we are looking up the */
869*0Sstevel@tonic-gate 				    /* authzid flags (no prefix) */
870*0Sstevel@tonic-gate 
871*0Sstevel@tonic-gate #define	SASL_AUXPROP_PLUG_VERSION 4
872*0Sstevel@tonic-gate 
873*0Sstevel@tonic-gate /*
874*0Sstevel@tonic-gate  * default name for auxprop plug-in entry point is "sasl_auxprop_init"
875*0Sstevel@tonic-gate  *  similar to sasl_server_plug_init model, except only returns one
876*0Sstevel@tonic-gate  *  sasl_auxprop_plug_t structure;
877*0Sstevel@tonic-gate  */
878*0Sstevel@tonic-gate typedef int sasl_auxprop_init_t(const sasl_utils_t *utils,
879*0Sstevel@tonic-gate 				int max_version,
880*0Sstevel@tonic-gate 				int *out_version,
881*0Sstevel@tonic-gate 				sasl_auxprop_plug_t **plug,
882*0Sstevel@tonic-gate 				const char *plugname);
883*0Sstevel@tonic-gate 
884*0Sstevel@tonic-gate /* add an auxiliary property plug-in */
885*0Sstevel@tonic-gate LIBSASL_API int sasl_auxprop_add_plugin(const char *plugname,
886*0Sstevel@tonic-gate 					sasl_auxprop_init_t *auxpropfunc);
887*0Sstevel@tonic-gate 
888*0Sstevel@tonic-gate #ifdef	__cplusplus
889*0Sstevel@tonic-gate }
890*0Sstevel@tonic-gate #endif
891*0Sstevel@tonic-gate 
892*0Sstevel@tonic-gate #endif /* _SASL_SASLPLUG_H */
893