gsasl  2.2.0
About: GNU SASL is an implementation of the Simple Authentication and Security Layer (SASL).
  Fossies Dox: gsasl-2.2.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
property.c
Go to the documentation of this file.
1/* property.c --- Callback property handling.
2 * Copyright (C) 2004-2022 Simon Josefsson
3 *
4 * This file is part of GNU SASL Library.
5 *
6 * GNU SASL Library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
10 *
11 * GNU SASL Library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License License along with GNU SASL Library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#include "internal.h"
24
25static char **
27{
28 char **p = NULL;
29
30 if (!sctx)
31 return NULL;
32
33 switch (prop)
34 {
36 p = &sctx->anonymous_token;
37 break;
38
39 case GSASL_SERVICE:
40 p = &sctx->service;
41 break;
42
43 case GSASL_HOSTNAME:
44 p = &sctx->hostname;
45 break;
46
47 case GSASL_AUTHID:
48 p = &sctx->authid;
49 break;
50
51 case GSASL_AUTHZID:
52 p = &sctx->authzid;
53 break;
54
55 case GSASL_PASSWORD:
56 p = &sctx->password;
57 break;
58
59 case GSASL_PASSCODE:
60 p = &sctx->passcode;
61 break;
62
63 case GSASL_PIN:
64 p = &sctx->pin;
65 break;
66
68 p = &sctx->suggestedpin;
69 break;
70
72 p = &sctx->gssapi_display_name;
73 break;
74
75 case GSASL_REALM:
76 p = &sctx->realm;
77 break;
78
81 break;
82
83 case GSASL_QOPS:
84 p = &sctx->qops;
85 break;
86
87 case GSASL_QOP:
88 p = &sctx->qop;
89 break;
90
92 p = &sctx->scram_iter;
93 break;
94
96 p = &sctx->scram_salt;
97 break;
98
100 p = &sctx->scram_salted_password;
101 break;
102
104 p = &sctx->scram_serverkey;
105 break;
106
108 p = &sctx->scram_storedkey;
109 break;
110
112 p = &sctx->cb_tls_unique;
113 break;
114
116 p = &sctx->cb_tls_exporter;
117 break;
118
120 p = &sctx->saml20_idp_identifier;
121 break;
122
124 p = &sctx->saml20_redirect_url;
125 break;
126
128 p = &sctx->openid20_redirect_url;
129 break;
130
132 p = &sctx->openid20_outcome_data;
133 break;
134
135 /* If you add anything here, remember to change change
136 gsasl_finish() in xfinish.c and Gsasl_session in
137 internal.h. */
138
139 default:
140 break;
141 }
142
143 return p;
144}
145
146/**
147 * gsasl_property_free:
148 * @sctx: session handle.
149 * @prop: enumerated value of %Gsasl_property type to clear
150 *
151 * Deallocate associated data with property @prop in session handle.
152 * After this call, gsasl_property_fast(@sctx, @prop) will always
153 * return NULL.
154 *
155 * Since: 2.0.0
156 **/
157void
159{
160 char **p = map (sctx, prop);
161
162 if (p)
163 {
164 free (*p);
165 *p = NULL;
166 }
167}
168
169/**
170 * gsasl_property_set:
171 * @sctx: session handle.
172 * @prop: enumerated value of Gsasl_property type, indicating the
173 * type of data in @data.
174 * @data: zero terminated character string to store.
175 *
176 * Make a copy of @data and store it in the session handle for the
177 * indicated property @prop.
178 *
179 * You can immediately deallocate @data after calling this function,
180 * without affecting the data stored in the session handle.
181 *
182 * Return value: %GSASL_OK iff successful, otherwise
183 * %GSASL_MALLOC_ERROR.
184 *
185 * Since: 0.2.0
186 **/
187int
189 const char *data)
190{
191 return gsasl_property_set_raw (sctx, prop, data, data ? strlen (data) : 0);
192}
193
194/**
195 * gsasl_property_set_raw:
196 * @sctx: session handle.
197 * @prop: enumerated value of Gsasl_property type, indicating the
198 * type of data in @data.
199 * @data: character string to store.
200 * @len: length of character string to store.
201 *
202 * Make a copy of @len sized @data and store a zero terminated version
203 * of it in the session handle for the indicated property @prop.
204 *
205 * You can immediately deallocate @data after calling this function,
206 * without affecting the data stored in the session handle.
207 *
208 * Except for the length indicator, this function is identical to
209 * gsasl_property_set.
210 *
211 * Return value: %GSASL_OK iff successful, otherwise
212 * %GSASL_MALLOC_ERROR.
213 *
214 * Since: 0.2.0
215 **/
216int
218 const char *data, size_t len)
219{
220 char **p = map (sctx, prop);
221
222 if (p)
223 {
224 free (*p);
225 if (data)
226 {
227 *p = malloc (len + 1);
228 if (!*p)
229 return GSASL_MALLOC_ERROR;
230
231 memcpy (*p, data, len);
232 (*p)[len] = '\0';
233 }
234 else
235 *p = NULL;
236 }
237
238 return GSASL_OK;
239}
240
241/**
242 * gsasl_property_fast:
243 * @sctx: session handle.
244 * @prop: enumerated value of Gsasl_property type, indicating the
245 * type of data in @data.
246 *
247 * Retrieve the data stored in the session handle for given property
248 * @prop.
249 *
250 * The pointer is to live data, and must not be deallocated or
251 * modified in any way.
252 *
253 * This function will not invoke the application callback.
254 *
255 * Return value: Return property value, if known, or NULL if no value
256 * known.
257 *
258 * Since: 0.2.0
259 **/
260const char *
262{
263 char **p = map (sctx, prop);
264
265 if (p)
266 return *p;
267
268 return NULL;
269}
270
271/**
272 * gsasl_property_get:
273 * @sctx: session handle.
274 * @prop: enumerated value of Gsasl_property type, indicating the
275 * type of data in @data.
276 *
277 * Retrieve the data stored in the session handle for given property
278 * @prop, possibly invoking the application callback to get the value.
279 *
280 * The pointer is to live data, and must not be deallocated or
281 * modified in any way.
282 *
283 * This function will invoke the application callback, using
284 * gsasl_callback(), when a property value is not known.
285 *
286 * Return value: Return data for property, or NULL if no value known.
287 *
288 * Since: 0.2.0
289 **/
290const char *
292{
293 const char *p = gsasl_property_fast (sctx, prop);
294
295 if (!p)
296 {
297 gsasl_callback (NULL, sctx, prop);
298 p = gsasl_property_fast (sctx, prop);
299 }
300
301 return p;
302}
int gsasl_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop)
Definition: callback.c:70
_GL_EXTERN_C void free(void *)
@ GSASL_OK
Definition: gsasl.h:129
@ GSASL_MALLOC_ERROR
Definition: gsasl.h:133
Gsasl_property
Definition: gsasl.h:222
@ GSASL_DIGEST_MD5_HASHED_PASSWORD
Definition: gsasl.h:235
@ GSASL_SCRAM_STOREDKEY
Definition: gsasl.h:242
@ GSASL_HOSTNAME
Definition: gsasl.h:229
@ GSASL_AUTHZID
Definition: gsasl.h:225
@ GSASL_SCRAM_SALT
Definition: gsasl.h:239
@ GSASL_QOP
Definition: gsasl.h:237
@ GSASL_CB_TLS_UNIQUE
Definition: gsasl.h:243
@ GSASL_SERVICE
Definition: gsasl.h:228
@ GSASL_GSSAPI_DISPLAY_NAME
Definition: gsasl.h:230
@ GSASL_OPENID20_OUTCOME_DATA
Definition: gsasl.h:247
@ GSASL_SAML20_IDP_IDENTIFIER
Definition: gsasl.h:244
@ GSASL_SCRAM_SALTED_PASSWORD
Definition: gsasl.h:240
@ GSASL_QOPS
Definition: gsasl.h:236
@ GSASL_PASSWORD
Definition: gsasl.h:226
@ GSASL_REALM
Definition: gsasl.h:234
@ GSASL_SCRAM_ITER
Definition: gsasl.h:238
@ GSASL_PASSCODE
Definition: gsasl.h:231
@ GSASL_AUTHID
Definition: gsasl.h:224
@ GSASL_SAML20_REDIRECT_URL
Definition: gsasl.h:245
@ GSASL_PIN
Definition: gsasl.h:233
@ GSASL_ANONYMOUS_TOKEN
Definition: gsasl.h:227
@ GSASL_SCRAM_SERVERKEY
Definition: gsasl.h:241
@ GSASL_CB_TLS_EXPORTER
Definition: gsasl.h:248
@ GSASL_SUGGESTED_PIN
Definition: gsasl.h:232
@ GSASL_OPENID20_REDIRECT_URL
Definition: gsasl.h:246
const char * p
Definition: mbrtowc-impl.h:42
int gsasl_property_set(Gsasl_session *sctx, Gsasl_property prop, const char *data)
Definition: property.c:188
const char * gsasl_property_get(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:291
int gsasl_property_set_raw(Gsasl_session *sctx, Gsasl_property prop, const char *data, size_t len)
Definition: property.c:217
const char * gsasl_property_fast(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:261
void gsasl_property_free(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:158
static char ** map(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:26
char * qops
Definition: internal.h:73
char * hostname
Definition: internal.h:69
char * authid
Definition: internal.h:62
char * openid20_redirect_url
Definition: internal.h:84
char * service
Definition: internal.h:68
char * qop
Definition: internal.h:74
char * cb_tls_exporter
Definition: internal.h:81
char * scram_salted_password
Definition: internal.h:77
char * gssapi_display_name
Definition: internal.h:70
char * pin
Definition: internal.h:66
char * cb_tls_unique
Definition: internal.h:80
char * scram_storedkey
Definition: internal.h:79
char * saml20_redirect_url
Definition: internal.h:83
char * scram_salt
Definition: internal.h:76
char * scram_iter
Definition: internal.h:75
char * passcode
Definition: internal.h:65
char * anonymous_token
Definition: internal.h:61
char * password
Definition: internal.h:64
char * openid20_outcome_data
Definition: internal.h:85
char * suggestedpin
Definition: internal.h:67
char * digest_md5_hashed_password
Definition: internal.h:72
char * authzid
Definition: internal.h:63
char * realm
Definition: internal.h:71
char * scram_serverkey
Definition: internal.h:78
char * saml20_idp_identifier
Definition: internal.h:82