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

property.c
Go to the documentation of this file.
1 /* property.c --- Callback property handling.
2  * Copyright (C) 2004-2021 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 
25 static 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 
91  case GSASL_SCRAM_ITER:
92  p = &sctx->scram_iter;
93  break;
94 
95  case GSASL_SCRAM_SALT:
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 
111  case GSASL_CB_TLS_UNIQUE:
112  p = &sctx->cb_tls_unique;
113  break;
114 
116  p = &sctx->saml20_idp_identifier;
117  break;
118 
120  p = &sctx->saml20_redirect_url;
121  break;
122 
124  p = &sctx->openid20_redirect_url;
125  break;
126 
128  p = &sctx->openid20_outcome_data;
129  break;
130 
131  /* If you add anything here, remember to change change
132  gsasl_finish() in xfinish.c and Gsasl_session in
133  internal.h. */
134 
135  default:
136  break;
137  }
138 
139  return p;
140 }
141 
142 /**
143  * gsasl_property_set:
144  * @sctx: session handle.
145  * @prop: enumerated value of Gsasl_property type, indicating the
146  * type of data in @data.
147  * @data: zero terminated character string to store.
148  *
149  * Make a copy of @data and store it in the session handle for the
150  * indicated property @prop.
151  *
152  * You can immediately deallocate @data after calling this function,
153  * without affecting the data stored in the session handle.
154  *
155  * Since: 0.2.0
156  **/
157 void
159  const char *data)
160 {
161  gsasl_property_set_raw (sctx, prop, data, data ? strlen (data) : 0);
162 }
163 
164 /**
165  * gsasl_property_set_raw:
166  * @sctx: session handle.
167  * @prop: enumerated value of Gsasl_property type, indicating the
168  * type of data in @data.
169  * @data: character string to store.
170  * @len: length of character string to store.
171  *
172  * Make a copy of @len sized @data and store a zero terminated version
173  * of it in the session handle for the indicated property @prop.
174  *
175  * You can immediately deallocate @data after calling this function,
176  * without affecting the data stored in the session handle.
177  *
178  * Except for the length indicator, this function is identical to
179  * gsasl_property_set.
180  *
181  * Since: 0.2.0
182  **/
183 void
185  const char *data, size_t len)
186 {
187  char **p = map (sctx, prop);
188 
189  if (p)
190  {
191  free (*p);
192  if (data)
193  {
194  *p = malloc (len + 1);
195  if (*p)
196  {
197  memcpy (*p, data, len);
198  (*p)[len] = '\0';
199  }
200  }
201  else
202  *p = NULL;
203  }
204 }
205 
206 /**
207  * gsasl_property_fast:
208  * @sctx: session handle.
209  * @prop: enumerated value of Gsasl_property type, indicating the
210  * type of data in @data.
211  *
212  * Retrieve the data stored in the session handle for given property
213  * @prop.
214  *
215  * The pointer is to live data, and must not be deallocated or
216  * modified in any way.
217  *
218  * This function will not invoke the application callback.
219  *
220  * Return value: Return property value, if known, or NULL if no value
221  * known.
222  *
223  * Since: 0.2.0
224  **/
225 const char *
227 {
228  char **p = map (sctx, prop);
229 
230  if (p)
231  return *p;
232 
233  return NULL;
234 }
235 
236 /**
237  * gsasl_property_get:
238  * @sctx: session handle.
239  * @prop: enumerated value of Gsasl_property type, indicating the
240  * type of data in @data.
241  *
242  * Retrieve the data stored in the session handle for given property
243  * @prop, possibly invoking the application callback to get the value.
244  *
245  * The pointer is to live data, and must not be deallocated or
246  * modified in any way.
247  *
248  * This function will invoke the application callback, using
249  * gsasl_callback(), when a property value is not known.
250  *
251  * If no value is known, and no callback is specified or if the
252  * callback fail to return data, and if any obsolete callback
253  * functions has been set by the application, this function will try
254  * to call these obsolete callbacks, and store the returned data as
255  * the corresponding property. This behaviour of this function will
256  * be removed when the obsolete callback interfaces are removed.
257  *
258  * Return value: Return data for property, or NULL if no value known.
259  *
260  * Since: 0.2.0
261  **/
262 const char *
264 {
265  const char *p = gsasl_property_fast (sctx, prop);
266 
267  if (!p)
268  {
269  gsasl_callback (NULL, sctx, prop);
270  p = gsasl_property_fast (sctx, prop);
271  }
272 
273 #ifndef GSASL_NO_OBSOLETE
274  if (!p)
275  p = _gsasl_obsolete_property_map (sctx, prop);
276 #endif
277 
278  return p;
279 }
int gsasl_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop)
Definition: callback.c:75
#define NULL
Definition: stddef.in.h:72
Gsasl_property
Definition: gsasl.h:333
@ GSASL_DIGEST_MD5_HASHED_PASSWORD
Definition: gsasl.h:346
@ GSASL_SCRAM_STOREDKEY
Definition: gsasl.h:353
@ GSASL_HOSTNAME
Definition: gsasl.h:340
@ GSASL_AUTHZID
Definition: gsasl.h:336
@ GSASL_SCRAM_SALT
Definition: gsasl.h:350
@ GSASL_QOP
Definition: gsasl.h:348
@ GSASL_CB_TLS_UNIQUE
Definition: gsasl.h:354
@ GSASL_SERVICE
Definition: gsasl.h:339
@ GSASL_GSSAPI_DISPLAY_NAME
Definition: gsasl.h:341
@ GSASL_OPENID20_OUTCOME_DATA
Definition: gsasl.h:358
@ GSASL_SAML20_IDP_IDENTIFIER
Definition: gsasl.h:355
@ GSASL_SCRAM_SALTED_PASSWORD
Definition: gsasl.h:351
@ GSASL_QOPS
Definition: gsasl.h:347
@ GSASL_PASSWORD
Definition: gsasl.h:337
@ GSASL_REALM
Definition: gsasl.h:345
@ GSASL_SCRAM_ITER
Definition: gsasl.h:349
@ GSASL_PASSCODE
Definition: gsasl.h:342
@ GSASL_AUTHID
Definition: gsasl.h:335
@ GSASL_SAML20_REDIRECT_URL
Definition: gsasl.h:356
@ GSASL_PIN
Definition: gsasl.h:344
@ GSASL_ANONYMOUS_TOKEN
Definition: gsasl.h:338
@ GSASL_SCRAM_SERVERKEY
Definition: gsasl.h:352
@ GSASL_SUGGESTED_PIN
Definition: gsasl.h:343
@ GSASL_OPENID20_REDIRECT_URL
Definition: gsasl.h:357
const char * _gsasl_obsolete_property_map(Gsasl_session *sctx, Gsasl_property prop)
Definition: obsolete.c:2042
const char * p
Definition: mbrtowc-impl.h:42
const char * gsasl_property_get(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:263
void gsasl_property_set(Gsasl_session *sctx, Gsasl_property prop, const char *data)
Definition: property.c:158
void gsasl_property_set_raw(Gsasl_session *sctx, Gsasl_property prop, const char *data, size_t len)
Definition: property.c:184
static char ** map(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:26
const char * gsasl_property_fast(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:226
char * qops
Definition: internal.h:99
char * hostname
Definition: internal.h:95
char * authid
Definition: internal.h:88
char * openid20_redirect_url
Definition: internal.h:109
char * service
Definition: internal.h:94
char * qop
Definition: internal.h:100
char * scram_salted_password
Definition: internal.h:103
char * gssapi_display_name
Definition: internal.h:96
char * pin
Definition: internal.h:92
char * cb_tls_unique
Definition: internal.h:106
char * scram_storedkey
Definition: internal.h:105
char * saml20_redirect_url
Definition: internal.h:108
char * scram_salt
Definition: internal.h:102
char * scram_iter
Definition: internal.h:101
char * passcode
Definition: internal.h:91
char * anonymous_token
Definition: internal.h:87
char * password
Definition: internal.h:90
char * openid20_outcome_data
Definition: internal.h:110
char * suggestedpin
Definition: internal.h:93
char * digest_md5_hashed_password
Definition: internal.h:98
char * authzid
Definition: internal.h:89
char * realm
Definition: internal.h:97
char * scram_serverkey
Definition: internal.h:104
char * saml20_idp_identifier
Definition: internal.h:107