Grid Community Toolkit  6.2.1705709074 (tag: v6.2.20240202)
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
plugin_common.h
1 
2 /* Generic SASL plugin utility functions
3  * Rob Siemborski
4  * $Id: plugin_common.h,v 1.20 2004/06/23 18:43:37 rjs3 Exp $
5  */
6 /*
7  * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
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
19  * distribution.
20  *
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
27  * 5000 Forbes Avenue
28  * Pittsburgh, PA 15213-3890
29  * (412) 268-4387, fax: (412) 268-7395
31  *
32  * 4. Redistributions of any form whatsoever must retain the following
33  * acknowledgment:
34  * "This product includes software developed by Computing Services
35  * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
36  *
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.
44  */
45 
46 #ifndef _PLUGIN_COMMON_H_
47 #define _PLUGIN_COMMON_H_
48 
49 #ifndef macintosh
50 #ifdef WIN32
51 # include <winsock2.h>
52 #else
53 # include <sys/socket.h>
54 # include <netinet/in.h>
55 # include <arpa/inet.h>
56 # include <netdb.h>
57 #endif /* WIN32 */
58 #endif /* macintosh */
59 
60 #include <sasl.h>
61 #include <saslutil.h>
62 #include <saslplug.h>
63 
64 #ifdef WIN32
65 #define PLUG_API __declspec(dllexport)
66 #else
67 #define PLUG_API extern
68 #endif
69 
70 #define SASL_CLIENT_PLUG_INIT( x ) \
71 extern sasl_client_plug_init_t x##_client_plug_init; \
72 PLUG_API int sasl_client_plug_init(const sasl_utils_t *utils, \
73  int maxversion, int *out_version, \
74  sasl_client_plug_t **pluglist, \
75  int *plugcount) { \
76  return x##_client_plug_init(utils, maxversion, out_version, \
77  pluglist, plugcount); \
78 }
79 
80 #define SASL_SERVER_PLUG_INIT( x ) \
81 extern sasl_server_plug_init_t x##_server_plug_init; \
82 PLUG_API int sasl_server_plug_init(const sasl_utils_t *utils, \
83  int maxversion, int *out_version, \
84  sasl_server_plug_t **pluglist, \
85  int *plugcount) { \
86  return x##_server_plug_init(utils, maxversion, out_version, \
87  pluglist, plugcount); \
88 }
89 
90 #define SASL_AUXPROP_PLUG_INIT( x ) \
91 extern sasl_auxprop_init_t x##_auxprop_plug_init; \
92 PLUG_API int sasl_auxprop_plug_init(const sasl_utils_t *utils, \
93  int maxversion, int *out_version, \
94  sasl_auxprop_plug_t **plug, \
95  const char *plugname) {\
96  return x##_auxprop_plug_init(utils, maxversion, out_version, \
97  plug, plugname); \
98 }
99 
100 #define SASL_CANONUSER_PLUG_INIT( x ) \
101 extern sasl_canonuser_init_t x##_canonuser_plug_init; \
102 PLUG_API int sasl_canonuser_init(const sasl_utils_t *utils, \
103  int maxversion, int *out_version, \
104  sasl_canonuser_plug_t **plug, \
105  const char *plugname) {\
106  return x##_canonuser_plug_init(utils, maxversion, out_version, \
107  plug, plugname); \
108 }
109 
110 /* note: msg cannot include additional variables, so if you want to
111  * do a printf-format string, then you need to call seterror yourself */
112 #define SETERROR( utils, msg ) (utils)->seterror( (utils)->conn, 0, "%s", (msg) )
113 
114 #ifndef MEMERROR
115 #define MEMERROR( utils ) \
116  (utils)->seterror( (utils)->conn, 0, \
117  "Out of Memory in " __FILE__ " near line %d", __LINE__ )
118 #endif
119 
120 #ifndef PARAMERROR
121 #define PARAMERROR( utils ) \
122  (utils)->seterror( (utils)->conn, 0, \
123  "Parameter Error in " __FILE__ " near line %d", __LINE__ )
124 #endif
125 
126 #ifndef SASLINT_H
127 typedef struct buffer_info
128 {
129  char *data;
130  unsigned curlen; /* Current length of data in buffer */
131  unsigned reallen; /* total length of buffer (>= curlen) */
132 } buffer_info_t;
133 #endif
134 
135 #ifdef __cplusplus
136 extern "C" {
137 #endif
138 
139 int _plug_ipfromstring(const sasl_utils_t *utils, const char *addr,
140  struct sockaddr *out, socklen_t outlen);
141 int _plug_iovec_to_buf(const sasl_utils_t *utils, const struct iovec *vec,
142  unsigned numiov, buffer_info_t **output);
143 int _plug_buf_alloc(const sasl_utils_t *utils, char **rwbuf,
144  unsigned *curlen, unsigned newlen);
145 int _plug_strdup(const sasl_utils_t * utils, const char *in,
146  char **out, int *outlen);
147 void _plug_free_string(const sasl_utils_t *utils, char **str);
148 void _plug_free_secret(const sasl_utils_t *utils, sasl_secret_t **secret);
149 
150 #define _plug_get_userid(utils, result, prompt_need) \
151  _plug_get_simple(utils, SASL_CB_USER, 0, result, prompt_need)
152 #define _plug_get_authid(utils, result, prompt_need) \
153  _plug_get_simple(utils, SASL_CB_AUTHNAME, 1, result, prompt_need)
154 int _plug_get_simple(const sasl_utils_t *utils, unsigned int id, int required,
155  const char **result, sasl_interact_t **prompt_need);
156 
157 int _plug_get_password(const sasl_utils_t *utils, sasl_secret_t **secret,
158  unsigned int *iscopy, sasl_interact_t **prompt_need);
159 
160 int _plug_challenge_prompt(const sasl_utils_t *utils, unsigned int id,
161  const char *challenge, const char *promptstr,
162  const char **result, sasl_interact_t **prompt_need);
163 
164 int _plug_get_realm(const sasl_utils_t *utils, const char **availrealms,
165  const char **realm, sasl_interact_t **prompt_need);
166 
167 int _plug_make_prompts(const sasl_utils_t *utils,
168  sasl_interact_t **prompts_res,
169  const char *user_prompt, const char *user_def,
170  const char *auth_prompt, const char *auth_def,
171  const char *pass_prompt, const char *pass_def,
172  const char *echo_chal,
173  const char *echo_prompt, const char *echo_def,
174  const char *realm_chal,
175  const char *realm_prompt, const char *realm_def);
176 
177 typedef struct decode_context {
178  const sasl_utils_t *utils;
179  unsigned int needsize; /* How much of the 4-byte size do we need? */
180  char sizebuf[4]; /* Buffer to accumulate the 4-byte size */
181  unsigned int size; /* Absolute size of the encoded packet */
182  char *buffer; /* Buffer to accumulate an encoded packet */
183  unsigned int cursize; /* Amount of packet data in the buffer */
184  unsigned int in_maxbuf; /* Maximum allowed size of an encoded packet */
185 } decode_context_t;
186 
187 void _plug_decode_init(decode_context_t *text,
188  const sasl_utils_t *utils, unsigned int in_maxbuf);
189 
190 int _plug_decode(decode_context_t *text,
191  const char *input, unsigned inputlen,
192  char **output, unsigned *outputsize, unsigned *outputlen,
193  int (*decode_pkt)(void *rock,
194  const char *input, unsigned inputlen,
195  char **output, unsigned *outputlen),
196  void *rock);
197 
198 void _plug_decode_free(decode_context_t *text);
199 
200 int _plug_parseuser(const sasl_utils_t *utils,
201  char **user, char **realm, const char *user_realm,
202  const char *serverFQDN, const char *input);
203 
204 int _plug_make_fulluser(const sasl_utils_t *utils,
205  char **fulluser, const char * useronly, const char *realm);
206 
207 char * _plug_get_error_message (const sasl_utils_t *utils,
208 #ifdef WIN32
209  DWORD error
210 #else
211  int error
212 #endif
213  );
214 void _plug_snprintf_os_info (char * osbuf, int osbuf_len);
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 #endif /* _PLUGIN_COMMON_H_ */