Kgapi

plugin_common.h
1
2/* Generic SASL plugin utility functions
3 * Rob Siemborski
4 */
5/*
6 * Copyright (c) 1998-2016 Carnegie Mellon University. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. The name "Carnegie Mellon University" must not be used to
21 * endorse or promote products derived from this software without
22 * prior written permission. For permission or any other legal
23 * details, please contact
24 * Carnegie Mellon University
25 * Center for Technology Transfer and Enterprise Creation
26 * 4615 Forbes Avenue
27 * Suite 302
28 * Pittsburgh, PA 15213
29 * (412) 268-7393, fax: (412) 268-7395
30 * innovation@andrew.cmu.edu
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#include <config.h>
50
51#ifdef WIN32
52#include <winsock2.h>
53#else
54#ifndef macintosh
55#include <arpa/inet.h>
56#endif /* macintosh */
57#include <netdb.h>
58#include <netinet/in.h>
59#include <sys/socket.h>
60#endif /* WIN32 */
61
62#include <sasl/sasl.h>
63#include <sasl/saslplug.h>
64#include <sasl/saslutil.h>
65
66#ifdef WIN32
67#define PLUG_API __declspec(dllexport)
68#else
69#define PLUG_API extern
70#endif
71
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, int maxversion, int *out_version, sasl_client_plug_t **pluglist, int *plugcount) \
75 { \
76 return x##_client_plug_init(utils, maxversion, out_version, pluglist, plugcount); \
77 }
78
79#define SASL_SERVER_PLUG_INIT(x) \
80 extern sasl_server_plug_init_t x##_server_plug_init; \
81 PLUG_API int sasl_server_plug_init(const sasl_utils_t *utils, int maxversion, int *out_version, sasl_server_plug_t **pluglist, int *plugcount) \
82 { \
83 return x##_server_plug_init(utils, maxversion, out_version, pluglist, plugcount); \
84 }
85
86#define SASL_AUXPROP_PLUG_INIT(x) \
87 extern sasl_auxprop_init_t x##_auxprop_plug_init; \
88 PLUG_API int sasl_auxprop_plug_init(const sasl_utils_t *utils, int maxversion, int *out_version, sasl_auxprop_plug_t **plug, const char *plugname) \
89 { \
90 return x##_auxprop_plug_init(utils, maxversion, out_version, plug, plugname); \
91 }
92
93#define SASL_CANONUSER_PLUG_INIT(x) \
94 extern sasl_canonuser_init_t x##_canonuser_plug_init; \
95 PLUG_API int sasl_canonuser_init(const sasl_utils_t *utils, int maxversion, int *out_version, sasl_canonuser_plug_t **plug, const char *plugname) \
96 { \
97 return x##_canonuser_plug_init(utils, maxversion, out_version, plug, plugname); \
98 }
99
100/* note: msg cannot include additional variables, so if you want to
101 * do a printf-format string, then you need to call seterror yourself */
102#define SETERROR(utils, msg) (utils)->seterror((utils)->conn, 0, (msg))
103
104#ifndef MEMERROR
105#define MEMERROR(utils) (utils)->seterror((utils)->conn, 0, "Out of Memory in " __FILE__ " near line %d", __LINE__)
106#endif
107
108#ifndef PARAMERROR
109#define PARAMERROR(utils) (utils)->seterror((utils)->conn, 0, "Parameter Error in " __FILE__ " near line %d", __LINE__)
110#endif
111
112#ifndef SASLINT_H
113typedef struct buffer_info {
114 char *data;
115 unsigned curlen; /* Current length of data in buffer */
116 unsigned reallen; /* total length of buffer (>= curlen) */
117} buffer_info_t;
118
119#ifndef HAVE_GETHOSTNAME
120#ifdef sun
121/* gotta define gethostname ourselves on suns */
122extern int gethostname(char *, int);
123#endif
124#endif /* HAVE_GETHOSTNAME */
125
126#endif /* SASLINT_H */
127
128#ifdef __cplusplus
129extern "C" {
130#endif
131
132int _plug_ipfromstring(const sasl_utils_t *utils, const char *addr, struct sockaddr *out, socklen_t outlen);
133int _plug_iovec_to_buf(const sasl_utils_t *utils, const struct iovec *vec, unsigned numiov, buffer_info_t **output);
134int _plug_buf_alloc(const sasl_utils_t *utils, char **rwbuf, unsigned *curlen, unsigned newlen);
135int _plug_strdup(const sasl_utils_t *utils, const char *in, char **out, int *outlen);
136void _plug_free_string(const sasl_utils_t *utils, char **str);
137void _plug_free_secret(const sasl_utils_t *utils, sasl_secret_t **secret);
138
139#define _plug_get_userid(utils, result, prompt_need) _plug_get_simple(utils, SASL_CB_USER, 0, result, prompt_need)
140#define _plug_get_authid(utils, result, prompt_need) _plug_get_simple(utils, SASL_CB_AUTHNAME, 1, result, prompt_need)
141int _plug_get_simple(const sasl_utils_t *utils, unsigned int id, int required, const char **result, sasl_interact_t **prompt_need);
142
143int _plug_get_password(const sasl_utils_t *utils, sasl_secret_t **secret, unsigned int *iscopy, sasl_interact_t **prompt_need);
144
145int _plug_challenge_prompt(const sasl_utils_t *utils,
146 unsigned int id,
147 const char *challenge,
148 const char *promptstr,
149 const char **result,
150 sasl_interact_t **prompt_need);
151
152int _plug_get_realm(const sasl_utils_t *utils, const char **availrealms, const char **realm, sasl_interact_t **prompt_need);
153
154int _plug_make_prompts(const sasl_utils_t *utils,
155 sasl_interact_t **prompts_res,
156 const char *user_prompt,
157 const char *user_def,
158 const char *auth_prompt,
159 const char *auth_def,
160 const char *pass_prompt,
161 const char *pass_def,
162 const char *echo_chal,
163 const char *echo_prompt,
164 const char *echo_def,
165 const char *realm_chal,
166 const char *realm_prompt,
167 const char *realm_def);
168
169typedef struct decode_context {
170 const sasl_utils_t *utils;
171 unsigned int needsize; /* How much of the 4-byte size do we need? */
172 char sizebuf[4]; /* Buffer to accumulate the 4-byte size */
173 unsigned int size; /* Absolute size of the encoded packet */
174 char *buffer; /* Buffer to accumulate an encoded packet */
175 unsigned int cursize; /* Amount of packet data in the buffer */
176 unsigned int in_maxbuf; /* Maximum allowed size of an incoming encoded packet */
177} decode_context_t;
178
179void _plug_decode_init(decode_context_t *text, const sasl_utils_t *utils, unsigned int in_maxbuf);
180
181int _plug_decode(decode_context_t *text,
182 const char *input,
183 unsigned inputlen,
184 char **output,
185 unsigned *outputsize,
186 unsigned *outputlen,
187 int (*decode_pkt)(void *rock, const char *input, unsigned inputlen, char **output, unsigned *outputlen),
188 void *rock);
189
190void _plug_decode_free(decode_context_t *text);
191
192int _plug_parseuser(const sasl_utils_t *utils, char **user, char **realm, const char *user_realm, const char *serverFQDN, const char *input);
193
194int _plug_make_fulluser(const sasl_utils_t *utils, char **fulluser, const char *useronly, const char *realm);
195
196char *_plug_get_error_message(const sasl_utils_t *utils,
197#ifdef WIN32
198 DWORD error
199#else
200 int error
201#endif
202);
203void _plug_snprintf_os_info(char *osbuf, int osbuf_len);
204
205#ifdef __cplusplus
206}
207#endif
208
209#endif /* _PLUGIN_COMMON_H_ */
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:17:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.