gsasl  2.2.1
property.c
Go to the documentation of this file.
1 /* property.c --- Callback property handling.
2  * Copyright (C) 2004-2024 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 <config.h>
24 #include "internal.h"
25 
26 static char **
27 map (Gsasl_session *sctx, Gsasl_property prop)
28 {
29  char **p = NULL;
30 
31  if (!sctx)
32  return NULL;
33 
34  switch (prop)
35  {
37  p = &sctx->anonymous_token;
38  break;
39 
40  case GSASL_SERVICE:
41  p = &sctx->service;
42  break;
43 
44  case GSASL_HOSTNAME:
45  p = &sctx->hostname;
46  break;
47 
48  case GSASL_AUTHID:
49  p = &sctx->authid;
50  break;
51 
52  case GSASL_AUTHZID:
53  p = &sctx->authzid;
54  break;
55 
56  case GSASL_PASSWORD:
57  p = &sctx->password;
58  break;
59 
60  case GSASL_PASSCODE:
61  p = &sctx->passcode;
62  break;
63 
64  case GSASL_PIN:
65  p = &sctx->pin;
66  break;
67 
69  p = &sctx->suggestedpin;
70  break;
71 
73  p = &sctx->gssapi_display_name;
74  break;
75 
76  case GSASL_REALM:
77  p = &sctx->realm;
78  break;
79 
81  p = &sctx->digest_md5_hashed_password;
82  break;
83 
84  case GSASL_QOPS:
85  p = &sctx->qops;
86  break;
87 
88  case GSASL_QOP:
89  p = &sctx->qop;
90  break;
91 
92  case GSASL_SCRAM_ITER:
93  p = &sctx->scram_iter;
94  break;
95 
96  case GSASL_SCRAM_SALT:
97  p = &sctx->scram_salt;
98  break;
99 
101  p = &sctx->scram_salted_password;
102  break;
103 
105  p = &sctx->scram_serverkey;
106  break;
107 
109  p = &sctx->scram_storedkey;
110  break;
111 
112  case GSASL_CB_TLS_UNIQUE:
113  p = &sctx->cb_tls_unique;
114  break;
115 
117  p = &sctx->cb_tls_exporter;
118  break;
119 
121  p = &sctx->saml20_idp_identifier;
122  break;
123 
125  p = &sctx->saml20_redirect_url;
126  break;
127 
129  p = &sctx->openid20_redirect_url;
130  break;
131 
133  p = &sctx->openid20_outcome_data;
134  break;
135 
136  /* If you add anything here, remember to change change
137  gsasl_finish() in xfinish.c and Gsasl_session in
138  internal.h. */
139 
140  default:
141  break;
142  }
143 
144  return p;
145 }
146 
158 void
160 {
161  char **p = map (sctx, prop);
162 
163  if (p)
164  {
165  free (*p);
166  *p = NULL;
167  }
168 }
169 
188 int
190  const char *data)
191 {
192  return gsasl_property_set_raw (sctx, prop, data, data ? strlen (data) : 0);
193 }
194 
217 int
219  const char *data, size_t len)
220 {
221  char **p = map (sctx, prop);
222 
223  if (p)
224  {
225  free (*p);
226  if (data)
227  {
228  *p = malloc (len + 1);
229  if (!*p)
230  return GSASL_MALLOC_ERROR;
231 
232  memcpy (*p, data, len);
233  (*p)[len] = '\0';
234  }
235  else
236  *p = NULL;
237  }
238 
239  return GSASL_OK;
240 }
241 
261 const char *
263 {
264  char **p = map (sctx, prop);
265 
266  if (p)
267  return *p;
268 
269  return NULL;
270 }
271 
291 const char *
293 {
294  const char *p = gsasl_property_fast (sctx, prop);
295 
296  if (!p)
297  {
298  gsasl_callback (NULL, sctx, prop);
299  p = gsasl_property_fast (sctx, prop);
300  }
301 
302  return p;
303 }
int gsasl_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop)
Definition: callback.c:71
@ 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 * gsasl_property_get(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:292
int gsasl_property_set(Gsasl_session *sctx, Gsasl_property prop, const char *data)
Definition: property.c:189
int gsasl_property_set_raw(Gsasl_session *sctx, Gsasl_property prop, const char *data, size_t len)
Definition: property.c:218
void gsasl_property_free(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:159
const char * gsasl_property_fast(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:262
char * qops
Definition: internal.h:69
char * hostname
Definition: internal.h:65
char * authid
Definition: internal.h:58
char * openid20_redirect_url
Definition: internal.h:80
char * service
Definition: internal.h:64
char * qop
Definition: internal.h:70
char * cb_tls_exporter
Definition: internal.h:77
char * scram_salted_password
Definition: internal.h:73
char * gssapi_display_name
Definition: internal.h:66
char * pin
Definition: internal.h:62
char * cb_tls_unique
Definition: internal.h:76
char * scram_storedkey
Definition: internal.h:75
char * saml20_redirect_url
Definition: internal.h:79
char * scram_salt
Definition: internal.h:72
char * scram_iter
Definition: internal.h:71
char * passcode
Definition: internal.h:61
char * anonymous_token
Definition: internal.h:57
char * password
Definition: internal.h:60
char * openid20_outcome_data
Definition: internal.h:81
char * suggestedpin
Definition: internal.h:63
char * digest_md5_hashed_password
Definition: internal.h:68
char * authzid
Definition: internal.h:59
char * realm
Definition: internal.h:67
char * scram_serverkey
Definition: internal.h:74
char * saml20_idp_identifier
Definition: internal.h:78