gsasl  2.2.2
property.c
Go to the documentation of this file.
1 /* property.c --- Callback property handling.
2  * Copyright (C) 2004-2025 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 along with GNU SASL Library; if not, see
18  * <https://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #include <config.h>
23 #include "internal.h"
24 
25 static char **
26 map (Gsasl_session *sctx, Gsasl_property prop)
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 
80  p = &sctx->digest_md5_hashed_password;
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->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 
157 void
159 {
160  char **p = map (sctx, prop);
161 
162  if (p)
163  {
164  free (*p);
165  *p = NULL;
166  }
167 }
168 
187 int
189  const char *data)
190 {
191  return gsasl_property_set_raw (sctx, prop, data, data ? strlen (data) : 0);
192 }
193 
216 int
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 
260 const char *
262 {
263  char **p = map (sctx, prop);
264 
265  if (p)
266  return *p;
267 
268  return NULL;
269 }
270 
290 const 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
@ GSASL_OK
Definition: gsasl.h:128
@ GSASL_MALLOC_ERROR
Definition: gsasl.h:132
Gsasl_property
Definition: gsasl.h:221
@ GSASL_DIGEST_MD5_HASHED_PASSWORD
Definition: gsasl.h:234
@ GSASL_SCRAM_STOREDKEY
Definition: gsasl.h:241
@ GSASL_HOSTNAME
Definition: gsasl.h:228
@ GSASL_AUTHZID
Definition: gsasl.h:224
@ GSASL_SCRAM_SALT
Definition: gsasl.h:238
@ GSASL_QOP
Definition: gsasl.h:236
@ GSASL_CB_TLS_UNIQUE
Definition: gsasl.h:242
@ GSASL_SERVICE
Definition: gsasl.h:227
@ GSASL_GSSAPI_DISPLAY_NAME
Definition: gsasl.h:229
@ GSASL_OPENID20_OUTCOME_DATA
Definition: gsasl.h:246
@ GSASL_SAML20_IDP_IDENTIFIER
Definition: gsasl.h:243
@ GSASL_SCRAM_SALTED_PASSWORD
Definition: gsasl.h:239
@ GSASL_QOPS
Definition: gsasl.h:235
@ GSASL_PASSWORD
Definition: gsasl.h:225
@ GSASL_REALM
Definition: gsasl.h:233
@ GSASL_SCRAM_ITER
Definition: gsasl.h:237
@ GSASL_PASSCODE
Definition: gsasl.h:230
@ GSASL_AUTHID
Definition: gsasl.h:223
@ GSASL_SAML20_REDIRECT_URL
Definition: gsasl.h:244
@ GSASL_PIN
Definition: gsasl.h:232
@ GSASL_ANONYMOUS_TOKEN
Definition: gsasl.h:226
@ GSASL_SCRAM_SERVERKEY
Definition: gsasl.h:240
@ GSASL_CB_TLS_EXPORTER
Definition: gsasl.h:247
@ GSASL_SUGGESTED_PIN
Definition: gsasl.h:231
@ GSASL_OPENID20_REDIRECT_URL
Definition: gsasl.h:245
const char * gsasl_property_get(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:291
int gsasl_property_set(Gsasl_session *sctx, Gsasl_property prop, const char *data)
Definition: property.c:188
int gsasl_property_set_raw(Gsasl_session *sctx, Gsasl_property prop, const char *data, size_t len)
Definition: property.c:217
void gsasl_property_free(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:158
const char * gsasl_property_fast(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:261
char * qops
Definition: internal.h:68
char * hostname
Definition: internal.h:64
char * authid
Definition: internal.h:57
char * openid20_redirect_url
Definition: internal.h:79
char * service
Definition: internal.h:63
char * qop
Definition: internal.h:69
char * cb_tls_exporter
Definition: internal.h:76
char * scram_salted_password
Definition: internal.h:72
char * gssapi_display_name
Definition: internal.h:65
char * pin
Definition: internal.h:61
char * cb_tls_unique
Definition: internal.h:75
char * scram_storedkey
Definition: internal.h:74
char * saml20_redirect_url
Definition: internal.h:78
char * scram_salt
Definition: internal.h:71
char * scram_iter
Definition: internal.h:70
char * passcode
Definition: internal.h:60
char * anonymous_token
Definition: internal.h:56
char * password
Definition: internal.h:59
char * openid20_outcome_data
Definition: internal.h:80
char * suggestedpin
Definition: internal.h:62
char * digest_md5_hashed_password
Definition: internal.h:67
char * authzid
Definition: internal.h:58
char * realm
Definition: internal.h:66
char * scram_serverkey
Definition: internal.h:73
char * saml20_idp_identifier
Definition: internal.h:77