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