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