1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 3*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 4*7c478bd9Sstevel@tonic-gate */ 5*7c478bd9Sstevel@tonic-gate 6*7c478bd9Sstevel@tonic-gate /* Generic SASL plugin utility functions 7*7c478bd9Sstevel@tonic-gate * Rob Siemborski 8*7c478bd9Sstevel@tonic-gate * $Id: plugin_common.h,v 1.16 2003/04/07 16:03:43 rjs3 Exp $ 9*7c478bd9Sstevel@tonic-gate */ 10*7c478bd9Sstevel@tonic-gate 11*7c478bd9Sstevel@tonic-gate /* 12*7c478bd9Sstevel@tonic-gate * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 15*7c478bd9Sstevel@tonic-gate * modification, are permitted provided that the following conditions 16*7c478bd9Sstevel@tonic-gate * are met: 17*7c478bd9Sstevel@tonic-gate * 18*7c478bd9Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 19*7c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 20*7c478bd9Sstevel@tonic-gate * 21*7c478bd9Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 22*7c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in 23*7c478bd9Sstevel@tonic-gate * the documentation and/or other materials provided with the 24*7c478bd9Sstevel@tonic-gate * distribution. 25*7c478bd9Sstevel@tonic-gate * 26*7c478bd9Sstevel@tonic-gate * 3. The name "Carnegie Mellon University" must not be used to 27*7c478bd9Sstevel@tonic-gate * endorse or promote products derived from this software without 28*7c478bd9Sstevel@tonic-gate * prior written permission. For permission or any other legal 29*7c478bd9Sstevel@tonic-gate * details, please contact 30*7c478bd9Sstevel@tonic-gate * Office of Technology Transfer 31*7c478bd9Sstevel@tonic-gate * Carnegie Mellon University 32*7c478bd9Sstevel@tonic-gate * 5000 Forbes Avenue 33*7c478bd9Sstevel@tonic-gate * Pittsburgh, PA 15213-3890 34*7c478bd9Sstevel@tonic-gate * (412) 268-4387, fax: (412) 268-7395 35*7c478bd9Sstevel@tonic-gate * tech-transfer@andrew.cmu.edu 36*7c478bd9Sstevel@tonic-gate * 37*7c478bd9Sstevel@tonic-gate * 4. Redistributions of any form whatsoever must retain the following 38*7c478bd9Sstevel@tonic-gate * acknowledgment: 39*7c478bd9Sstevel@tonic-gate * "This product includes software developed by Computing Services 40*7c478bd9Sstevel@tonic-gate * at Carnegie Mellon University (http://www.cmu.edu/computing/)." 41*7c478bd9Sstevel@tonic-gate * 42*7c478bd9Sstevel@tonic-gate * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO 43*7c478bd9Sstevel@tonic-gate * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 44*7c478bd9Sstevel@tonic-gate * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE 45*7c478bd9Sstevel@tonic-gate * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 46*7c478bd9Sstevel@tonic-gate * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 47*7c478bd9Sstevel@tonic-gate * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 48*7c478bd9Sstevel@tonic-gate * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 49*7c478bd9Sstevel@tonic-gate */ 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate #ifndef _PLUGIN_COMMON_H_ 52*7c478bd9Sstevel@tonic-gate #define _PLUGIN_COMMON_H_ 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate #include <config.h> 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate #ifndef macintosh 57*7c478bd9Sstevel@tonic-gate #ifdef WIN32 58*7c478bd9Sstevel@tonic-gate # include <winsock.h> 59*7c478bd9Sstevel@tonic-gate #else 60*7c478bd9Sstevel@tonic-gate # include <sys/socket.h> 61*7c478bd9Sstevel@tonic-gate # include <netinet/in.h> 62*7c478bd9Sstevel@tonic-gate # include <arpa/inet.h> 63*7c478bd9Sstevel@tonic-gate # include <netdb.h> 64*7c478bd9Sstevel@tonic-gate #endif /* WIN32 */ 65*7c478bd9Sstevel@tonic-gate #endif /* macintosh */ 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate #include <sasl.h> 68*7c478bd9Sstevel@tonic-gate #include <saslutil.h> 69*7c478bd9Sstevel@tonic-gate #include <saslplug.h> 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate #ifdef WIN32 72*7c478bd9Sstevel@tonic-gate #define PLUG_API __declspec(dllexport) 73*7c478bd9Sstevel@tonic-gate #else 74*7c478bd9Sstevel@tonic-gate #define PLUG_API extern 75*7c478bd9Sstevel@tonic-gate #endif 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate #define SASL_CLIENT_PLUG_INIT( x ) \ 78*7c478bd9Sstevel@tonic-gate extern sasl_client_plug_init_t x##_client_plug_init; \ 79*7c478bd9Sstevel@tonic-gate PLUG_API int sasl_client_plug_init(const sasl_utils_t *utils, \ 80*7c478bd9Sstevel@tonic-gate int maxversion, int *out_version, \ 81*7c478bd9Sstevel@tonic-gate sasl_client_plug_t **pluglist, \ 82*7c478bd9Sstevel@tonic-gate int *plugcount) { \ 83*7c478bd9Sstevel@tonic-gate return x##_client_plug_init(utils, maxversion, out_version, \ 84*7c478bd9Sstevel@tonic-gate pluglist, plugcount); \ 85*7c478bd9Sstevel@tonic-gate } 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate #define SASL_SERVER_PLUG_INIT( x ) \ 88*7c478bd9Sstevel@tonic-gate extern sasl_server_plug_init_t x##_server_plug_init; \ 89*7c478bd9Sstevel@tonic-gate PLUG_API int sasl_server_plug_init(const sasl_utils_t *utils, \ 90*7c478bd9Sstevel@tonic-gate int maxversion, int *out_version, \ 91*7c478bd9Sstevel@tonic-gate sasl_server_plug_t **pluglist, \ 92*7c478bd9Sstevel@tonic-gate int *plugcount) { \ 93*7c478bd9Sstevel@tonic-gate return x##_server_plug_init(utils, maxversion, out_version, \ 94*7c478bd9Sstevel@tonic-gate pluglist, plugcount); \ 95*7c478bd9Sstevel@tonic-gate } 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate #define SASL_AUXPROP_PLUG_INIT( x ) \ 98*7c478bd9Sstevel@tonic-gate extern sasl_auxprop_init_t x##_auxprop_plug_init; \ 99*7c478bd9Sstevel@tonic-gate PLUG_API int sasl_auxprop_plug_init(const sasl_utils_t *utils, \ 100*7c478bd9Sstevel@tonic-gate int maxversion, int *out_version, \ 101*7c478bd9Sstevel@tonic-gate sasl_auxprop_plug_t **plug, \ 102*7c478bd9Sstevel@tonic-gate const char *plugname) {\ 103*7c478bd9Sstevel@tonic-gate return x##_auxprop_plug_init(utils, maxversion, out_version, \ 104*7c478bd9Sstevel@tonic-gate plug, plugname); \ 105*7c478bd9Sstevel@tonic-gate } 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate #define SASL_CANONUSER_PLUG_INIT( x ) \ 108*7c478bd9Sstevel@tonic-gate extern sasl_canonuser_init_t x##_canonuser_plug_init; \ 109*7c478bd9Sstevel@tonic-gate PLUG_API int sasl_canonuser_init(const sasl_utils_t *utils, \ 110*7c478bd9Sstevel@tonic-gate int maxversion, int *out_version, \ 111*7c478bd9Sstevel@tonic-gate sasl_canonuser_plug_t **plug, \ 112*7c478bd9Sstevel@tonic-gate const char *plugname) {\ 113*7c478bd9Sstevel@tonic-gate return x##_canonuser_plug_init(utils, maxversion, out_version, \ 114*7c478bd9Sstevel@tonic-gate plug, plugname); \ 115*7c478bd9Sstevel@tonic-gate } 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate /* note: msg cannot include additional variables, so if you want to 118*7c478bd9Sstevel@tonic-gate * do a printf-format string, then you need to call seterror yourself */ 119*7c478bd9Sstevel@tonic-gate #define SETERROR( utils, msg ) (utils)->seterror( (utils)->conn, 0, (msg) ) 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate #ifndef MEMERROR 122*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_ 123*7c478bd9Sstevel@tonic-gate #define MEMERROR( utils ) \ 124*7c478bd9Sstevel@tonic-gate (utils)->seterror( (utils)->conn, 0, "Out of Memory") 125*7c478bd9Sstevel@tonic-gate #else 126*7c478bd9Sstevel@tonic-gate #define MEMERROR( utils ) \ 127*7c478bd9Sstevel@tonic-gate (utils)->seterror( (utils)->conn, 0, \ 128*7c478bd9Sstevel@tonic-gate "Out of Memory in " __FILE__ " near line %d", __LINE__ ) 129*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */ 130*7c478bd9Sstevel@tonic-gate #endif 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate #ifndef PARAMERROR 133*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_ 134*7c478bd9Sstevel@tonic-gate #define PARAMERROR( utils ) \ 135*7c478bd9Sstevel@tonic-gate (utils)->seterror( (utils)->conn, 0, "Parameter Error") 136*7c478bd9Sstevel@tonic-gate #else 137*7c478bd9Sstevel@tonic-gate #define PARAMERROR( utils ) \ 138*7c478bd9Sstevel@tonic-gate (utils)->seterror( (utils)->conn, 0, \ 139*7c478bd9Sstevel@tonic-gate "Parameter Error in " __FILE__ " near line %d", __LINE__ ) 140*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */ 141*7c478bd9Sstevel@tonic-gate #endif 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate #ifndef SASLINT_H 144*7c478bd9Sstevel@tonic-gate typedef struct buffer_info 145*7c478bd9Sstevel@tonic-gate { 146*7c478bd9Sstevel@tonic-gate char *data; 147*7c478bd9Sstevel@tonic-gate unsigned curlen; /* Current length of data in buffer */ 148*7c478bd9Sstevel@tonic-gate unsigned reallen; /* total length of buffer (>= curlen) */ 149*7c478bd9Sstevel@tonic-gate } buffer_info_t; 150*7c478bd9Sstevel@tonic-gate #endif 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate int _plug_ipfromstring(const sasl_utils_t *utils, const char *addr, 153*7c478bd9Sstevel@tonic-gate struct sockaddr *out, socklen_t outlen); 154*7c478bd9Sstevel@tonic-gate int _plug_iovec_to_buf(const sasl_utils_t *utils, const struct iovec *vec, 155*7c478bd9Sstevel@tonic-gate unsigned numiov, buffer_info_t **output); 156*7c478bd9Sstevel@tonic-gate int _plug_buf_alloc(const sasl_utils_t *utils, char **rwbuf, 157*7c478bd9Sstevel@tonic-gate unsigned *curlen, unsigned newlen); 158*7c478bd9Sstevel@tonic-gate int _plug_strdup(const sasl_utils_t * utils, const char *in, 159*7c478bd9Sstevel@tonic-gate char **out, int *outlen); 160*7c478bd9Sstevel@tonic-gate void _plug_free_string(const sasl_utils_t *utils, char **str); 161*7c478bd9Sstevel@tonic-gate void _plug_free_secret(const sasl_utils_t *utils, sasl_secret_t **secret); 162*7c478bd9Sstevel@tonic-gate 163*7c478bd9Sstevel@tonic-gate #define _plug_get_userid(utils, result, prompt_need) \ 164*7c478bd9Sstevel@tonic-gate _plug_get_simple(utils, SASL_CB_USER, 0, result, prompt_need) 165*7c478bd9Sstevel@tonic-gate #define _plug_get_authid(utils, result, prompt_need) \ 166*7c478bd9Sstevel@tonic-gate _plug_get_simple(utils, SASL_CB_AUTHNAME, 1, result, prompt_need) 167*7c478bd9Sstevel@tonic-gate int _plug_get_simple(const sasl_utils_t *utils, unsigned int id, int required, 168*7c478bd9Sstevel@tonic-gate const char **result, sasl_interact_t **prompt_need); 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate int _plug_get_password(const sasl_utils_t *utils, sasl_secret_t **secret, 171*7c478bd9Sstevel@tonic-gate unsigned int *iscopy, sasl_interact_t **prompt_need); 172*7c478bd9Sstevel@tonic-gate 173*7c478bd9Sstevel@tonic-gate int _plug_challenge_prompt(const sasl_utils_t *utils, unsigned int id, 174*7c478bd9Sstevel@tonic-gate const char *challenge, const char *promptstr, 175*7c478bd9Sstevel@tonic-gate const char **result, sasl_interact_t **prompt_need); 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate int _plug_get_realm(const sasl_utils_t *utils, const char **availrealms, 178*7c478bd9Sstevel@tonic-gate const char **realm, sasl_interact_t **prompt_need); 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate int _plug_make_prompts(const sasl_utils_t *utils, 181*7c478bd9Sstevel@tonic-gate #ifdef _INTEGRATED_SOLARIS_ 182*7c478bd9Sstevel@tonic-gate void **h, 183*7c478bd9Sstevel@tonic-gate #endif /* _INTEGRATED_SOLARIS_ */ 184*7c478bd9Sstevel@tonic-gate sasl_interact_t **prompts_res, 185*7c478bd9Sstevel@tonic-gate const char *user_prompt, const char *user_def, 186*7c478bd9Sstevel@tonic-gate const char *auth_prompt, const char *auth_def, 187*7c478bd9Sstevel@tonic-gate const char *pass_prompt, const char *pass_def, 188*7c478bd9Sstevel@tonic-gate const char *echo_chal, 189*7c478bd9Sstevel@tonic-gate const char *echo_prompt, const char *echo_def, 190*7c478bd9Sstevel@tonic-gate const char *realm_chal, 191*7c478bd9Sstevel@tonic-gate const char *realm_prompt, const char *realm_def); 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate int _plug_decode(const sasl_utils_t *utils, 194*7c478bd9Sstevel@tonic-gate void *context, 195*7c478bd9Sstevel@tonic-gate const char *input, unsigned inputlen, 196*7c478bd9Sstevel@tonic-gate char **output, unsigned *outputsize, unsigned *outputlen, 197*7c478bd9Sstevel@tonic-gate int (*decode_pkt)(void *context, 198*7c478bd9Sstevel@tonic-gate const char **input, unsigned *inputlen, 199*7c478bd9Sstevel@tonic-gate char **output, unsigned *outputlen)); 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate int _plug_parseuser(const sasl_utils_t *utils, 202*7c478bd9Sstevel@tonic-gate char **user, char **realm, const char *user_realm, 203*7c478bd9Sstevel@tonic-gate const char *serverFQDN, const char *input); 204*7c478bd9Sstevel@tonic-gate 205*7c478bd9Sstevel@tonic-gate #ifdef _INTEGRATED_SOLARIS_ 206*7c478bd9Sstevel@tonic-gate typedef void reg_sun_t(void *); 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate #define REG_PLUG( X, Y ) { \ 209*7c478bd9Sstevel@tonic-gate reg_sun_t *func = NULL; \ 210*7c478bd9Sstevel@tonic-gate unsigned int l; \ 211*7c478bd9Sstevel@tonic-gate utils->getopt(utils->getopt_context, X, "reg_sun_plug", \ 212*7c478bd9Sstevel@tonic-gate (const char **)&func, &l); \ 213*7c478bd9Sstevel@tonic-gate if (func != NULL && l == 0) \ 214*7c478bd9Sstevel@tonic-gate (*func)(Y); \ 215*7c478bd9Sstevel@tonic-gate } 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate int use_locale(const char *lang_list, int is_client); 218*7c478bd9Sstevel@tonic-gate const char *convert_prompt(const sasl_utils_t *utils, void **h, const char *s); 219*7c478bd9Sstevel@tonic-gate char *local_to_utf(const sasl_utils_t *utils, const char *s); 220*7c478bd9Sstevel@tonic-gate #endif /* _INTEGRATED_SOLARIS_ */ 221*7c478bd9Sstevel@tonic-gate #endif /* _PLUGIN_COMMON_H_ */ 222