2 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 /* Generic SASL plugin utility functions
8 * $Id: plugin_common.h,v 1.16 2003/04/07 16:03:43 rjs3 Exp $
12 * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
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
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
33 * Pittsburgh, PA 15213-3890
34 * (412) 268-4387, fax: (412) 268-7395
35 * tech-transfer@andrew.cmu.edu
37 * 4. Redistributions of any form whatsoever must retain the following
39 * "This product includes software developed by Computing Services
40 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
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.
51 #ifndef _PLUGIN_COMMON_H_
52 #define _PLUGIN_COMMON_H_
60 # include <sys/socket.h>
61 # include <netinet/in.h>
62 # include <arpa/inet.h>
65 #endif /* macintosh */
72 #define PLUG_API __declspec(dllexport)
74 #define PLUG_API extern
77 #define SASL_CLIENT_PLUG_INIT( x ) \
78 extern sasl_client_plug_init_t x##_client_plug_init; \
79 PLUG_API int sasl_client_plug_init(const sasl_utils_t *utils, \
80 int maxversion, int *out_version, \
81 sasl_client_plug_t **pluglist, \
83 return x##_client_plug_init(utils, maxversion, out_version, \
84 pluglist, plugcount); \
87 #define SASL_SERVER_PLUG_INIT( x ) \
88 extern sasl_server_plug_init_t x##_server_plug_init; \
89 PLUG_API int sasl_server_plug_init(const sasl_utils_t *utils, \
90 int maxversion, int *out_version, \
91 sasl_server_plug_t **pluglist, \
93 return x##_server_plug_init(utils, maxversion, out_version, \
94 pluglist, plugcount); \
97 #define SASL_AUXPROP_PLUG_INIT( x ) \
98 extern sasl_auxprop_init_t x##_auxprop_plug_init; \
99 PLUG_API int sasl_auxprop_plug_init(const sasl_utils_t *utils, \
100 int maxversion, int *out_version, \
101 sasl_auxprop_plug_t **plug, \
102 const char *plugname) {\
103 return x##_auxprop_plug_init(utils, maxversion, out_version, \
107 #define SASL_CANONUSER_PLUG_INIT( x ) \
108 extern sasl_canonuser_init_t x##_canonuser_plug_init; \
109 PLUG_API int sasl_canonuser_init(const sasl_utils_t *utils, \
110 int maxversion, int *out_version, \
111 sasl_canonuser_plug_t **plug, \
112 const char *plugname) {\
113 return x##_canonuser_plug_init(utils, maxversion, out_version, \
117 /* note: msg cannot include additional variables, so if you want to
118 * do a printf-format string, then you need to call seterror yourself */
119 #define SETERROR( utils, msg ) (utils)->seterror( (utils)->conn, 0, (msg) )
123 #define MEMERROR( utils ) \
124 (utils)->seterror( (utils)->conn, 0, "Out of Memory")
126 #define MEMERROR( utils ) \
127 (utils)->seterror( (utils)->conn, 0, \
128 "Out of Memory in " __FILE__ " near line %d", __LINE__ )
129 #endif /* _SUN_SDK_ */
134 #define PARAMERROR( utils ) \
135 (utils)->seterror( (utils)->conn, 0, "Parameter Error")
137 #define PARAMERROR( utils ) \
138 (utils)->seterror( (utils)->conn, 0, \
139 "Parameter Error in " __FILE__ " near line %d", __LINE__ )
140 #endif /* _SUN_SDK_ */
144 typedef struct buffer_info
147 unsigned curlen
; /* Current length of data in buffer */
148 unsigned reallen
; /* total length of buffer (>= curlen) */
152 int _plug_ipfromstring(const sasl_utils_t
*utils
, const char *addr
,
153 struct sockaddr
*out
, socklen_t outlen
);
154 int _plug_iovec_to_buf(const sasl_utils_t
*utils
, const struct iovec
*vec
,
155 unsigned numiov
, buffer_info_t
**output
);
156 int _plug_buf_alloc(const sasl_utils_t
*utils
, char **rwbuf
,
157 unsigned *curlen
, unsigned newlen
);
158 int _plug_strdup(const sasl_utils_t
* utils
, const char *in
,
159 char **out
, int *outlen
);
160 void _plug_free_string(const sasl_utils_t
*utils
, char **str
);
161 void _plug_free_secret(const sasl_utils_t
*utils
, sasl_secret_t
**secret
);
163 #define _plug_get_userid(utils, result, prompt_need) \
164 _plug_get_simple(utils, SASL_CB_USER, 0, result, prompt_need)
165 #define _plug_get_authid(utils, result, prompt_need) \
166 _plug_get_simple(utils, SASL_CB_AUTHNAME, 1, result, prompt_need)
167 int _plug_get_simple(const sasl_utils_t
*utils
, unsigned int id
, int required
,
168 const char **result
, sasl_interact_t
**prompt_need
);
170 int _plug_get_password(const sasl_utils_t
*utils
, sasl_secret_t
**secret
,
171 unsigned int *iscopy
, sasl_interact_t
**prompt_need
);
173 int _plug_challenge_prompt(const sasl_utils_t
*utils
, unsigned int id
,
174 const char *challenge
, const char *promptstr
,
175 const char **result
, sasl_interact_t
**prompt_need
);
177 int _plug_get_realm(const sasl_utils_t
*utils
, const char **availrealms
,
178 const char **realm
, sasl_interact_t
**prompt_need
);
180 int _plug_make_prompts(const sasl_utils_t
*utils
,
181 #ifdef _INTEGRATED_SOLARIS_
183 #endif /* _INTEGRATED_SOLARIS_ */
184 sasl_interact_t
**prompts_res
,
185 const char *user_prompt
, const char *user_def
,
186 const char *auth_prompt
, const char *auth_def
,
187 const char *pass_prompt
, const char *pass_def
,
188 const char *echo_chal
,
189 const char *echo_prompt
, const char *echo_def
,
190 const char *realm_chal
,
191 const char *realm_prompt
, const char *realm_def
);
193 int _plug_decode(const sasl_utils_t
*utils
,
195 const char *input
, unsigned inputlen
,
196 char **output
, unsigned *outputsize
, unsigned *outputlen
,
197 int (*decode_pkt
)(void *context
,
198 const char **input
, unsigned *inputlen
,
199 char **output
, unsigned *outputlen
));
201 int _plug_parseuser(const sasl_utils_t
*utils
,
202 char **user
, char **realm
, const char *user_realm
,
203 const char *serverFQDN
, const char *input
);
205 #ifdef _INTEGRATED_SOLARIS_
206 typedef void reg_sun_t(void *);
208 #define REG_PLUG( X, Y ) { \
209 reg_sun_t *func = NULL; \
211 utils->getopt(utils->getopt_context, X, "reg_sun_plug", \
212 (const char **)&func, &l); \
213 if (func != NULL && l == 0) \
217 int use_locale(const char *lang_list
, int is_client
);
218 const char *convert_prompt(const sasl_utils_t
*utils
, void **h
, const char *s
);
219 char *local_to_utf(const sasl_utils_t
*utils
, const char *s
);
220 #endif /* _INTEGRATED_SOLARIS_ */
221 #endif /* _PLUGIN_COMMON_H_ */