xref: /titanic_44/usr/src/lib/libsasl/lib/saslint.h (revision 694c35faa87b858ecdadfe4fc592615f4eefbb07)
1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /* saslint.h - internal SASL library definitions
7  * Rob Siemborski
8  * Tim Martin
9  * $Id: saslint.h,v 1.48 2003/04/16 19:36:01 rjs3 Exp $
10  */
11 /*
12  * Copyright (c) 1998-2003 Carnegie Mellon University.  All rights reserved.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  *
18  * 1. Redistributions of source code must retain the above copyright
19  *    notice, this list of conditions and the following disclaimer.
20  *
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in
23  *    the documentation and/or other materials provided with the
24  *    distribution.
25  *
26  * 3. The name "Carnegie Mellon University" must not be used to
27  *    endorse or promote products derived from this software without
28  *    prior written permission. For permission or any other legal
29  *    details, please contact
30  *      Office of Technology Transfer
31  *      Carnegie Mellon University
32  *      5000 Forbes Avenue
33  *      Pittsburgh, PA  15213-3890
34  *      (412) 268-4387, fax: (412) 268-7395
35  *      tech-transfer@andrew.cmu.edu
36  *
37  * 4. Redistributions of any form whatsoever must retain the following
38  *    acknowledgment:
39  *    "This product includes software developed by Computing Services
40  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
41  *
42  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
43  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
44  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
45  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
46  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
47  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
48  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
49  */
50 
51 #ifndef SASLINT_H
52 #define SASLINT_H
53 
54 #include <config.h>
55 #include "sasl.h"
56 #include "saslplug.h"
57 #include "saslutil.h"
58 #include "prop.h"
59 
60 /* #define'd constants */
61 #define CANON_BUF_SIZE 256
62 
63 /* Error Handling Foo */
64 /* Helpful Hints:
65  *  -Error strings are set as soon as possible (first function in stack trace
66  *   with a pointer to the sasl_conn_t.
67  *  -Error codes are set as late as possible (only in the sasl api functions),
68  *   thoug "as often as possible" also comes to mind to ensure correctness
69  *  -Errors from calls to _buf_alloc, _sasl_strdup, etc are assumed to be
70  *   memory errors.
71  *  -Only errors (error codes < SASL_OK) should be remembered
72  */
73 #define RETURN(conn, val) { if(conn && (val) < SASL_OK) \
74                                (conn)->error_code = (val); \
75                             return (val); }
76 #if !defined _SUN_SDK || defined  DEBUG
77 #define MEMERROR(conn) {\
78     if(conn) sasl_seterror( (conn), 0, \
79                    "Out of Memory in " __FILE__ " near line %d", __LINE__ ); \
80     RETURN(conn, SASL_NOMEM) }
81 #define PARAMERROR(conn) {\
82     if(conn) sasl_seterror( (conn), SASL_NOLOG, \
83                   "Parameter error in " __FILE__ " near line %d", __LINE__ ); \
84     RETURN(conn, SASL_BADPARAM) }
85 #define INTERROR(conn, val) {\
86     if(conn) sasl_seterror( (conn), 0, \
87                    "Internal Error %d in " __FILE__ " near line %d", (val),\
88 		   __LINE__ ); \
89     RETURN(conn, (val)) }
90 #else
91 #define MEMERROR(conn) {\
92     if(conn) _sasl_log((conn), SASL_LOG_WARN, "Out of Memory"); \
93     RETURN(conn, SASL_NOMEM) }
94 #define PARAMERROR(conn) {\
95     if(conn) _sasl_log((conn), SASL_LOG_WARN, "Parameter error"); \
96     RETURN(conn, SASL_BADPARAM) }
97 #define INTERROR(conn, val) {\
98     if(conn) _sasl_log((conn), SASL_LOG_ERR, "Internal Error: %d", (val)); \
99     RETURN(conn, (val)) }
100 #endif
101 
102 #ifndef PATH_MAX
103 # ifdef WIN32
104 #  define PATH_MAX MAX_PATH
105 # else
106 #  ifdef _POSIX_PATH_MAX
107 #   define PATH_MAX _POSIX_PATH_MAX
108 #  else
109 #   define PATH_MAX 1024         /* arbitrary; probably big enough will
110                                   * probably only be 256+64 on
111                                   * pre-posix machines */
112 #  endif /* _POSIX_PATH_MAX */
113 # endif /* WIN32 */
114 #endif
115 
116 /* : Define directory delimiter in SASL_PATH variable */
117 #ifdef WIN32
118 #define PATHS_DELIMITER	';'
119 #else
120 #define PATHS_DELIMITER	':'
121 #endif
122 
123 /* Datatype Definitions */
124 typedef struct {
125   const sasl_callback_t *callbacks;
126   const char *appname;
127 #ifdef _SUN_SDK_
128   struct _sasl_global_context_s *gctx;
129 #endif /* _SUN_SDK_ */
130 } sasl_global_callbacks_t;
131 
132 typedef struct _sasl_external_properties
133 {
134     sasl_ssf_t ssf;
135     char *auth_id;
136 } _sasl_external_properties_t;
137 
138 typedef struct sasl_string_list
139 {
140     const char *d;
141     struct sasl_string_list *next;
142 } sasl_string_list_t;
143 
144 typedef struct buffer_info
145 {
146     char *data;
147     size_t curlen;
148     size_t reallen;
149 } buffer_info_t;
150 
151 #ifdef _SUN_SDK_
152 typedef int add_plugin_t(struct _sasl_global_context_s *gctx,
153 			const char *, void *);
154 #else
155 typedef int add_plugin_t(const char *, void *);
156 #endif /* _SUN_SDK_ */
157 
158 typedef struct add_plugin_list
159 {
160     const char *entryname;
161     add_plugin_t *add_plugin;
162 } add_plugin_list_t;
163 
164 enum Sasl_conn_type { SASL_CONN_UNKNOWN = 0,
165 		      SASL_CONN_SERVER = 1,
166                       SASL_CONN_CLIENT = 2 };
167 
168 struct sasl_conn {
169   enum Sasl_conn_type type;
170 
171   void (*destroy_conn)(sasl_conn_t *); /* destroy function */
172 
173   char *service;
174 
175   unsigned int flags;  /* flags passed to sasl_*_new */
176 
177   /* IP information.  A buffer of size 52 is adequate for this in its
178      longest format (see sasl.h) */
179   int got_ip_local, got_ip_remote;
180   char iplocalport[NI_MAXHOST + NI_MAXSERV];
181   char ipremoteport[NI_MAXHOST + NI_MAXSERV];
182 
183   void *context;
184   sasl_out_params_t oparams;
185 
186   sasl_security_properties_t props;
187   _sasl_external_properties_t external;
188 
189 #ifndef _SUN_SDK_
190   sasl_secret_t *secret;
191 #endif /* !_SUN_SDK_ */
192 
193   int (*idle_hook)(sasl_conn_t *conn);
194   const sasl_callback_t *callbacks;
195   const sasl_global_callbacks_t *global_callbacks; /* global callbacks
196 						    * connection */
197   char *serverFQDN;
198 
199   /* Pointers to memory that we are responsible for */
200   buffer_info_t *encode_buf;
201 
202   int error_code;
203   char *error_buf, *errdetail_buf;
204   size_t error_buf_len, errdetail_buf_len;
205   char *mechlist_buf;
206   size_t mechlist_buf_len;
207 
208   char *decode_buf;
209 
210   char user_buf[CANON_BUF_SIZE+1], authid_buf[CANON_BUF_SIZE+1];
211 
212 #ifdef _SUN_SDK_
213   struct _sasl_global_context_s *gctx;
214 #ifdef _INTEGRATED_SOLARIS_
215   int sun_reg;
216 #endif /* _INTEGRATED_SOLARIS_ */
217 #endif /* _SUN_SDK_ */
218 };
219 
220 #ifdef _SUN_SDK_
221 /* track changes in file system */
222 typedef struct _sasl_path_info {
223     char *path;
224     time_t last_changed;
225     struct _sasl_path_info *next;
226 } _sasl_path_info_t;
227 #endif /* _SUN_SDK_ */
228 
229 /* Server Conn Type Information */
230 
231 typedef struct mechanism
232 {
233     int version;
234     int condition; /* set to SASL_NOUSER if no available users;
235 		      set to SASL_CONTINUE if delayed plugn loading */
236     char *plugname; /* for AUTHSOURCE tracking */
237 #ifdef _SUN_SDK_
238 #ifdef _INTEGRATED_SOLARIS_
239     int sun_reg;
240 #endif /* _INTEGRATED_SOLARIS_ */
241     sasl_server_plug_t *plug;
242 	/*
243 	 * The global context needs to be stored with separately from the
244 	 * the plugin because it will be overwritten when the plugin is
245 	 * relloaded
246 	 */
247     void *glob_context;
248     struct mechanism *next;
249 #else
250     const sasl_server_plug_t *plug;
251     struct mechanism *next;
252     char *f;       /* where should i load the mechanism from? */
253 #endif /* _SUN_SDK_ */
254 } mechanism_t;
255 
256 typedef struct mech_list {
257   const sasl_utils_t *utils;  /* gotten from plug_init */
258 
259   void *mutex;            /* mutex for this data */
260   mechanism_t *mech_list; /* list of mechanisms */
261   int mech_length;       /* number of mechanisms */
262 } mech_list_t;
263 
264 typedef struct context_list
265 {
266     mechanism_t *mech;
267     void *context;     /* if NULL, this mech is disabled for this connection
268 			* otherwise, use this context instead of a call
269 			* to mech_new */
270     struct context_list *next;
271 } context_list_t;
272 
273 typedef struct sasl_server_conn {
274     sasl_conn_t base; /* parts common to server + client */
275 
276     char *user_realm; /* domain the user authenticating is in */
277     int sent_last; /* Have we already done the last send? */
278     int authenticated;
279     mechanism_t *mech; /* mechanism trying to use */
280     sasl_server_params_t *sparams;
281     context_list_t *mech_contexts;
282 } sasl_server_conn_t;
283 
284 /* Client Conn Type Information */
285 
286 typedef struct cmechanism
287 {
288     int version;
289 
290     char *plugname;
291 #ifdef _SUN_SDK_
292 #ifdef _INTEGRATED_SOLARIS_
293     int sun_reg;
294 #endif /* _INTEGRATED_SOLARIS_ */
295 	/*
296 	 * The global context needs to be stored with separately from the
297 	 * the plugin because it will be overwritten when the plugin is
298 	 * relloaded
299 	 */
300     void *glob_context;
301     sasl_client_plug_t *plug;
302 #else
303     const sasl_client_plug_t *plug;
304 #endif /* _SUN_SDK_ */
305 
306     struct cmechanism *next;
307 } cmechanism_t;
308 
309 typedef struct cmech_list {
310   const sasl_utils_t *utils;
311 
312   void *mutex;            /* mutex for this data */
313   cmechanism_t *mech_list; /* list of mechanisms */
314   int mech_length;       /* number of mechanisms */
315 
316 } cmech_list_t;
317 
318 typedef struct sasl_client_conn {
319   sasl_conn_t base; /* parts common to server + client */
320 
321   cmechanism_t *mech;
322   sasl_client_params_t *cparams;
323 
324   char *clientFQDN;
325 
326 } sasl_client_conn_t;
327 
328 typedef struct sasl_allocation_utils {
329   sasl_malloc_t *malloc;
330   sasl_calloc_t *calloc;
331   sasl_realloc_t *realloc;
332   sasl_free_t *free;
333 } sasl_allocation_utils_t;
334 
335 typedef struct sasl_mutex_utils {
336   sasl_mutex_alloc_t *alloc;
337   sasl_mutex_lock_t *lock;
338   sasl_mutex_unlock_t *unlock;
339   sasl_mutex_free_t *free;
340 } sasl_mutex_utils_t;
341 
342 typedef struct sasl_log_utils_s {
343   sasl_log_t *log;
344 } sasl_log_utils_t;
345 
346 #ifdef _SUN_SDK_
347 /*
348  * The following structure contains the global state for libsasl */
349 typedef struct _sasl_global_context_s {
350     int				sasl_server_active;
351 				/* sasl server init'ed */
352     mech_list_t			*mechlist;
353 				/* list of server mechs */
354     _sasl_path_info_t		*splug_path_info;
355 				/* path info for server plugins */
356     sasl_global_callbacks_t	server_global_callbacks;
357 				/* callbacks for sasl_server_init */
358     int				(*sasl_server_cleanup_hook)
359 					(struct _sasl_global_context_s *gctx);
360 				/* entry point to clean up sasl server */
361     int				(*sasl_server_idle_hook)(sasl_conn_t *conn);
362 				/* entry point for sasl server idle */
363 
364     cmech_list_t		*cmechlist;
365 				/* list of client mechs */
366     _sasl_path_info_t		*cplug_path_info;
367 				/* path info for client plugins */
368     sasl_global_callbacks_t	client_global_callbacks;
369 				/* callbacks for sasl_client_init */
370     int				sasl_client_active;
371 				/* sasl client init'ed */
372     int				(*sasl_client_cleanup_hook)
373 					(struct _sasl_global_context_s *gctx);
374 				/* entry point to clean up sasl client */
375     int				(*sasl_client_idle_hook)(sasl_conn_t *conn);
376 				/* entry point for sasl client idle */
377 
378     const sasl_utils_t		*sasl_server_global_utils;
379 				/* sasl server global utils */
380     const sasl_utils_t		*sasl_canonusr_global_utils;
381 				/* sasl global utils for canonusr plugin */
382 
383     void			*configlist;
384 				/* Configuration key value pair data list */
385     int				nconfiglist;
386 				/* number of items in configlist */
387     char			*config_path;
388 				/* last read config path */
389     time_t			config_last_read;
390 				/* last time config read */
391 
392     void			*auxprop_head;
393 				/* Head of auxprop plugin list */
394     void			*canonuser_head;
395 				/* Head of canonusr plugin list */
396     char			**global_mech_list;
397 				/* Global list of mechanisms */
398     void			*free_mutex;
399 				/* sasl_done()/sasl_dispose() mutex */
400     sasl_allocation_utils_t     sasl_allocation_utils;
401 				/* malloc et al */
402     sasl_mutex_utils_t		sasl_mutex_utils;
403 				/* mutex_alloc et al */
404     void			*lib_list_head;
405 				/* list of dynamic libs opened */
406 }_sasl_global_context_t;
407 #endif /* _SUN_SDK_ */
408 
409 typedef int sasl_plaintext_verifier(sasl_conn_t *conn,
410 				    const char *userid,
411 				    const char *passwd,
412 				    const char *service,
413 				    const char *user_realm);
414 
415 struct sasl_verify_password_s {
416     char *name;
417     sasl_plaintext_verifier *verify;
418 };
419 
420 /*
421  * globals & constants
422  */
423 /*
424  * common.c
425  */
426 #ifndef _SUN_SDK_
427 LIBSASL_API const sasl_utils_t *sasl_global_utils;
428 
429 extern int (*_sasl_client_idle_hook)(sasl_conn_t *conn);
430 extern int (*_sasl_server_idle_hook)(sasl_conn_t *conn);
431 
432 /* These return SASL_OK if we've actually finished cleanup,
433  * SASL_NOTINIT if that part of the library isn't inited, and
434  * SASL_CONTINUE if we need to call them again */
435 extern int (*_sasl_client_cleanup_hook)(void);
436 extern int (*_sasl_server_cleanup_hook)(void);
437 
438 extern sasl_allocation_utils_t _sasl_allocation_utils;
439 extern sasl_mutex_utils_t _sasl_mutex_utils;
440 #endif /* !_SUN_SDK_ */
441 
442 /*
443  * checkpw.c
444  */
445 extern struct sasl_verify_password_s _sasl_verify_password[];
446 
447 /*
448  * server.c
449  */
450 /* (this is a function call to ensure this is read-only to the outside) */
451 #ifdef _SUN_SDK_
452 extern int _is_sasl_server_active(_sasl_global_context_t *gctx);
453 #else
454 extern int _is_sasl_server_active(void);
455 #endif /* _SUN_SDK_ */
456 
457 /*
458  * Allocation and Mutex utility macros
459  */
460 #ifdef _SUN_SDK_
461 #define sasl_ALLOC(__size__) (gctx->sasl_allocation_utils.malloc((__size__)))
462 #define sasl_CALLOC(__nelem__, __size__) \
463         (gctx->sasl_allocation_utils.calloc((__nelem__), (__size__)))
464 #define sasl_REALLOC(__ptr__, __size__) \
465         (gctx->sasl_allocation_utils.realloc((__ptr__), (__size__)))
466 #define sasl_FREE(__ptr__) (gctx->sasl_allocation_utils.free((__ptr__)))
467 #define sasl_sun_ALLOC(__size__) (malloc((__size__)))
468 #define sasl_sun_CALLOC(__nelem__, __size__) (calloc((__nelem__), (__size__)))
469 #define sasl_sun_REALLOC(__ptr__, __size__) (realloc((__ptr__), (__size__)))
470 #define sasl_sun_FREE(__ptr__) (free((__ptr__)))
471 
472 #define sasl_MUTEX_ALLOC() (gctx->sasl_mutex_utils.alloc())
473 #define sasl_MUTEX_LOCK(__mutex__) (gctx->sasl_mutex_utils.lock((__mutex__)))
474 #define sasl_MUTEX_UNLOCK(__mutex__) \
475 	(gctx->sasl_mutex_utils.unlock((__mutex__)))
476 #define sasl_MUTEX_FREE(__mutex__) (gctx->sasl_mutex_utils.free((__mutex__)))
477 #else
478 #define sasl_ALLOC(__size__) (_sasl_allocation_utils.malloc((__size__)))
479 #define sasl_CALLOC(__nelem__, __size__) \
480 	(_sasl_allocation_utils.calloc((__nelem__), (__size__)))
481 #define sasl_REALLOC(__ptr__, __size__) \
482 	(_sasl_allocation_utils.realloc((__ptr__), (__size__)))
483 #define sasl_FREE(__ptr__) (_sasl_allocation_utils.free((__ptr__)))
484 
485 #define sasl_MUTEX_ALLOC() (_sasl_mutex_utils.alloc())
486 #define sasl_MUTEX_LOCK(__mutex__) (_sasl_mutex_utils.lock((__mutex__)))
487 #define sasl_MUTEX_UNLOCK(__mutex__) (_sasl_mutex_utils.unlock((__mutex__)))
488 #define sasl_MUTEX_FREE(__mutex__) \
489 	(_sasl_mutex_utils.free((__mutex__)))
490 #endif /* _SUN_SDK_ */
491 
492 /* function prototypes */
493 /*
494  * dlopen.c and staticopen.c
495  */
496 /*
497  * The differences here are:
498  * _sasl_load_plugins loads all plugins from all files
499  * _sasl_get_plugin loads the LIBRARY for an individual file
500  * _sasl_done_with_plugins frees the LIBRARIES loaded by the above 2
501  * _sasl_locate_entry locates an entrypoint in a given library
502  */
503 #ifdef _SUN_SDK_
504 extern int _sasl_load_plugins(_sasl_global_context_t *gctx,
505 			      int server,
506                               const add_plugin_list_t *entrypoints,
507                               const sasl_callback_t *getpath_callback,
508                               const sasl_callback_t *verifyfile_callback);
509 
510 extern int _sasl_get_plugin(_sasl_global_context_t *gctx,
511                             const char *file,
512                             const sasl_callback_t *verifyfile_cb,
513                             void **libraryptr);
514 extern int _sasl_locate_entry(void *library, const char *entryname,
515                               void **entry_point);
516 extern int _sasl_done_with_plugins(_sasl_global_context_t *gctx);
517 #else
518 extern int _sasl_load_plugins(const add_plugin_list_t *entrypoints,
519 			       const sasl_callback_t *getpath_callback,
520 			       const sasl_callback_t *verifyfile_callback);
521 extern int _sasl_get_plugin(const char *file,
522 			    const sasl_callback_t *verifyfile_cb,
523 			    void **libraryptr);
524 extern int _sasl_locate_entry(void *library, const char *entryname,
525                               void **entry_point);
526 extern int _sasl_done_with_plugins();
527 #endif /* _SUN_SDK_ */
528 
529 
530 /*
531  * common.c
532  */
533 extern const sasl_callback_t *
534 _sasl_find_getpath_callback(const sasl_callback_t *callbacks);
535 
536 extern const sasl_callback_t *
537 _sasl_find_verifyfile_callback(const sasl_callback_t *callbacks);
538 
539 #ifdef _SUN_SDK_
540 extern const sasl_callback_t *
541 _sasl_find_getconf_callback(const sasl_callback_t *callbacks);
542 
543 extern int _sasl_common_init(_sasl_global_context_t *gctx,
544 			     sasl_global_callbacks_t *global_callbacks,
545 			     int server);
546 #else
547 extern int _sasl_common_init(sasl_global_callbacks_t *global_callbacks);
548 #endif /* _SUN_SDK_ */
549 
550 extern int _sasl_conn_init(sasl_conn_t *conn,
551 			   const char *service,
552 			   unsigned int flags,
553 			   enum Sasl_conn_type type,
554 			   int (*idle_hook)(sasl_conn_t *conn),
555 			   const char *serverFQDN,
556 			   const char *iplocalport,
557 			   const char *ipremoteport,
558 			   const sasl_callback_t *callbacks,
559 			   const sasl_global_callbacks_t *global_callbacks);
560 extern void _sasl_conn_dispose(sasl_conn_t *conn);
561 
562 #ifdef _SUN_SDK_
563 extern sasl_utils_t *
564 _sasl_alloc_utils(_sasl_global_context_t *gctx, sasl_conn_t *conn,
565 		  sasl_global_callbacks_t *global_callbacks);
566 #else
567 extern sasl_utils_t *
568 _sasl_alloc_utils(sasl_conn_t *conn,
569 		  sasl_global_callbacks_t *global_callbacks);
570 #endif /* _SUN_SDK_ */
571 extern int _sasl_free_utils(const sasl_utils_t ** utils);
572 
573 extern int
574 _sasl_getcallback(sasl_conn_t * conn,
575 		  unsigned long callbackid,
576 		  int (**pproc)(),
577 		  void **pcontext);
578 
579 extern void
580 _sasl_log(sasl_conn_t *conn,
581 	  int level,
582 	  const char *fmt,
583 	  ...);
584 
585 #ifdef _SUN_SDK_
586 extern void
587 __sasl_log(const _sasl_global_context_t *gctx,
588 	   const sasl_callback_t *callbacks,
589 	   int level,
590 	   const char *fmt,
591 	   ...);
592 #endif /* _SUN_SDK_ */
593 void _sasl_get_errorbuf(sasl_conn_t *conn, char ***bufhdl, size_t **lenhdl);
594 #ifdef _SUN_SDK_
595 int __sasl_add_string(const _sasl_global_context_t *gctx, char **out,
596                       size_t *alloclen,
597                       size_t *outlen, const char *add);
598 
599 #define _sasl_add_string(out, alloclen, outlen, add) \
600 	__sasl_add_string(gctx, out, alloclen, outlen, add)
601 
602 /* More Generic Utilities in common.c */
603 #define _sasl_strdup(in, out, outlen) \
604 	__sasl_strdup(gctx, in, out, outlen)
605 extern int __sasl_strdup(const _sasl_global_context_t *gctx, const char *in,
606                         char **out, size_t *outlen);
607 
608 /* Basically a conditional call to realloc(), if we need more */
609 int __buf_alloc(const _sasl_global_context_t *gctx, char **rwbuf,
610 	size_t *curlen, size_t newlen);
611 #define _buf_alloc(rwbuf, curlen, newlen) \
612 	__buf_alloc(gctx, rwbuf, curlen, newlen)
613 #else
614 int _sasl_add_string(char **out, size_t *alloclen,
615 		     size_t *outlen, const char *add);
616 
617 /* More Generic Utilities in common.c */
618 extern int _sasl_strdup(const char *in, char **out, size_t *outlen);
619 
620 /* Basically a conditional call to realloc(), if we need more */
621 int _buf_alloc(char **rwbuf, size_t *curlen, size_t newlen);
622 #endif /* _SUN_SDK_ */
623 
624 /* convert an iovec to a single buffer */
625 #ifdef _SUN_SDK_
626 int _iovec_to_buf(const _sasl_global_context_t *gctx, const struct iovec *vec,
627                   unsigned numiov, buffer_info_t **output);
628 #else
629 int _iovec_to_buf(const struct iovec *vec,
630 		  unsigned numiov, buffer_info_t **output);
631 #endif /* _SUN_SDK_ */
632 
633 /* Convert between string formats and sockaddr formats */
634 int _sasl_iptostring(const struct sockaddr *addr, socklen_t addrlen,
635 		     char *out, unsigned outlen);
636 int _sasl_ipfromstring(const char *addr, struct sockaddr *out,
637 		       socklen_t outlen);
638 
639 /*
640  * external plugin (external.c)
641  */
642 int external_client_plug_init(const sasl_utils_t *utils,
643 			      int max_version,
644 			      int *out_version,
645 			      sasl_client_plug_t **pluglist,
646 			      int *plugcount);
647 int external_server_plug_init(const sasl_utils_t *utils,
648 			      int max_version,
649 			      int *out_version,
650 			      sasl_server_plug_t **pluglist,
651 			      int *plugcount);
652 
653 /* Mech Listing Functions */
654 #ifdef _SUN_SDK_
655 int _sasl_build_mechlist(_sasl_global_context_t *gctx);
656 #else
657 int _sasl_build_mechlist(void);
658 #endif /* _SUN_SDK_ */
659 
660 int _sasl_server_listmech(sasl_conn_t *conn,
661 			  const char *user,
662 			  const char *prefix,
663 			  const char *sep,
664 			  const char *suffix,
665 			  const char **result,
666 			  unsigned *plen,
667 			  int *pcount);
668 int _sasl_client_listmech(sasl_conn_t *conn,
669 			  const char *prefix,
670 			  const char *sep,
671 			  const char *suffix,
672 			  const char **result,
673 			  unsigned *plen,
674 			  int *pcount);
675 /* Just create a straight list of them */
676 #ifdef _SUN_SDK_
677 sasl_string_list_t *_sasl_client_mechs(_sasl_global_context_t *gctx);
678 sasl_string_list_t *_sasl_server_mechs(_sasl_global_context_t *gctx);
679 #else
680 sasl_string_list_t *_sasl_client_mechs(void);
681 sasl_string_list_t *_sasl_server_mechs(void);
682 #endif /* _SUN_SDK_ */
683 
684 /*
685  * config file declarations (config.c)
686  */
687 #ifdef _SUN_SDK_
688 extern int sasl_config_init(_sasl_global_context_t *gctx,
689         const char *filename);
690 extern void sasl_config_free(_sasl_global_context_t *gctx);
691 extern const char *sasl_config_getstring(_sasl_global_context_t *gctx,
692         const char *key,const char *def);
693 extern int sasl_config_getint(_sasl_global_context_t *gctx,
694         const char *key,int def);
695 extern int sasl_config_getswitch(_sasl_global_context_t *gctx,
696         const char *key,int def);
697 #else
698 extern int sasl_config_init(const char *filename);
699 extern const char *sasl_config_getstring(const char *key,const char *def);
700 extern int sasl_config_getint(const char *key,int def);
701 extern int sasl_config_getswitch(const char *key,int def);
702 #endif /* _SUN_SDK_ */
703 
704 /* checkpw.c */
705 #ifdef DO_SASL_CHECKAPOP
706 extern int _sasl_auxprop_verify_apop(sasl_conn_t *conn,
707 				     const char *userstr,
708 				     const char *challenge,
709 				     const char *response,
710 				     const char *user_realm);
711 #endif /* DO_SASL_CHECKAPOP */
712 
713 /* Auxprop Plugin (checkpw.c) */
714 extern int sasldb_auxprop_plug_init(const sasl_utils_t *utils,
715 				    int max_version,
716 				    int *out_version,
717 				    sasl_auxprop_plug_t **plug,
718 				    const char *plugname);
719 
720 /*
721  * auxprop.c
722  */
723 #ifdef _SUN_SDK_
724 extern void _sasl_auxprop_free(_sasl_global_context_t *gctx);
725 #else
726 extern int _sasl_auxprop_add_plugin(void *p, void *library);
727 extern void _sasl_auxprop_free(void);
728 #endif /* _SUN_SDK_ */
729 extern void _sasl_auxprop_lookup(sasl_server_params_t *sparams,
730 				 unsigned flags,
731 				 const char *user, unsigned ulen);
732 
733 /*
734  * canonusr.c
735  */
736 #ifdef _SUN_SDK_
737 void _sasl_canonuser_free(_sasl_global_context_t *gctx);
738 #else
739 void _sasl_canonuser_free();
740 #endif /* _SUN_SDK_ */
741 extern int internal_canonuser_init(const sasl_utils_t *utils,
742 				   int max_version,
743 				   int *out_version,
744 				   sasl_canonuser_plug_t **plug,
745 				   const char *plugname);
746 extern int _sasl_canon_user(sasl_conn_t *conn,
747 			    const char *user, unsigned ulen,
748 			    unsigned flags,
749 			    sasl_out_params_t *oparams);
750 
751 #ifdef _SUN_SDK_
752 /* Private functions to create, free, and use a private context */
753 void *sasl_create_context(void);
754 
755 void sasl_free_context(void *context);
756 
757 extern int _sasl_server_init(void *ctx, const sasl_callback_t *callbacks,
758 		     const char *appname);
759 
760 extern int _sasl_server_new(void *ctx, const char *service,
761 			    const char *serverFQDN, const char *user_realm,
762 			    const char *iplocalport, const char *ipremoteport,
763 			    const sasl_callback_t *callbacks, unsigned flags,
764 			    sasl_conn_t **pconn);
765 
766 extern int _sasl_client_init(void *ctx,
767 			     const sasl_callback_t *callbacks);
768 
769 extern int _sasl_client_new(void *ctx,
770 			    const char *service,
771 			    const char *serverFQDN,
772 			    const char *iplocalport,
773 			    const char *ipremoteport,
774 			    const sasl_callback_t *prompt_supp,
775 			    unsigned flags,
776 			    sasl_conn_t **pconn);
777 
778 extern int _sasl_client_add_plugin(void *ctx,
779                                    const char *plugname,
780                                    sasl_client_plug_init_t *cplugfunc);
781 extern int _sasl_server_add_plugin(void *ctx,
782                                    const char *plugname,
783                                    sasl_server_plug_init_t *splugfunc);
784 extern int _sasl_canonuser_add_plugin(void *ctx,
785                                       const char *plugname,
786                                       sasl_canonuser_init_t *canonuserfunc);
787 extern int _sasl_auxprop_add_plugin(void *ctx,
788                                     const char *plugname,
789                                     sasl_auxprop_init_t *auxpropfunc);
790 
791 _sasl_global_context_t *_sasl_gbl_ctx(void);
792 
793 #ifdef _INTEGRATED_SOLARIS_
794 int _is_sun_reg(void *mech);
795 #endif /* _INTEGRATED_SOLARIS_ */
796 
797 /* unsupported functions that are used internally */
798 int sasl_randcreate(sasl_rand_t **rpool);
799 
800 void sasl_randfree(sasl_rand_t **rpool);
801 
802 void sasl_rand(sasl_rand_t *rpool, char *buf, unsigned len);
803 
804 void sasl_churn(sasl_rand_t *rpool, const char *data, unsigned len);
805 
806 int sasl_mkchal(sasl_conn_t *conn, char *buf, unsigned maxlen,
807 		unsigned hostflag);
808 #endif	/* _SUN_SDK_ */
809 
810 #endif /* SASLINT_H */
811