|
gsasl
1.8.0
|
00001 /* property.c --- Callback property handling. 00002 * Copyright (C) 2004-2012 Simon Josefsson 00003 * 00004 * This file is part of GNU SASL Library. 00005 * 00006 * GNU SASL Library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public License 00008 * as published by the Free Software Foundation; either version 2.1 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * GNU SASL Library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License License along with GNU SASL Library; if not, write to the 00018 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 */ 00022 00023 #include "internal.h" 00024 00025 static char ** 00026 map (Gsasl_session * sctx, Gsasl_property prop) 00027 { 00028 char **p = NULL; 00029 00030 if (!sctx) 00031 return NULL; 00032 00033 switch (prop) 00034 { 00035 case GSASL_ANONYMOUS_TOKEN: 00036 p = &sctx->anonymous_token; 00037 break; 00038 00039 case GSASL_SERVICE: 00040 p = &sctx->service; 00041 break; 00042 00043 case GSASL_HOSTNAME: 00044 p = &sctx->hostname; 00045 break; 00046 00047 case GSASL_AUTHID: 00048 p = &sctx->authid; 00049 break; 00050 00051 case GSASL_AUTHZID: 00052 p = &sctx->authzid; 00053 break; 00054 00055 case GSASL_PASSWORD: 00056 p = &sctx->password; 00057 break; 00058 00059 case GSASL_PASSCODE: 00060 p = &sctx->passcode; 00061 break; 00062 00063 case GSASL_PIN: 00064 p = &sctx->pin; 00065 break; 00066 00067 case GSASL_SUGGESTED_PIN: 00068 p = &sctx->suggestedpin; 00069 break; 00070 00071 case GSASL_GSSAPI_DISPLAY_NAME: 00072 p = &sctx->gssapi_display_name; 00073 break; 00074 00075 case GSASL_REALM: 00076 p = &sctx->realm; 00077 break; 00078 00079 case GSASL_DIGEST_MD5_HASHED_PASSWORD: 00080 p = &sctx->digest_md5_hashed_password; 00081 break; 00082 00083 case GSASL_QOPS: 00084 p = &sctx->qops; 00085 break; 00086 00087 case GSASL_QOP: 00088 p = &sctx->qop; 00089 break; 00090 00091 case GSASL_SCRAM_ITER: 00092 p = &sctx->scram_iter; 00093 break; 00094 00095 case GSASL_SCRAM_SALT: 00096 p = &sctx->scram_salt; 00097 break; 00098 00099 case GSASL_SCRAM_SALTED_PASSWORD: 00100 p = &sctx->scram_salted_password; 00101 break; 00102 00103 case GSASL_CB_TLS_UNIQUE: 00104 p = &sctx->cb_tls_unique; 00105 break; 00106 00107 case GSASL_SAML20_IDP_IDENTIFIER: 00108 p = &sctx->saml20_idp_identifier; 00109 break; 00110 00111 case GSASL_SAML20_REDIRECT_URL: 00112 p = &sctx->saml20_redirect_url; 00113 break; 00114 00115 case GSASL_OPENID20_REDIRECT_URL: 00116 p = &sctx->openid20_redirect_url; 00117 break; 00118 00119 case GSASL_OPENID20_OUTCOME_DATA: 00120 p = &sctx->openid20_outcome_data; 00121 break; 00122 00123 /* If you add anything here, remember to change change 00124 gsasl_finish() in xfinish.c and Gsasl_session in 00125 internal.h. */ 00126 00127 default: 00128 break; 00129 } 00130 00131 return p; 00132 } 00133 00149 void 00150 gsasl_property_set (Gsasl_session * sctx, Gsasl_property prop, 00151 const char *data) 00152 { 00153 gsasl_property_set_raw (sctx, prop, data, data ? strlen (data) : 0); 00154 } 00155 00175 void 00176 gsasl_property_set_raw (Gsasl_session * sctx, Gsasl_property prop, 00177 const char *data, size_t len) 00178 { 00179 char **p = map (sctx, prop); 00180 00181 if (p) 00182 { 00183 free (*p); 00184 if (data) 00185 { 00186 *p = malloc (len + 1); 00187 if (*p) 00188 { 00189 memcpy (*p, data, len); 00190 (*p)[len] = '\0'; 00191 } 00192 } 00193 else 00194 *p = NULL; 00195 } 00196 } 00197 00217 const char * 00218 gsasl_property_fast (Gsasl_session * sctx, Gsasl_property prop) 00219 { 00220 char **p = map (sctx, prop); 00221 00222 if (p) 00223 return *p; 00224 00225 return NULL; 00226 } 00227 00254 const char * 00255 gsasl_property_get (Gsasl_session * sctx, Gsasl_property prop) 00256 { 00257 const char *p = gsasl_property_fast (sctx, prop); 00258 00259 if (!p) 00260 { 00261 gsasl_callback (NULL, sctx, prop); 00262 p = gsasl_property_fast (sctx, prop); 00263 } 00264 00265 #ifndef GSASL_NO_OBSOLETE 00266 if (!p) 00267 p = _gsasl_obsolete_property_map (sctx, prop); 00268 #endif 00269 00270 return p; 00271 }
1.7.6.1