#ifndef SASLINT_H
#define SASLINT_H
#include <config.h>
#include "sasl.h"
#include "saslplug.h"
#include "saslutil.h"
#include "prop.h"
#define CANON_BUF_SIZE 256
#define RETURN(conn, val) { if(conn && (val) < SASL_OK) \
(conn)->error_code = (val); \
return (val); }
#if !defined _SUN_SDK || defined DEBUG
#define MEMERROR(conn) {\
if(conn) sasl_seterror( (conn), 0, \
"Out of Memory in " __FILE__ " near line %d", __LINE__ ); \
RETURN(conn, SASL_NOMEM) }
#define PARAMERROR(conn) {\
if(conn) sasl_seterror( (conn), SASL_NOLOG, \
"Parameter error in " __FILE__ " near line %d", __LINE__ ); \
RETURN(conn, SASL_BADPARAM) }
#define INTERROR(conn, val) {\
if(conn) sasl_seterror( (conn), 0, \
"Internal Error %d in " __FILE__ " near line %d", (val),\
__LINE__ ); \
RETURN(conn, (val)) }
#else
#define MEMERROR(conn) {\
if(conn) _sasl_log((conn), SASL_LOG_WARN, "Out of Memory"); \
RETURN(conn, SASL_NOMEM) }
#define PARAMERROR(conn) {\
if(conn) _sasl_log((conn), SASL_LOG_WARN, "Parameter error"); \
RETURN(conn, SASL_BADPARAM) }
#define INTERROR(conn, val) {\
if(conn) _sasl_log((conn), SASL_LOG_ERR, "Internal Error: %d", (val)); \
RETURN(conn, (val)) }
#endif
#ifndef PATH_MAX
# ifdef WIN32
# define PATH_MAX MAX_PATH
# else
# ifdef _POSIX_PATH_MAX
# define PATH_MAX _POSIX_PATH_MAX
# else
# define PATH_MAX 1024
# endif
# endif
#endif
#ifdef WIN32
#define PATHS_DELIMITER ';'
#else
#define PATHS_DELIMITER ':'
#endif
typedef struct {
const sasl_callback_t *callbacks;
const char *appname;
#ifdef _SUN_SDK_
struct _sasl_global_context_s *gctx;
#endif
} sasl_global_callbacks_t;
typedef struct _sasl_external_properties
{
sasl_ssf_t ssf;
char *auth_id;
} _sasl_external_properties_t;
typedef struct sasl_string_list
{
const char *d;
struct sasl_string_list *next;
} sasl_string_list_t;
typedef struct buffer_info
{
char *data;
size_t curlen;
size_t reallen;
} buffer_info_t;
#ifdef _SUN_SDK_
typedef int add_plugin_t(struct _sasl_global_context_s *gctx,
const char *, void *);
#else
typedef int add_plugin_t(const char *, void *);
#endif
typedef struct add_plugin_list
{
const char *entryname;
add_plugin_t *add_plugin;
} add_plugin_list_t;
enum Sasl_conn_type { SASL_CONN_UNKNOWN = 0,
SASL_CONN_SERVER = 1,
SASL_CONN_CLIENT = 2 };
struct sasl_conn {
enum Sasl_conn_type type;
void (*destroy_conn)(sasl_conn_t *);
char *service;
unsigned int flags;
int got_ip_local, got_ip_remote;
char iplocalport[NI_MAXHOST + NI_MAXSERV];
char ipremoteport[NI_MAXHOST + NI_MAXSERV];
void *context;
sasl_out_params_t oparams;
sasl_security_properties_t props;
_sasl_external_properties_t external;
#ifndef _SUN_SDK_
sasl_secret_t *secret;
#endif
int (*idle_hook)(sasl_conn_t *conn);
const sasl_callback_t *callbacks;
const sasl_global_callbacks_t *global_callbacks;
char *serverFQDN;
buffer_info_t *encode_buf;
int error_code;
char *error_buf, *errdetail_buf;
size_t error_buf_len, errdetail_buf_len;
char *mechlist_buf;
size_t mechlist_buf_len;
char *decode_buf;
char user_buf[CANON_BUF_SIZE+1], authid_buf[CANON_BUF_SIZE+1];
#ifdef _SUN_SDK_
struct _sasl_global_context_s *gctx;
#ifdef _INTEGRATED_SOLARIS_
int sun_reg;
#endif
#endif
};
#ifdef _SUN_SDK_
typedef struct _sasl_path_info {
char *path;
time_t last_changed;
struct _sasl_path_info *next;
} _sasl_path_info_t;
#endif
typedef struct mechanism
{
int version;
int condition;
char *plugname;
#ifdef _SUN_SDK_
#ifdef _INTEGRATED_SOLARIS_
int sun_reg;
#endif
sasl_server_plug_t *plug;
void *glob_context;
struct mechanism *next;
#else
const sasl_server_plug_t *plug;
struct mechanism *next;
char *f;
#endif
} mechanism_t;
typedef struct mech_list {
const sasl_utils_t *utils;
void *mutex;
mechanism_t *mech_list;
int mech_length;
} mech_list_t;
typedef struct context_list
{
mechanism_t *mech;
void *context;
struct context_list *next;
} context_list_t;
typedef struct sasl_server_conn {
sasl_conn_t base;
char *user_realm;
int sent_last;
int authenticated;
mechanism_t *mech;
sasl_server_params_t *sparams;
context_list_t *mech_contexts;
} sasl_server_conn_t;
typedef struct cmechanism
{
int version;
char *plugname;
#ifdef _SUN_SDK_
#ifdef _INTEGRATED_SOLARIS_
int sun_reg;
#endif
void *glob_context;
sasl_client_plug_t *plug;
#else
const sasl_client_plug_t *plug;
#endif
struct cmechanism *next;
} cmechanism_t;
typedef struct cmech_list {
const sasl_utils_t *utils;
void *mutex;
cmechanism_t *mech_list;
int mech_length;
} cmech_list_t;
typedef struct sasl_client_conn {
sasl_conn_t base;
cmechanism_t *mech;
sasl_client_params_t *cparams;
char *clientFQDN;
} sasl_client_conn_t;
typedef struct sasl_allocation_utils {
sasl_malloc_t *malloc;
sasl_calloc_t *calloc;
sasl_realloc_t *realloc;
sasl_free_t *free;
} sasl_allocation_utils_t;
typedef struct sasl_mutex_utils {
sasl_mutex_alloc_t *alloc;
sasl_mutex_lock_t *lock;
sasl_mutex_unlock_t *unlock;
sasl_mutex_free_t *free;
} sasl_mutex_utils_t;
typedef struct sasl_log_utils_s {
sasl_log_t *log;
} sasl_log_utils_t;
#ifdef _SUN_SDK_
typedef struct _sasl_global_context_s {
int sasl_server_active;
mech_list_t *mechlist;
_sasl_path_info_t *splug_path_info;
sasl_global_callbacks_t server_global_callbacks;
int (*sasl_server_cleanup_hook)
(struct _sasl_global_context_s *gctx);
int (*sasl_server_idle_hook)(sasl_conn_t *conn);
cmech_list_t *cmechlist;
_sasl_path_info_t *cplug_path_info;
sasl_global_callbacks_t client_global_callbacks;
int sasl_client_active;
int (*sasl_client_cleanup_hook)
(struct _sasl_global_context_s *gctx);
int (*sasl_client_idle_hook)(sasl_conn_t *conn);
const sasl_utils_t *sasl_server_global_utils;
const sasl_utils_t *sasl_canonusr_global_utils;
void *configlist;
int nconfiglist;
char *config_path;
time_t config_last_read;
void *auxprop_head;
void *canonuser_head;
char **global_mech_list;
void *free_mutex;
sasl_allocation_utils_t sasl_allocation_utils;
sasl_mutex_utils_t sasl_mutex_utils;
void *lib_list_head;
}_sasl_global_context_t;
#endif
typedef int sasl_plaintext_verifier(sasl_conn_t *conn,
const char *userid,
const char *passwd,
const char *service,
const char *user_realm);
struct sasl_verify_password_s {
char *name;
sasl_plaintext_verifier *verify;
};
#ifndef _SUN_SDK_
LIBSASL_API const sasl_utils_t *sasl_global_utils;
extern int (*_sasl_client_idle_hook)(sasl_conn_t *conn);
extern int (*_sasl_server_idle_hook)(sasl_conn_t *conn);
extern int (*_sasl_client_cleanup_hook)(void);
extern int (*_sasl_server_cleanup_hook)(void);
extern sasl_allocation_utils_t _sasl_allocation_utils;
extern sasl_mutex_utils_t _sasl_mutex_utils;
#endif
extern struct sasl_verify_password_s _sasl_verify_password[];
#ifdef _SUN_SDK_
extern int _is_sasl_server_active(_sasl_global_context_t *gctx);
#else
extern int _is_sasl_server_active(void);
#endif
#ifdef _SUN_SDK_
#define sasl_ALLOC(__size__) (gctx->sasl_allocation_utils.malloc((__size__)))
#define sasl_CALLOC(__nelem__, __size__) \
(gctx->sasl_allocation_utils.calloc((__nelem__), (__size__)))
#define sasl_REALLOC(__ptr__, __size__) \
(gctx->sasl_allocation_utils.realloc((__ptr__), (__size__)))
#define sasl_FREE(__ptr__) (gctx->sasl_allocation_utils.free((__ptr__)))
#define sasl_sun_ALLOC(__size__) (malloc((__size__)))
#define sasl_sun_CALLOC(__nelem__, __size__) (calloc((__nelem__), (__size__)))
#define sasl_sun_REALLOC(__ptr__, __size__) (realloc((__ptr__), (__size__)))
#define sasl_sun_FREE(__ptr__) (free((__ptr__)))
#define sasl_MUTEX_ALLOC() (gctx->sasl_mutex_utils.alloc())
#define sasl_MUTEX_LOCK(__mutex__) (gctx->sasl_mutex_utils.lock((__mutex__)))
#define sasl_MUTEX_UNLOCK(__mutex__) \
(gctx->sasl_mutex_utils.unlock((__mutex__)))
#define sasl_MUTEX_FREE(__mutex__) (gctx->sasl_mutex_utils.free((__mutex__)))
#else
#define sasl_ALLOC(__size__) (_sasl_allocation_utils.malloc((__size__)))
#define sasl_CALLOC(__nelem__, __size__) \
(_sasl_allocation_utils.calloc((__nelem__), (__size__)))
#define sasl_REALLOC(__ptr__, __size__) \
(_sasl_allocation_utils.realloc((__ptr__), (__size__)))
#define sasl_FREE(__ptr__) (_sasl_allocation_utils.free((__ptr__)))
#define sasl_MUTEX_ALLOC() (_sasl_mutex_utils.alloc())
#define sasl_MUTEX_LOCK(__mutex__) (_sasl_mutex_utils.lock((__mutex__)))
#define sasl_MUTEX_UNLOCK(__mutex__) (_sasl_mutex_utils.unlock((__mutex__)))
#define sasl_MUTEX_FREE(__mutex__) \
(_sasl_mutex_utils.free((__mutex__)))
#endif
#ifdef _SUN_SDK_
extern int _sasl_load_plugins(_sasl_global_context_t *gctx,
int server,
const add_plugin_list_t *entrypoints,
const sasl_callback_t *getpath_callback,
const sasl_callback_t *verifyfile_callback);
extern int _sasl_get_plugin(_sasl_global_context_t *gctx,
const char *file,
const sasl_callback_t *verifyfile_cb,
void **libraryptr);
extern int _sasl_locate_entry(void *library, const char *entryname,
void **entry_point);
extern int _sasl_done_with_plugins(_sasl_global_context_t *gctx);
#else
extern int _sasl_load_plugins(const add_plugin_list_t *entrypoints,
const sasl_callback_t *getpath_callback,
const sasl_callback_t *verifyfile_callback);
extern int _sasl_get_plugin(const char *file,
const sasl_callback_t *verifyfile_cb,
void **libraryptr);
extern int _sasl_locate_entry(void *library, const char *entryname,
void **entry_point);
extern int _sasl_done_with_plugins();
#endif
extern const sasl_callback_t *
_sasl_find_getpath_callback(const sasl_callback_t *callbacks);
extern const sasl_callback_t *
_sasl_find_verifyfile_callback(const sasl_callback_t *callbacks);
#ifdef _SUN_SDK_
extern const sasl_callback_t *
_sasl_find_getconf_callback(const sasl_callback_t *callbacks);
extern int _sasl_common_init(_sasl_global_context_t *gctx,
sasl_global_callbacks_t *global_callbacks,
int server);
#else
extern int _sasl_common_init(sasl_global_callbacks_t *global_callbacks);
#endif
extern int _sasl_conn_init(sasl_conn_t *conn,
const char *service,
unsigned int flags,
enum Sasl_conn_type type,
int (*idle_hook)(sasl_conn_t *conn),
const char *serverFQDN,
const char *iplocalport,
const char *ipremoteport,
const sasl_callback_t *callbacks,
const sasl_global_callbacks_t *global_callbacks);
extern void _sasl_conn_dispose(sasl_conn_t *conn);
#ifdef _SUN_SDK_
extern sasl_utils_t *
_sasl_alloc_utils(_sasl_global_context_t *gctx, sasl_conn_t *conn,
sasl_global_callbacks_t *global_callbacks);
#else
extern sasl_utils_t *
_sasl_alloc_utils(sasl_conn_t *conn,
sasl_global_callbacks_t *global_callbacks);
#endif
extern int _sasl_free_utils(const sasl_utils_t ** utils);
extern int
_sasl_getcallback(sasl_conn_t * conn,
unsigned long callbackid,
int (**pproc)(),
void **pcontext);
extern void
_sasl_log(sasl_conn_t *conn,
int level,
const char *fmt,
...);
#ifdef _SUN_SDK_
extern void
__sasl_log(const _sasl_global_context_t *gctx,
const sasl_callback_t *callbacks,
int level,
const char *fmt,
...);
#endif
void _sasl_get_errorbuf(sasl_conn_t *conn, char ***bufhdl, size_t **lenhdl);
#ifdef _SUN_SDK_
int __sasl_add_string(const _sasl_global_context_t *gctx, char **out,
size_t *alloclen,
size_t *outlen, const char *add);
#define _sasl_add_string(out, alloclen, outlen, add) \
__sasl_add_string(gctx, out, alloclen, outlen, add)
#define _sasl_strdup(in, out, outlen) \
__sasl_strdup(gctx, in, out, outlen)
extern int __sasl_strdup(const _sasl_global_context_t *gctx, const char *in,
char **out, size_t *outlen);
int __buf_alloc(const _sasl_global_context_t *gctx, char **rwbuf,
size_t *curlen, size_t newlen);
#define _buf_alloc(rwbuf, curlen, newlen) \
__buf_alloc(gctx, rwbuf, curlen, newlen)
#else
int _sasl_add_string(char **out, size_t *alloclen,
size_t *outlen, const char *add);
extern int _sasl_strdup(const char *in, char **out, size_t *outlen);
int _buf_alloc(char **rwbuf, size_t *curlen, size_t newlen);
#endif
#ifdef _SUN_SDK_
int _iovec_to_buf(const _sasl_global_context_t *gctx, const struct iovec *vec,
unsigned numiov, buffer_info_t **output);
#else
int _iovec_to_buf(const struct iovec *vec,
unsigned numiov, buffer_info_t **output);
#endif
int _sasl_iptostring(const struct sockaddr *addr, socklen_t addrlen,
char *out, unsigned outlen);
int _sasl_ipfromstring(const char *addr, struct sockaddr *out,
socklen_t outlen);
int external_client_plug_init(const sasl_utils_t *utils,
int max_version,
int *out_version,
sasl_client_plug_t **pluglist,
int *plugcount);
int external_server_plug_init(const sasl_utils_t *utils,
int max_version,
int *out_version,
sasl_server_plug_t **pluglist,
int *plugcount);
#ifdef _SUN_SDK_
int _sasl_build_mechlist(_sasl_global_context_t *gctx);
#else
int _sasl_build_mechlist(void);
#endif
int _sasl_server_listmech(sasl_conn_t *conn,
const char *user,
const char *prefix,
const char *sep,
const char *suffix,
const char **result,
unsigned *plen,
int *pcount);
int _sasl_client_listmech(sasl_conn_t *conn,
const char *prefix,
const char *sep,
const char *suffix,
const char **result,
unsigned *plen,
int *pcount);
#ifdef _SUN_SDK_
sasl_string_list_t *_sasl_client_mechs(_sasl_global_context_t *gctx);
sasl_string_list_t *_sasl_server_mechs(_sasl_global_context_t *gctx);
#else
sasl_string_list_t *_sasl_client_mechs(void);
sasl_string_list_t *_sasl_server_mechs(void);
#endif
#ifdef _SUN_SDK_
extern int sasl_config_init(_sasl_global_context_t *gctx,
const char *filename);
extern void sasl_config_free(_sasl_global_context_t *gctx);
extern const char *sasl_config_getstring(_sasl_global_context_t *gctx,
const char *key,const char *def);
extern int sasl_config_getint(_sasl_global_context_t *gctx,
const char *key,int def);
extern int sasl_config_getswitch(_sasl_global_context_t *gctx,
const char *key,int def);
#else
extern int sasl_config_init(const char *filename);
extern const char *sasl_config_getstring(const char *key,const char *def);
extern int sasl_config_getint(const char *key,int def);
extern int sasl_config_getswitch(const char *key,int def);
#endif
#ifdef DO_SASL_CHECKAPOP
extern int _sasl_auxprop_verify_apop(sasl_conn_t *conn,
const char *userstr,
const char *challenge,
const char *response,
const char *user_realm);
#endif
extern int sasldb_auxprop_plug_init(const sasl_utils_t *utils,
int max_version,
int *out_version,
sasl_auxprop_plug_t **plug,
const char *plugname);
#ifdef _SUN_SDK_
extern void _sasl_auxprop_free(_sasl_global_context_t *gctx);
#else
extern int _sasl_auxprop_add_plugin(void *p, void *library);
extern void _sasl_auxprop_free(void);
#endif
extern void _sasl_auxprop_lookup(sasl_server_params_t *sparams,
unsigned flags,
const char *user, unsigned ulen);
#ifdef _SUN_SDK_
void _sasl_canonuser_free(_sasl_global_context_t *gctx);
#else
void _sasl_canonuser_free();
#endif
extern int internal_canonuser_init(const sasl_utils_t *utils,
int max_version,
int *out_version,
sasl_canonuser_plug_t **plug,
const char *plugname);
extern int _sasl_canon_user(sasl_conn_t *conn,
const char *user, unsigned ulen,
unsigned flags,
sasl_out_params_t *oparams);
#ifdef _SUN_SDK_
void *sasl_create_context(void);
void sasl_free_context(void *context);
extern int _sasl_server_init(void *ctx, const sasl_callback_t *callbacks,
const char *appname);
extern int _sasl_server_new(void *ctx, const char *service,
const char *serverFQDN, const char *user_realm,
const char *iplocalport, const char *ipremoteport,
const sasl_callback_t *callbacks, unsigned flags,
sasl_conn_t **pconn);
extern int _sasl_client_init(void *ctx,
const sasl_callback_t *callbacks);
extern int _sasl_client_new(void *ctx,
const char *service,
const char *serverFQDN,
const char *iplocalport,
const char *ipremoteport,
const sasl_callback_t *prompt_supp,
unsigned flags,
sasl_conn_t **pconn);
extern int _sasl_client_add_plugin(void *ctx,
const char *plugname,
sasl_client_plug_init_t *cplugfunc);
extern int _sasl_server_add_plugin(void *ctx,
const char *plugname,
sasl_server_plug_init_t *splugfunc);
extern int _sasl_canonuser_add_plugin(void *ctx,
const char *plugname,
sasl_canonuser_init_t *canonuserfunc);
extern int _sasl_auxprop_add_plugin(void *ctx,
const char *plugname,
sasl_auxprop_init_t *auxpropfunc);
_sasl_global_context_t *_sasl_gbl_ctx(void);
#ifdef _INTEGRATED_SOLARIS_
int _is_sun_reg(void *mech);
#endif
int sasl_randcreate(sasl_rand_t **rpool);
void sasl_randfree(sasl_rand_t **rpool);
void sasl_rand(sasl_rand_t *rpool, char *buf, unsigned len);
void sasl_churn(sasl_rand_t *rpool, const char *data, unsigned len);
int sasl_mkchal(sasl_conn_t *conn, char *buf, unsigned maxlen,
unsigned hostflag);
#endif
#endif