xref: /titanic_52/usr/src/lib/libsasl/include/plugin_common.h (revision 263f549e5da8b32c4922f586afb365b8ae388a6c)
1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /* Generic SASL plugin utility functions
7  * Rob Siemborski
8  * $Id: plugin_common.h,v 1.16 2003/04/07 16:03:43 rjs3 Exp $
9  */
10 
11 /*
12  * Copyright (c) 1998-2003 Carnegie Mellon University.  All rights reserved.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  *
18  * 1. Redistributions of source code must retain the above copyright
19  *    notice, this list of conditions and the following disclaimer.
20  *
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
24  *    distribution.
25  *
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
32  *      5000 Forbes Avenue
33  *      Pittsburgh, PA  15213-3890
34  *      (412) 268-4387, fax: (412) 268-7395
35  *      tech-transfer@andrew.cmu.edu
36  *
37  * 4. Redistributions of any form whatsoever must retain the following
38  *    acknowledgment:
39  *    "This product includes software developed by Computing Services
40  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
41  *
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.
49  */
50 
51 #ifndef _PLUGIN_COMMON_H_
52 #define _PLUGIN_COMMON_H_
53 
54 #include <config.h>
55 
56 #ifndef macintosh
57 #ifdef WIN32
58 # include <winsock.h>
59 #else
60 # include <sys/socket.h>
61 # include <netinet/in.h>
62 # include <arpa/inet.h>
63 # include <netdb.h>
64 #endif /* WIN32 */
65 #endif /* macintosh */
66 
67 #include <sasl.h>
68 #include <saslutil.h>
69 #include <saslplug.h>
70 
71 #ifdef WIN32
72 #define PLUG_API __declspec(dllexport)
73 #else
74 #define PLUG_API extern
75 #endif
76 
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, \
82                          int *plugcount) { \
83         return x##_client_plug_init(utils, maxversion, out_version, \
84 				     pluglist, plugcount); \
85 }
86 
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, \
92                          int *plugcount) { \
93         return x##_server_plug_init(utils, maxversion, out_version, \
94 				     pluglist, plugcount); \
95 }
96 
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, \
104                                      plug, plugname); \
105 }
106 
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, \
114                                      plug, plugname); \
115 }
116 
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) )
120 
121 #ifndef MEMERROR
122 #ifdef _SUN_SDK_
123 #define MEMERROR( utils ) \
124     (utils)->seterror( (utils)->conn, 0, "Out of Memory")
125 #else
126 #define MEMERROR( utils ) \
127     (utils)->seterror( (utils)->conn, 0, \
128                        "Out of Memory in " __FILE__ " near line %d", __LINE__ )
129 #endif /* _SUN_SDK_ */
130 #endif
131 
132 #ifndef PARAMERROR
133 #ifdef _SUN_SDK_
134 #define PARAMERROR( utils ) \
135     (utils)->seterror( (utils)->conn, 0, "Parameter Error")
136 #else
137 #define PARAMERROR( utils ) \
138     (utils)->seterror( (utils)->conn, 0, \
139                        "Parameter Error in " __FILE__ " near line %d", __LINE__ )
140 #endif /* _SUN_SDK_ */
141 #endif
142 
143 #ifndef SASLINT_H
144 typedef struct buffer_info
145 {
146     char *data;
147     unsigned curlen;   /* Current length of data in buffer */
148     unsigned reallen;  /* total length of buffer (>= curlen) */
149 } buffer_info_t;
150 #endif
151 
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);
162 
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);
169 
170 int _plug_get_password(const sasl_utils_t *utils, sasl_secret_t **secret,
171 		       unsigned int *iscopy, sasl_interact_t **prompt_need);
172 
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);
176 
177 int _plug_get_realm(const sasl_utils_t *utils, const char **availrealms,
178 		    const char **realm, sasl_interact_t **prompt_need);
179 
180 int _plug_make_prompts(const sasl_utils_t *utils,
181 #ifdef _INTEGRATED_SOLARIS_
182 		       void **h,
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);
192 
193 int _plug_decode(const sasl_utils_t *utils,
194 		 void *context,
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));
200 
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);
204 
205 #ifdef _INTEGRATED_SOLARIS_
206 typedef void reg_sun_t(void *);
207 
208 #define REG_PLUG( X, Y ) { \
209 	reg_sun_t *func = NULL; \
210 	unsigned int l; \
211 	utils->getopt(utils->getopt_context, X, "reg_sun_plug", \
212 		(const char **)&func, &l); \
213 	if (func != NULL && l == 0) \
214 		(*func)(Y); \
215 }
216 
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_ */
222