17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 37c478bd9Sstevel@tonic-gate * Use is subject to license terms. 47c478bd9Sstevel@tonic-gate */ 57c478bd9Sstevel@tonic-gate 67c478bd9Sstevel@tonic-gate /* Generic SASL plugin utility functions 77c478bd9Sstevel@tonic-gate * Rob Siemborski 87c478bd9Sstevel@tonic-gate * $Id: plugin_common.h,v 1.16 2003/04/07 16:03:43 rjs3 Exp $ 97c478bd9Sstevel@tonic-gate */ 107c478bd9Sstevel@tonic-gate 11*55fea89dSDan Cross /* 127c478bd9Sstevel@tonic-gate * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 157c478bd9Sstevel@tonic-gate * modification, are permitted provided that the following conditions 167c478bd9Sstevel@tonic-gate * are met: 177c478bd9Sstevel@tonic-gate * 187c478bd9Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 19*55fea89dSDan Cross * notice, this list of conditions and the following disclaimer. 207c478bd9Sstevel@tonic-gate * 217c478bd9Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 227c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in 237c478bd9Sstevel@tonic-gate * the documentation and/or other materials provided with the 247c478bd9Sstevel@tonic-gate * distribution. 257c478bd9Sstevel@tonic-gate * 267c478bd9Sstevel@tonic-gate * 3. The name "Carnegie Mellon University" must not be used to 277c478bd9Sstevel@tonic-gate * endorse or promote products derived from this software without 287c478bd9Sstevel@tonic-gate * prior written permission. For permission or any other legal 29*55fea89dSDan Cross * details, please contact 307c478bd9Sstevel@tonic-gate * Office of Technology Transfer 317c478bd9Sstevel@tonic-gate * Carnegie Mellon University 327c478bd9Sstevel@tonic-gate * 5000 Forbes Avenue 337c478bd9Sstevel@tonic-gate * Pittsburgh, PA 15213-3890 347c478bd9Sstevel@tonic-gate * (412) 268-4387, fax: (412) 268-7395 357c478bd9Sstevel@tonic-gate * tech-transfer@andrew.cmu.edu 367c478bd9Sstevel@tonic-gate * 377c478bd9Sstevel@tonic-gate * 4. Redistributions of any form whatsoever must retain the following 387c478bd9Sstevel@tonic-gate * acknowledgment: 397c478bd9Sstevel@tonic-gate * "This product includes software developed by Computing Services 407c478bd9Sstevel@tonic-gate * at Carnegie Mellon University (http://www.cmu.edu/computing/)." 417c478bd9Sstevel@tonic-gate * 427c478bd9Sstevel@tonic-gate * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO 437c478bd9Sstevel@tonic-gate * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 447c478bd9Sstevel@tonic-gate * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE 457c478bd9Sstevel@tonic-gate * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 467c478bd9Sstevel@tonic-gate * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 477c478bd9Sstevel@tonic-gate * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 487c478bd9Sstevel@tonic-gate * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 497c478bd9Sstevel@tonic-gate */ 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #ifndef _PLUGIN_COMMON_H_ 527c478bd9Sstevel@tonic-gate #define _PLUGIN_COMMON_H_ 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate #include <config.h> 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #ifndef macintosh 577c478bd9Sstevel@tonic-gate #ifdef WIN32 587c478bd9Sstevel@tonic-gate # include <winsock.h> 597c478bd9Sstevel@tonic-gate #else 607c478bd9Sstevel@tonic-gate # include <sys/socket.h> 617c478bd9Sstevel@tonic-gate # include <netinet/in.h> 627c478bd9Sstevel@tonic-gate # include <arpa/inet.h> 637c478bd9Sstevel@tonic-gate # include <netdb.h> 647c478bd9Sstevel@tonic-gate #endif /* WIN32 */ 657c478bd9Sstevel@tonic-gate #endif /* macintosh */ 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate #include <sasl.h> 687c478bd9Sstevel@tonic-gate #include <saslutil.h> 697c478bd9Sstevel@tonic-gate #include <saslplug.h> 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate #ifdef WIN32 727c478bd9Sstevel@tonic-gate #define PLUG_API __declspec(dllexport) 737c478bd9Sstevel@tonic-gate #else 747c478bd9Sstevel@tonic-gate #define PLUG_API extern 757c478bd9Sstevel@tonic-gate #endif 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate #define SASL_CLIENT_PLUG_INIT( x ) \ 787c478bd9Sstevel@tonic-gate extern sasl_client_plug_init_t x##_client_plug_init; \ 797c478bd9Sstevel@tonic-gate PLUG_API int sasl_client_plug_init(const sasl_utils_t *utils, \ 807c478bd9Sstevel@tonic-gate int maxversion, int *out_version, \ 817c478bd9Sstevel@tonic-gate sasl_client_plug_t **pluglist, \ 827c478bd9Sstevel@tonic-gate int *plugcount) { \ 837c478bd9Sstevel@tonic-gate return x##_client_plug_init(utils, maxversion, out_version, \ 847c478bd9Sstevel@tonic-gate pluglist, plugcount); \ 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate #define SASL_SERVER_PLUG_INIT( x ) \ 887c478bd9Sstevel@tonic-gate extern sasl_server_plug_init_t x##_server_plug_init; \ 897c478bd9Sstevel@tonic-gate PLUG_API int sasl_server_plug_init(const sasl_utils_t *utils, \ 907c478bd9Sstevel@tonic-gate int maxversion, int *out_version, \ 917c478bd9Sstevel@tonic-gate sasl_server_plug_t **pluglist, \ 927c478bd9Sstevel@tonic-gate int *plugcount) { \ 937c478bd9Sstevel@tonic-gate return x##_server_plug_init(utils, maxversion, out_version, \ 947c478bd9Sstevel@tonic-gate pluglist, plugcount); \ 957c478bd9Sstevel@tonic-gate } 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate #define SASL_AUXPROP_PLUG_INIT( x ) \ 987c478bd9Sstevel@tonic-gate extern sasl_auxprop_init_t x##_auxprop_plug_init; \ 997c478bd9Sstevel@tonic-gate PLUG_API int sasl_auxprop_plug_init(const sasl_utils_t *utils, \ 1007c478bd9Sstevel@tonic-gate int maxversion, int *out_version, \ 1017c478bd9Sstevel@tonic-gate sasl_auxprop_plug_t **plug, \ 1027c478bd9Sstevel@tonic-gate const char *plugname) {\ 1037c478bd9Sstevel@tonic-gate return x##_auxprop_plug_init(utils, maxversion, out_version, \ 1047c478bd9Sstevel@tonic-gate plug, plugname); \ 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate #define SASL_CANONUSER_PLUG_INIT( x ) \ 1087c478bd9Sstevel@tonic-gate extern sasl_canonuser_init_t x##_canonuser_plug_init; \ 1097c478bd9Sstevel@tonic-gate PLUG_API int sasl_canonuser_init(const sasl_utils_t *utils, \ 1107c478bd9Sstevel@tonic-gate int maxversion, int *out_version, \ 1117c478bd9Sstevel@tonic-gate sasl_canonuser_plug_t **plug, \ 1127c478bd9Sstevel@tonic-gate const char *plugname) {\ 1137c478bd9Sstevel@tonic-gate return x##_canonuser_plug_init(utils, maxversion, out_version, \ 1147c478bd9Sstevel@tonic-gate plug, plugname); \ 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* note: msg cannot include additional variables, so if you want to 1187c478bd9Sstevel@tonic-gate * do a printf-format string, then you need to call seterror yourself */ 1197c478bd9Sstevel@tonic-gate #define SETERROR( utils, msg ) (utils)->seterror( (utils)->conn, 0, (msg) ) 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate #ifndef MEMERROR 1227c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_ 1237c478bd9Sstevel@tonic-gate #define MEMERROR( utils ) \ 1247c478bd9Sstevel@tonic-gate (utils)->seterror( (utils)->conn, 0, "Out of Memory") 1257c478bd9Sstevel@tonic-gate #else 1267c478bd9Sstevel@tonic-gate #define MEMERROR( utils ) \ 1277c478bd9Sstevel@tonic-gate (utils)->seterror( (utils)->conn, 0, \ 1287c478bd9Sstevel@tonic-gate "Out of Memory in " __FILE__ " near line %d", __LINE__ ) 1297c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */ 1307c478bd9Sstevel@tonic-gate #endif 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate #ifndef PARAMERROR 1337c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_ 1347c478bd9Sstevel@tonic-gate #define PARAMERROR( utils ) \ 1357c478bd9Sstevel@tonic-gate (utils)->seterror( (utils)->conn, 0, "Parameter Error") 1367c478bd9Sstevel@tonic-gate #else 1377c478bd9Sstevel@tonic-gate #define PARAMERROR( utils ) \ 1387c478bd9Sstevel@tonic-gate (utils)->seterror( (utils)->conn, 0, \ 1397c478bd9Sstevel@tonic-gate "Parameter Error in " __FILE__ " near line %d", __LINE__ ) 1407c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */ 1417c478bd9Sstevel@tonic-gate #endif 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate #ifndef SASLINT_H 144*55fea89dSDan Cross typedef struct buffer_info 1457c478bd9Sstevel@tonic-gate { 1467c478bd9Sstevel@tonic-gate char *data; 1477c478bd9Sstevel@tonic-gate unsigned curlen; /* Current length of data in buffer */ 1487c478bd9Sstevel@tonic-gate unsigned reallen; /* total length of buffer (>= curlen) */ 1497c478bd9Sstevel@tonic-gate } buffer_info_t; 1507c478bd9Sstevel@tonic-gate #endif 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate int _plug_ipfromstring(const sasl_utils_t *utils, const char *addr, 1537c478bd9Sstevel@tonic-gate struct sockaddr *out, socklen_t outlen); 1547c478bd9Sstevel@tonic-gate int _plug_iovec_to_buf(const sasl_utils_t *utils, const struct iovec *vec, 1557c478bd9Sstevel@tonic-gate unsigned numiov, buffer_info_t **output); 1567c478bd9Sstevel@tonic-gate int _plug_buf_alloc(const sasl_utils_t *utils, char **rwbuf, 1577c478bd9Sstevel@tonic-gate unsigned *curlen, unsigned newlen); 1587c478bd9Sstevel@tonic-gate int _plug_strdup(const sasl_utils_t * utils, const char *in, 1597c478bd9Sstevel@tonic-gate char **out, int *outlen); 1607c478bd9Sstevel@tonic-gate void _plug_free_string(const sasl_utils_t *utils, char **str); 1617c478bd9Sstevel@tonic-gate void _plug_free_secret(const sasl_utils_t *utils, sasl_secret_t **secret); 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate #define _plug_get_userid(utils, result, prompt_need) \ 1647c478bd9Sstevel@tonic-gate _plug_get_simple(utils, SASL_CB_USER, 0, result, prompt_need) 1657c478bd9Sstevel@tonic-gate #define _plug_get_authid(utils, result, prompt_need) \ 1667c478bd9Sstevel@tonic-gate _plug_get_simple(utils, SASL_CB_AUTHNAME, 1, result, prompt_need) 1677c478bd9Sstevel@tonic-gate int _plug_get_simple(const sasl_utils_t *utils, unsigned int id, int required, 1687c478bd9Sstevel@tonic-gate const char **result, sasl_interact_t **prompt_need); 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate int _plug_get_password(const sasl_utils_t *utils, sasl_secret_t **secret, 1717c478bd9Sstevel@tonic-gate unsigned int *iscopy, sasl_interact_t **prompt_need); 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate int _plug_challenge_prompt(const sasl_utils_t *utils, unsigned int id, 1747c478bd9Sstevel@tonic-gate const char *challenge, const char *promptstr, 1757c478bd9Sstevel@tonic-gate const char **result, sasl_interact_t **prompt_need); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate int _plug_get_realm(const sasl_utils_t *utils, const char **availrealms, 1787c478bd9Sstevel@tonic-gate const char **realm, sasl_interact_t **prompt_need); 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate int _plug_make_prompts(const sasl_utils_t *utils, 1817c478bd9Sstevel@tonic-gate #ifdef _INTEGRATED_SOLARIS_ 1827c478bd9Sstevel@tonic-gate void **h, 1837c478bd9Sstevel@tonic-gate #endif /* _INTEGRATED_SOLARIS_ */ 1847c478bd9Sstevel@tonic-gate sasl_interact_t **prompts_res, 1857c478bd9Sstevel@tonic-gate const char *user_prompt, const char *user_def, 1867c478bd9Sstevel@tonic-gate const char *auth_prompt, const char *auth_def, 1877c478bd9Sstevel@tonic-gate const char *pass_prompt, const char *pass_def, 1887c478bd9Sstevel@tonic-gate const char *echo_chal, 1897c478bd9Sstevel@tonic-gate const char *echo_prompt, const char *echo_def, 1907c478bd9Sstevel@tonic-gate const char *realm_chal, 1917c478bd9Sstevel@tonic-gate const char *realm_prompt, const char *realm_def); 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate int _plug_decode(const sasl_utils_t *utils, 1947c478bd9Sstevel@tonic-gate void *context, 1957c478bd9Sstevel@tonic-gate const char *input, unsigned inputlen, 1967c478bd9Sstevel@tonic-gate char **output, unsigned *outputsize, unsigned *outputlen, 1977c478bd9Sstevel@tonic-gate int (*decode_pkt)(void *context, 1987c478bd9Sstevel@tonic-gate const char **input, unsigned *inputlen, 1997c478bd9Sstevel@tonic-gate char **output, unsigned *outputlen)); 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate int _plug_parseuser(const sasl_utils_t *utils, 202*55fea89dSDan Cross char **user, char **realm, const char *user_realm, 2037c478bd9Sstevel@tonic-gate const char *serverFQDN, const char *input); 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate #ifdef _INTEGRATED_SOLARIS_ 2067c478bd9Sstevel@tonic-gate typedef void reg_sun_t(void *); 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate #define REG_PLUG( X, Y ) { \ 2097c478bd9Sstevel@tonic-gate reg_sun_t *func = NULL; \ 2107c478bd9Sstevel@tonic-gate unsigned int l; \ 2117c478bd9Sstevel@tonic-gate utils->getopt(utils->getopt_context, X, "reg_sun_plug", \ 2127c478bd9Sstevel@tonic-gate (const char **)&func, &l); \ 2137c478bd9Sstevel@tonic-gate if (func != NULL && l == 0) \ 2147c478bd9Sstevel@tonic-gate (*func)(Y); \ 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate int use_locale(const char *lang_list, int is_client); 2187c478bd9Sstevel@tonic-gate const char *convert_prompt(const sasl_utils_t *utils, void **h, const char *s); 2197c478bd9Sstevel@tonic-gate char *local_to_utf(const sasl_utils_t *utils, const char *s); 2207c478bd9Sstevel@tonic-gate #endif /* _INTEGRATED_SOLARIS_ */ 2217c478bd9Sstevel@tonic-gate #endif /* _PLUGIN_COMMON_H_ */ 222