2 /* Generic SASL plugin utility functions
4 * $Id: plugin_common.h,v 1.21 2006/01/17 12:18:21 mel Exp $
7 * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
21 * 3. The name "Carnegie Mellon University" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For permission or any other legal
24 * details, please contact
25 * Office of Technology Transfer
26 * Carnegie Mellon University
28 * Pittsburgh, PA 15213-3890
29 * (412) 268-4387, fax: (412) 268-7395
30 * tech-transfer@andrew.cmu.edu
32 * 4. Redistributions of any form whatsoever must retain the following
34 * "This product includes software developed by Computing Services
35 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
37 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
38 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
39 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
40 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
41 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
42 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
43 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
46 #ifndef _PLUGIN_COMMON_H_
47 #define _PLUGIN_COMMON_H_
53 # include <winsock2.h>
55 # include <sys/socket.h>
56 # include <netinet/in.h>
57 # include <arpa/inet.h>
60 #endif /* macintosh */
67 #define PLUG_API __declspec(dllexport)
69 #define PLUG_API extern
72 #define SASL_CLIENT_PLUG_INIT( x ) \
73 extern sasl_client_plug_init_t x##_client_plug_init; \
74 PLUG_API int sasl_client_plug_init(const sasl_utils_t *utils, \
75 int maxversion, int *out_version, \
76 sasl_client_plug_t **pluglist, \
78 return x##_client_plug_init(utils, maxversion, out_version, \
79 pluglist, plugcount); \
82 #define SASL_SERVER_PLUG_INIT( x ) \
83 extern sasl_server_plug_init_t x##_server_plug_init; \
84 PLUG_API int sasl_server_plug_init(const sasl_utils_t *utils, \
85 int maxversion, int *out_version, \
86 sasl_server_plug_t **pluglist, \
88 return x##_server_plug_init(utils, maxversion, out_version, \
89 pluglist, plugcount); \
92 #define SASL_AUXPROP_PLUG_INIT( x ) \
93 extern sasl_auxprop_init_t x##_auxprop_plug_init; \
94 PLUG_API int sasl_auxprop_plug_init(const sasl_utils_t *utils, \
95 int maxversion, int *out_version, \
96 sasl_auxprop_plug_t **plug, \
97 const char *plugname) {\
98 return x##_auxprop_plug_init(utils, maxversion, out_version, \
102 #define SASL_CANONUSER_PLUG_INIT( x ) \
103 extern sasl_canonuser_init_t x##_canonuser_plug_init; \
104 PLUG_API int sasl_canonuser_init(const sasl_utils_t *utils, \
105 int maxversion, int *out_version, \
106 sasl_canonuser_plug_t **plug, \
107 const char *plugname) {\
108 return x##_canonuser_plug_init(utils, maxversion, out_version, \
112 /* note: msg cannot include additional variables, so if you want to
113 * do a printf-format string, then you need to call seterror yourself */
114 #define SETERROR( utils, msg ) (utils)->seterror( (utils)->conn, 0, (msg) )
117 #define MEMERROR( utils ) \
118 (utils)->seterror( (utils)->conn, 0, \
119 "Out of Memory in " __FILE__ " near line %d", __LINE__ )
123 #define PARAMERROR( utils ) \
124 (utils)->seterror( (utils)->conn, 0, \
125 "Parameter Error in " __FILE__ " near line %d", __LINE__ )
129 typedef struct buffer_info
132 unsigned curlen; /* Current length of data in buffer */
133 unsigned reallen; /* total length of buffer (>= curlen) */
141 int _plug_ipfromstring(const sasl_utils_t *utils, const char *addr,
142 struct sockaddr *out, socklen_t outlen);
143 int _plug_iovec_to_buf(const sasl_utils_t *utils, const struct iovec *vec,
144 unsigned numiov, buffer_info_t **output);
145 int _plug_buf_alloc(const sasl_utils_t *utils, char **rwbuf,
146 unsigned *curlen, unsigned newlen);
147 int _plug_strdup(const sasl_utils_t * utils, const char *in,
148 char **out, int *outlen);
149 void _plug_free_string(const sasl_utils_t *utils, char **str);
150 void _plug_free_secret(const sasl_utils_t *utils, sasl_secret_t **secret);
152 #define _plug_get_userid(utils, result, prompt_need) \
153 _plug_get_simple(utils, SASL_CB_USER, 0, result, prompt_need)
154 #define _plug_get_authid(utils, result, prompt_need) \
155 _plug_get_simple(utils, SASL_CB_AUTHNAME, 1, result, prompt_need)
156 int _plug_get_simple(const sasl_utils_t *utils, unsigned int id, int required,
157 const char **result, sasl_interact_t **prompt_need);
159 int _plug_get_password(const sasl_utils_t *utils, sasl_secret_t **secret,
160 unsigned int *iscopy, sasl_interact_t **prompt_need);
162 int _plug_challenge_prompt(const sasl_utils_t *utils, unsigned int id,
163 const char *challenge, const char *promptstr,
164 const char **result, sasl_interact_t **prompt_need);
166 int _plug_get_realm(const sasl_utils_t *utils, const char **availrealms,
167 const char **realm, sasl_interact_t **prompt_need);
169 int _plug_make_prompts(const sasl_utils_t *utils,
170 sasl_interact_t **prompts_res,
171 const char *user_prompt, const char *user_def,
172 const char *auth_prompt, const char *auth_def,
173 const char *pass_prompt, const char *pass_def,
174 const char *echo_chal,
175 const char *echo_prompt, const char *echo_def,
176 const char *realm_chal,
177 const char *realm_prompt, const char *realm_def);
179 typedef struct decode_context {
180 const sasl_utils_t *utils;
181 unsigned int needsize; /* How much of the 4-byte size do we need? */
182 char sizebuf[4]; /* Buffer to accumulate the 4-byte size */
183 unsigned int size; /* Absolute size of the encoded packet */
184 char *buffer; /* Buffer to accumulate an encoded packet */
185 unsigned int cursize; /* Amount of packet data in the buffer */
186 unsigned int in_maxbuf; /* Maximum allowed size of an incoming encoded packet */
189 void _plug_decode_init(decode_context_t *text,
190 const sasl_utils_t *utils, unsigned int in_maxbuf);
192 int _plug_decode(decode_context_t *text,
193 const char *input, unsigned inputlen,
194 char **output, unsigned *outputsize, unsigned *outputlen,
195 int (*decode_pkt)(void *rock,
196 const char *input, unsigned inputlen,
197 char **output, unsigned *outputlen),
200 void _plug_decode_free(decode_context_t *text);
202 int _plug_parseuser(const sasl_utils_t *utils,
203 char **user, char **realm, const char *user_realm,
204 const char *serverFQDN, const char *input);
206 int _plug_make_fulluser(const sasl_utils_t *utils,
207 char **fulluser, const char * useronly, const char *realm);
209 char * _plug_get_error_message (const sasl_utils_t *utils,
216 void _plug_snprintf_os_info (char * osbuf, int osbuf_len);
222 #endif /* _PLUGIN_COMMON_H_ */